1 21 22 package org.apache.derby.client.net; 23 24 import java.sql.SQLException ; 25 26 import javax.transaction.xa.XAException ; 27 import javax.transaction.xa.XAResource ; 28 import javax.transaction.xa.Xid ; 29 30 import org.apache.derby.client.am.SqlException; 31 import org.apache.derby.client.am.Statement; 32 33 import org.apache.derby.client.ClientPooledConnection; 34 import org.apache.derby.client.am.ClientMessageId; 35 import org.apache.derby.shared.common.reference.SQLState; 36 37 import org.apache.derby.jdbc.ClientDriver; 38 39 public class NetXAConnection { 40 private NetConnection netCon; 41 66 public NetXAConnection(NetLogWriter netLogWriter, 67 String user, 68 String password, 69 org.apache.derby.jdbc.ClientBaseDataSource dataSource, 70 int rmId, 71 boolean isXAConn, 72 ClientPooledConnection cpc) throws SqlException { 73 netCon = createNetConnection (netLogWriter, user, password, 74 dataSource, rmId, isXAConn,cpc); 75 checkPlatformVersion(); 76 } 77 78 protected void finalize() throws java.lang.Throwable { 79 netCon.finalize(); 80 } 81 82 public void setCorrelatorToken(byte[] crttoken) { 83 netCon.crrtkn_ = crttoken; 84 } 85 86 public byte[] getCorrelatorToken() { 87 return netCon.crrtkn_; 88 } 89 90 void setNetXAResource(NetXAResource xares) { 91 netCon.xares_ = xares; 92 } 93 94 public void writeLocalXAStart_() throws SqlException { 95 netCon.netAgent_.netConnectionRequest_.writeLocalXAStart(netCon); 96 } 97 98 public void readLocalXAStart_() throws SqlException { 99 netCon.netAgent_.netConnectionReply_.readLocalXAStart(netCon); 100 } 101 102 public void writeLocalXACommit_() throws SqlException { 103 netCon.netAgent_.netConnectionRequest_.writeLocalXACommit(netCon); 104 } 105 106 public void readLocalXACommit_() throws SqlException { 107 netCon.netAgent_.netConnectionReply_.readLocalXACommit(netCon); 108 } 109 110 public void writeLocalXARollback_() throws SqlException { 111 netCon.netAgent_.netConnectionRequest_.writeLocalXARollback(netCon); 112 } 113 114 public void readLocalXARollback_() throws SqlException { 115 netCon.netAgent_.netConnectionReply_.readLocalXARollback(netCon); 116 } 117 118 public void writeTransactionStart(Statement statement) throws SqlException { 119 if (!netCon.isXAConnection()) { 121 return; } 123 124 int xaState = netCon.getXAState(); 126 netCon.xares_.exceptionsOnXA = null; 127 138 return; 141 } 142 143 public byte[] getUOWID(Xid xid) { 144 NetIndoubtTransaction indoubtTxn = 145 (NetIndoubtTransaction) netCon.indoubtTransactions_.get(xid); 146 if (indoubtTxn == null) { 147 return null; 148 } 149 byte[] uowid = indoubtTxn.getUOWID(); 150 return uowid; 151 } 152 153 public int getPort(Xid xid) { 154 NetIndoubtTransaction indoubtTxn = (NetIndoubtTransaction) netCon.indoubtTransactions_.get(xid); 155 if (indoubtTxn == null) { 156 return -1; 157 } 158 return indoubtTxn.getPort(); 159 } 160 161 public void writeCommit() throws SqlException { 162 int xaState = netCon.getXAState(); 164 if (xaState == netCon.XA_T0_NOT_ASSOCIATED){ 165 netCon.xares_.callInfoArray_[ 166 netCon.xares_.conn_.currXACallInfoOffset_ 167 ].xid_ = NetXAResource.nullXid; 168 writeLocalXACommit_(); 169 } 170 } 171 172 public void readCommit() throws SqlException { 173 int xaState = netCon.getXAState(); 174 NetXACallInfo callInfo = netCon.xares_.callInfoArray_ 175 [netCon.currXACallInfoOffset_]; 176 callInfo.xaRetVal_ = XAResource.XA_OK; if (xaState == netCon.XA_T0_NOT_ASSOCIATED) { 178 readLocalXACommit_(); 179 } 182 if (callInfo.xaRetVal_ != XAResource.XA_OK) { callInfo.xaFunction_ = NetXAResource.XAFUNC_COMMIT; 184 netCon.xares_.xaRetValErrorAccumSQL(callInfo, 0); 185 callInfo.xaRetVal_ = XAResource.XA_OK; throw netCon.xares_.exceptionsOnXA; 187 } 188 } 189 190 public void writeRollback() throws SqlException { 191 netCon.xares_.callInfoArray_[ 192 netCon.xares_.conn_.currXACallInfoOffset_ 193 ].xid_ = netCon.xares_.nullXid; 194 writeLocalXARollback_(); 195 } 196 197 public void readRollback() throws SqlException { 198 NetXACallInfo callInfo = netCon.xares_.callInfoArray_ 199 [netCon.currXACallInfoOffset_]; 200 callInfo.xaRetVal_ = XAResource.XA_OK; readLocalXARollback_(); 202 203 if (callInfo.xaRetVal_ != XAResource.XA_OK) { callInfo.xaFunction_ = NetXAResource.XAFUNC_ROLLBACK; 205 netCon.xares_.xaRetValErrorAccumSQL(callInfo, 0); 206 callInfo.xaRetVal_ = XAResource.XA_OK; throw netCon.xares_.exceptionsOnXA; 208 } 209 210 211 netCon.setXAState(netCon.XA_T0_NOT_ASSOCIATED); 214 } 215 216 220 public NetConnection getNetConnection () { 221 return netCon; 222 } 223 224 private void checkPlatformVersion() throws SqlException { 225 int supportedVersion; 226 227 supportedVersion = 8; 228 229 if (netCon.xaHostVersion_ >= supportedVersion) { 230 return; 232 } 233 234 String platform = null; 236 platform = "Linux, Unix, Windows"; 237 throw new SqlException(netCon.agent_.logWriter_, 238 new ClientMessageId(SQLState.NET_WRONG_XA_VERSION), 239 platform, new Integer (supportedVersion), 240 new Integer (netCon.xaHostVersion_)); 241 } 242 243 262 protected NetConnection createNetConnection (NetLogWriter netLogWriter, 263 String user, 264 String password, 265 org.apache.derby.jdbc.ClientBaseDataSource dataSource, 266 int rmId, 267 boolean isXAConn, 268 ClientPooledConnection cpc) throws SqlException { 269 return (NetConnection)ClientDriver.getFactory().newNetConnection 270 (netLogWriter, user, password,dataSource, rmId, isXAConn,cpc); 271 } 272 } 273 | Popular Tags |