1 21 22 package org.apache.derby.client.net; 23 24 import javax.transaction.xa.XAResource ; 25 import javax.transaction.xa.Xid ; 26 27 import org.apache.derby.client.am.ConnectionCallbackInterface; 28 import org.apache.derby.client.am.DisconnectException; 29 30 public class NetXAConnectionReply extends NetResultSetReply { 31 NetXAConnectionReply(NetAgent netAgent, int bufferSize) { 32 super(netAgent, bufferSize); 33 } 34 36 37 public void readLocalXAStart(ConnectionCallbackInterface connection) throws DisconnectException { 38 } 39 40 public void readLocalXACommit(ConnectionCallbackInterface connection) throws DisconnectException { 41 42 startSameIdChainParse(); 43 parseSYNCCTLreply(connection); 44 endOfSameIdChainData(); 45 46 NetXACallInfo callInfo = 47 netAgent_.netConnection_.xares_.callInfoArray_[netAgent_.netConnection_.currXACallInfoOffset_]; 48 callInfo.xaInProgress_ = false; 49 callInfo.xaWasSuspended = false; 50 connection.completeLocalCommit(); 51 } 52 53 public void readLocalXARollback(ConnectionCallbackInterface connection) throws DisconnectException { 54 startSameIdChainParse(); 55 parseSYNCCTLreply(connection); 56 endOfSameIdChainData(); 57 connection.completeLocalRollback(); 58 } 59 60 protected void readXaStartUnitOfWork(NetConnection conn) throws DisconnectException { 61 startSameIdChainParse(); 62 parseSYNCCTLreply(conn); 63 endOfSameIdChainData(); 64 } 65 66 protected int readXaEndUnitOfWork(NetConnection conn) throws DisconnectException { 67 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 68 int xaFlags = callInfo.xaFlags_; 69 70 startSameIdChainParse(); 71 parseSYNCCTLreply(conn); 72 endOfSameIdChainData(); 73 if (xaFlags == XAResource.TMFAIL) { 74 return javax.transaction.xa.XAException.XA_RBROLLBACK; 75 } 76 return javax.transaction.xa.XAResource.XA_OK; 77 } 78 79 protected int readXaPrepare(NetConnection conn) throws DisconnectException { 80 startSameIdChainParse(); 81 int synctype = parseSYNCCTLreply(conn); 82 endOfSameIdChainData(); 83 84 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 85 if (synctype == XAResource.XA_RDONLY) { callInfo.setReadOnlyTransactionFlag(true); 87 } else { callInfo.setReadOnlyTransactionFlag(false); 89 } 90 return synctype; 91 } 92 93 protected void readXaCommit(NetConnection conn) throws DisconnectException { 94 startSameIdChainParse(); 95 parseSYNCCTLreply(conn); 96 endOfSameIdChainData(); 97 98 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 99 callInfo.xaInProgress_ = false; 100 conn.completeLocalCommit(); 101 } 102 103 protected int readXaRollback(NetConnection conn) throws DisconnectException { 104 startSameIdChainParse(); 105 parseSYNCCTLreply(conn); 106 endOfSameIdChainData(); 107 108 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 109 callInfo.xaInProgress_ = false; 110 callInfo.xaWasSuspended = false; 111 conn.completeLocalRollback(); 112 113 return javax.transaction.xa.XAResource.XA_OK; 114 } 115 116 protected void readXaRecover(NetConnection conn) throws DisconnectException { 117 startSameIdChainParse(); 118 parseSYNCCTLreply(conn); 119 endOfSameIdChainData(); 120 } 121 122 protected void readXaForget(NetConnection conn) throws DisconnectException { 123 startSameIdChainParse(); 124 parseSYNCCTLreply(conn); 125 endOfSameIdChainData(); 126 } 127 129 131 132 int parseSYNCCRD(ConnectionCallbackInterface connection) throws DisconnectException { 137 boolean svrcodReceived = false; 138 int svrcod = CodePoint.SVRCOD_INFO; 139 int xaretval = 0; 140 int synctype = 0; 141 java.util.Hashtable indoubtTransactions = null; 142 NetConnection conn = netAgent_.netConnection_; 143 144 parseLengthAndMatchCodePoint(CodePoint.SYNCCRD); 145 pushLengthOnCollectionStack(); 146 int peekCP = peekCodePoint(); 147 148 while (peekCP != Reply.END_OF_COLLECTION) { 149 150 boolean foundInPass = false; 151 152 if (peekCP == CodePoint.SVRCOD) { 153 foundInPass = true; 154 svrcodReceived = checkAndGetReceivedFlag(svrcodReceived); 155 svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR, CodePoint.SVRCOD_ERROR); 156 peekCP = peekCodePoint(); 157 } 158 159 if (peekCP == CodePoint.XARETVAL) { 160 foundInPass = true; 161 xaretval = parseXARETVAL(); 162 conn.xares_.callInfoArray_[conn.currXACallInfoOffset_].xaRetVal_ = 163 xaretval; 164 peekCP = peekCodePoint(); 165 } 166 167 if (peekCP == CodePoint.SYNCTYPE) { 168 foundInPass = true; 169 synctype = parseSYNCTYPE(); 170 peekCP = peekCodePoint(); 171 } 172 173 if (peekCP == CodePoint.PRPHRCLST) { 174 foundInPass = true; 175 indoubtTransactions = parseIndoubtList(); 176 conn.setIndoubtTransactions(indoubtTransactions); 177 peekCP = peekCodePoint(); 178 } 179 180 if (!foundInPass) { 181 doPrmnsprmSemantics(peekCP); 182 } 183 } 184 popCollectionStack(); 185 186 187 return xaretval; 188 189 } 190 191 protected int parseXARETVAL() throws DisconnectException { 193 parseLengthAndMatchCodePoint(CodePoint.XARETVAL); 194 return readInt(); 195 } 196 197 protected byte parseSYNCTYPE() throws DisconnectException { 199 parseLengthAndMatchCodePoint(CodePoint.SYNCTYPE); 200 return readByte(); 201 } 202 203 protected int parseSYNCCTLreply(ConnectionCallbackInterface connection) throws DisconnectException { 206 int retval = 0; 207 int peekCP = peekCodePoint(); 208 209 if (peekCP != CodePoint.SYNCCRD) { 210 parseSYNCCTLError(peekCP); 211 return -1; 212 } 213 retval = parseSYNCCRD(connection); 214 215 peekCP = peekCodePoint(); 216 while (peekCP == CodePoint.SQLSTT) { 217 String s = parseSQLSTT(); 218 netAgent_.netConnection_.xares_.addSpecialRegisters(s); 220 peekCP = peekCodePoint(); 221 } 222 223 return retval; 224 } 225 226 227 229 230 231 232 private String parseSQLSTT() throws DisconnectException { 233 parseLengthAndMatchCodePoint(CodePoint.SQLSTT); 234 return parseSQLSTTGRPNOCMorNOCS(); 235 } 236 237 private String parseSQLSTTGRPNOCMorNOCS() throws DisconnectException { 238 int mixedNullInd = readUnsignedByte(); 239 int singleNullInd = 0; 240 String sqlsttString = null; 241 int stringLength = 0; 242 243 if (mixedNullInd == CodePoint.NULLDATA) { 244 singleNullInd = readUnsignedByte(); 245 if (singleNullInd == CodePoint.NULLDATA) { 246 doDtamchrmSemantics(); 248 } 249 stringLength = readInt(); 251 sqlsttString = readString(stringLength, netAgent_.targetTypdef_.getCcsidSbcEncoding()); 253 } else { 254 stringLength = readInt(); 256 sqlsttString = readString(stringLength, netAgent_.targetTypdef_.getCcsidMbcEncoding()); 258 singleNullInd = readUnsignedByte(); 260 } 261 return sqlsttString; 262 } 263 264 265 protected int parseXIDCNT() throws DisconnectException { 266 parseLengthAndMatchCodePoint(CodePoint.XIDCNT); 267 return readUnsignedShort(); 268 } 269 270 protected Xid parseXID() throws DisconnectException { 271 parseLengthAndMatchCodePoint(CodePoint.XID); 272 int formatId = readInt(); 273 int gtridLen = readInt(); 274 int bqualLen = readInt(); 275 byte[] gtrid = readBytes(gtridLen); 276 byte[] bqual = readBytes(bqualLen); 277 278 return new org.apache.derby.client.ClientXid(formatId, gtrid, bqual); 279 } 280 281 protected java.util.Hashtable parseIndoubtList() throws DisconnectException { 282 boolean found = false; 283 int port = 0; 284 int numXid = 0; 285 String sIpAddr = null; 286 int peekCP = peekCodePoint(); 287 parseLengthAndMatchCodePoint(CodePoint.PRPHRCLST); 288 peekCP = peekCodePoint(); 289 if (peekCP == CodePoint.XIDCNT) { 290 found = true; 291 numXid = parseXIDCNT(); 292 peekCP = peekCodePoint(); 293 } 294 295 java.util.Hashtable indoubtTransactions = new java.util.Hashtable (); 296 while (peekCP == CodePoint.XID) { 297 Xid xid = parseXID(); 298 indoubtTransactions.put(xid, new NetIndoubtTransaction(xid, null, null, null, sIpAddr, port)); 299 peekCP = peekCodePoint(); 300 } 301 302 return indoubtTransactions; 303 } 304 305 } 306 307 308 309 | Popular Tags |