public class DualNodeJtaTransactionImpl implements Transaction { private static final Logger log = LoggerFactory.getLogger( DualNodeJtaTransactionImpl.class ); private int status; private LinkedList synchronizations; private Connection connection; // the only resource we care about is jdbc connection private final DualNodeJtaTransactionManagerImpl jtaTransactionManager; public DualNodeJtaTransactionImpl(DualNodeJtaTransactionManagerImpl jtaTransactionManager) { this.jtaTransactionManager = jtaTransactionManager; this.status = Status.STATUS_ACTIVE; } public int getStatus() { return status; } public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException { if ( status == Status.STATUS_MARKED_ROLLBACK ) { log.trace( "on commit, status was marked for rollback-only" ); rollback(); } else { status = Status.STATUS_PREPARING; for ( int i = 0; i < synchronizations.size(); i++ ) { Synchronization s = ( Synchronization ) synchronizations.get( i ); s.beforeCompletion(); } status = Status.STATUS_COMMITTING; if ( connection != null ) { try { connection.commit(); connection.close(); } catch ( SQLException sqle ) { status = Status.STATUS_UNKNOWN; throw new SystemException(); } } status = Status.STATUS_COMMITTED; for ( int i = 0; i < synchronizations.size(); i++ ) { Synchronization s = ( Synchronization ) synchronizations.get( i ); s.afterCompletion( status ); } //status = Status.STATUS_NO_TRANSACTION; jtaTransactionManager.endCurrent( this ); } } public void rollback() throws IllegalStateException, SystemException { status = Status.STATUS_ROLLEDBACK; if ( connection != null ) { try { connection.rollback(); connection.close(); } catch ( SQLException sqle ) { status = Status.STATUS_UNKNOWN; throw new SystemException(); } } if (synchronizations != null) { for ( int i = 0; i < synchronizations.size(); i++ ) { Synchronization s = ( Synchronization ) synchronizations.get( i ); s.afterCompletion( status ); } } //status = Status.STATUS_NO_TRANSACTION; jtaTransactionManager.endCurrent( this ); } public void setRollbackOnly() throws IllegalStateException, SystemException { status = Status.STATUS_MARKED_ROLLBACK; } public void registerSynchronization(Synchronization synchronization) throws RollbackException, IllegalStateException, SystemException { // todo : find the spec-allowable statuses during which synch can be registered... if ( synchronizations == null ) { synchronizations = new LinkedList(); } synchronizations.add( synchronization ); } public void enlistConnection(Connection connection) { if ( this.connection != null ) { throw new IllegalStateException( "Connection already registered" ); } this.connection = connection; } public Connection getEnlistedConnection() { return connection; } public boolean enlistResource(XAResource xaResource) throws RollbackException, IllegalStateException, SystemException { return false; } public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException { return false
public class SimpleJtaTransactionImpl implements Transaction { private static final Logger log = LoggerFactory.getLogger( SimpleJtaTransactionImpl.class ); private int status; private LinkedList synchronizations; private Connection connection; // the only resource we care about is jdbc connection private final SimpleJtaTransactionManagerImpl jtaTransactionManager; public SimpleJtaTransactionImpl(SimpleJtaTransactionManagerImpl jtaTransactionManager) { this.jtaTransactionManager = jtaTransactionManager; this.status = Status.STATUS_ACTIVE; } public int getStatus() { return status; } public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException { if ( status == Status.STATUS_MARKED_ROLLBACK ) { log.trace( "on commit, status was marked for rollback-only" ); rollback(); } else { status = Status.STATUS_PREPARING; for ( int i = 0; i < synchronizations.size(); i++ ) { Synchronization s = ( Synchronization ) synchronizations.get( i ); s.beforeCompletion(); } status = Status.STATUS_COMMITTING; if ( connection != null ) { try { connection.commit(); connection.close(); } catch ( SQLException sqle ) { status = Status.STATUS_UNKNOWN; throw new SystemException(); } } status = Status.STATUS_COMMITTED; for ( int i = 0; i < synchronizations.size(); i++ ) { Synchronization s = ( Synchronization ) synchronizations.get( i ); s.afterCompletion( status ); } //status = Status.STATUS_NO_TRANSACTION; jtaTransactionManager.endCurrent( this ); } } public void rollback() throws IllegalStateException, SystemException { status = Status.STATUS_ROLLEDBACK; if ( connection != null ) { try { connection.rollback(); connection.close(); } catch ( SQLException sqle ) { status = Status.STATUS_UNKNOWN; throw new SystemException(); } } for ( int i = 0; i < synchronizations.size(); i++ ) { Synchronization s = ( Synchronization ) synchronizations.get( i ); s.afterCompletion( status ); } //status = Status.STATUS_NO_TRANSACTION; jtaTransactionManager.endCurrent( this ); } public void setRollbackOnly() throws IllegalStateException, SystemException { status = Status.STATUS_MARKED_ROLLBACK; } public void registerSynchronization(Synchronization synchronization) throws RollbackException, IllegalStateException, SystemException { // todo : find the spec-allowable statuses during which synch can be registered... if ( synchronizations == null ) { synchronizations = new LinkedList(); } synchronizations.add( synchronization ); } public void enlistConnection(Connection connection) { if ( this.connection != null ) { throw new IllegalStateException( "Connection already registered" ); } this.connection = connection; } public Connection getEnlistedConnection() { return connection; } public boolean enlistResource(XAResource xaResource) throws RollbackException, IllegalStateException, SystemException { return false; } public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException { return false
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/util/DualNodeJtaTransactionImpl.java File path: /hibernate-distribution-3.3.2.GA/project/testing/src/main/java/org/hibernate/test/tm/SimpleJtaTransactionImpl.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class DualNodeJtaTransactionImpl implements Transaction {
1
public class SimpleJtaTransactionImpl implements Transaction {
2
	private static final Logger log = LoggerFactory.getLogger( DualNodeJtaTransactionImpl.class );
2
	private static final Logger log = LoggerFactory.getLogger( SimpleJtaTransactionImpl.class );
3
	private int status;
3
	private int status;
4
	private LinkedList synchronizations;
4
	private LinkedList synchronizations;
5
	private Connection connection; // the only resource we care about is jdbc connection
5
	private Connection connection; // the only resource we care about is jdbc connection
6
	private final DualNodeJtaTransactionManagerImpl jtaTransactionManager;
6
	private final SimpleJtaTransactionManagerImpl jtaTransactionManager;
7
	public DualNodeJtaTransactionImpl(DualNodeJtaTransactionManagerImpl jtaTransactionManager) {
7
	public SimpleJtaTransactionImpl(SimpleJtaTransactionManagerImpl jtaTransactionManager) {
8
		this.jtaTransactionManager = jtaTransactionManager;
8
		this.jtaTransactionManager = jtaTransactionManager;
9
		this.status = Status.STATUS_ACTIVE;
9
		this.status = Status.STATUS_ACTIVE;
10
	}
10
	}
11
	public int getStatus() {
11
	public int getStatus() {
12
		return status;
12
		return status;
13
	}
13
	}
14
	public void commit()
14
	public void commit()
15
			throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
15
			throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
16
		if ( status == Status.STATUS_MARKED_ROLLBACK ) {
16
		if ( status == Status.STATUS_MARKED_ROLLBACK ) {
17
			log.trace( "on commit, status was marked for rollback-only" );
17
			log.trace( "on commit, status was marked for rollback-only" );
18
			rollback();
18
			rollback();
19
		}
19
		}
20
		else {
20
		else {
21
			status = Status.STATUS_PREPARING;
21
			status = Status.STATUS_PREPARING;
22
			for ( int i = 0; i < synchronizations.size(); i++ ) {
22
			for ( int i = 0; i < synchronizations.size(); i++ ) {
23
				Synchronization s = ( Synchronization ) synchronizations.get( i );
23
				Synchronization s = ( Synchronization ) synchronizations.get( i );
24
				s.beforeCompletion();
24
				s.beforeCompletion();
25
			}
25
			}
26
			status = Status.STATUS_COMMITTING;
26
			status = Status.STATUS_COMMITTING;
27
			if ( connection != null ) {
27
			if ( connection != null ) {
28
				try {
28
				try {
29
					connection.commit();
29
					connection.commit();
30
					connection.close();
30
					connection.close();
31
				}
31
				}
32
				catch ( SQLException sqle ) {
32
				catch ( SQLException sqle ) {
33
					status = Status.STATUS_UNKNOWN;
33
					status = Status.STATUS_UNKNOWN;
34
					throw new SystemException();
34
					throw new SystemException();
35
				}
35
				}
36
			}
36
			}
37
			status = Status.STATUS_COMMITTED;
37
			status = Status.STATUS_COMMITTED;
38
			for ( int i = 0; i < synchronizations.size(); i++ ) {
38
			for ( int i = 0; i < synchronizations.size(); i++ ) {
39
				Synchronization s = ( Synchronization ) synchronizations.get( i );
39
				Synchronization s = ( Synchronization ) synchronizations.get( i );
40
				s.afterCompletion( status );
40
				s.afterCompletion( status );
41
			}
41
			}
42
			//status = Status.STATUS_NO_TRANSACTION;
42
			//status = Status.STATUS_NO_TRANSACTION;
43
			jtaTransactionManager.endCurrent( this );
43
			jtaTransactionManager.endCurrent( this );
44
		}
44
		}
45
	}
45
	}
46
	public void rollback() throws IllegalStateException, SystemException {
46
	public void rollback() throws IllegalStateException, SystemException {
47
		status = Status.STATUS_ROLLEDBACK;
47
		status = Status.STATUS_ROLLEDBACK;
48
		if ( connection != null ) {
48
		if ( connection != null ) {
49
			try {
49
			try {
50
				connection.rollback();
50
				connection.rollback();
51
				connection.close();
51
				connection.close();
52
			}
52
			}
53
			catch ( SQLException sqle ) {
53
			catch ( SQLException sqle ) {
54
				status = Status.STATUS_UNKNOWN;
54
				status = Status.STATUS_UNKNOWN;
55
				throw new SystemException();
55
				throw new SystemException();
56
			}
56
			}
57
		}
57
		}
58
		if (synchronizations != null) {
58
		
59
   		    for ( int i = 0; i < synchronizations.size(); i++ ) {
59
for ( int i = 0; i < synchronizations.size(); i++ ) {
60
   			    Synchronization s = ( Synchronization ) synchronizations.get( i );
60
			Synchronization s = ( Synchronization ) synchronizations.get( i );
61
   			    s.afterCompletion( status );
61
			s.afterCompletion( status );
62
   		    }
63
		}
62
		}
64
		//status = Status.STATUS_NO_TRANSACTION;
63
		//status = Status.STATUS_NO_TRANSACTION;
65
		jtaTransactionManager.endCurrent( this );
64
		jtaTransactionManager.endCurrent( this );
66
	}
65
	}
67
	public void setRollbackOnly() throws IllegalStateException, SystemException {
66
	public void setRollbackOnly() throws IllegalStateException, SystemException {
68
		status = Status.STATUS_MARKED_ROLLBACK;
67
		status = Status.STATUS_MARKED_ROLLBACK;
69
	}
68
	}
70
	public void registerSynchronization(Synchronization synchronization)
69
	public void registerSynchronization(Synchronization synchronization)
71
			throws RollbackException, IllegalStateException, SystemException {
70
			throws RollbackException, IllegalStateException, SystemException {
72
		// todo : find the spec-allowable statuses during which synch can be registered...
71
		// todo : find the spec-allowable statuses during which synch can be registered...
73
		if ( synchronizations == null ) {
72
		if ( synchronizations == null ) {
74
			synchronizations = new LinkedList();
73
			synchronizations = new LinkedList();
75
		}
74
		}
76
		synchronizations.add( synchronization );
75
		synchronizations.add( synchronization );
77
	}
76
	}
78
	public void enlistConnection(Connection connection) {
77
	public void enlistConnection(Connection connection) {
79
		if ( this.connection != null ) {
78
		if ( this.connection != null ) {
80
			throw new IllegalStateException( "Connection already registered" );
79
			throw new IllegalStateException( "Connection already registered" );
81
		}
80
		}
82
		this.connection = connection;
81
		this.connection = connection;
83
	}
82
	}
84
	public Connection getEnlistedConnection() {
83
	public Connection getEnlistedConnection() {
85
		return connection;
84
		return connection;
86
	}
85
	}
87
	public boolean enlistResource(XAResource xaResource)
86
	public boolean enlistResource(XAResource xaResource)
88
			throws RollbackException, IllegalStateException, SystemException {
87
			throws RollbackException, IllegalStateException, SystemException {
89
		return false;
88
		return false;
90
	}
89
	}
91
	public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException {
90
	public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException {
92
		return false
91
		return false
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0