1 package org.csc.phynixx.xa;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import org.csc.phynixx.connection.IPhynixxConnection;
25 import org.csc.phynixx.connection.IPhynixxManagedConnection;
26 import org.csc.phynixx.connection.IPhynixxManagedConnectionListener;
27 import org.csc.phynixx.connection.PhynixxManagedConnectionListenerAdapter;
28
29 import javax.transaction.xa.Xid;
30
31
32
33
34
35 class GlobalTransactionProxy<C extends IPhynixxConnection> extends PhynixxManagedConnectionListenerAdapter<C> implements IPhynixxManagedConnectionListener<C>, ITransactionBinding<C> {
36
37
38
39 private XATransactionalBranch<C> transactionalBranch;
40
41 GlobalTransactionProxy() {
42 }
43
44 XATransactionalBranch<C> getGlobalTransactionalBranch() {
45 return transactionalBranch;
46 }
47
48
49
50
51
52 GlobalTransactionProxy<C> assignTransactionalBranch( XATransactionalBranch<C> transactionalBranch ) {
53 if( this.transactionalBranch!=null) {
54 throw new IllegalStateException("transactionalBranch already assigned");
55 }
56 this.transactionalBranch=transactionalBranch;
57
58 return this;
59 }
60
61 @Override
62 public TransactionBindingType getTransactionBindingType() {
63 return TransactionBindingType.GlobalTransaction;
64 }
65
66
67
68
69 @Override
70 public void release() {
71 if (transactionalBranch != null) {
72 transactionalBranch.getManagedConnection().removeConnectionListener(this);
73
74
75
76
77 }
78 this.transactionalBranch = null;
79
80 }
81
82
83
84
85 @Override
86 public void close() {
87 if (transactionalBranch != null) {
88 XATransactionalBranch<C> branch= this.transactionalBranch;
89 this.release();
90 branch.getManagedConnection().close();
91 }
92
93 }
94
95
96 Xid getXid() {
97 if (transactionalBranch != null) {
98 return this.transactionalBranch.getXid();
99 }
100 return null;
101
102 }
103
104
105 @Override
106 public IPhynixxManagedConnection<C> getConnection() {
107 return this.transactionalBranch.getManagedConnection();
108 }
109
110 }