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;↵
|
93 | | | 92 |
|