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.SqlException; 28 29 public class NetXAConnectionRequest extends NetResultSetRequest { 30 NetXAConnectionRequest(NetAgent netAgent, CcsidManager ccsidManager, int bufferSize) { 31 super(netAgent, ccsidManager, bufferSize); 32 } 33 34 36 37 public void writeLocalXACommit(NetConnection conn) throws SqlException { 39 NetXACallInfo callInfo = 40 conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 41 Xid xid = callInfo.xid_; 42 buildSYNCCTLMigrate(); buildSYNCCTLCommit(CodePoint.TMLOCAL, xid); } 45 46 public void writeLocalXARollback(NetConnection conn) throws SqlException { 48 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 49 buildSYNCCTLRollback(CodePoint.TMLOCAL); } 51 52 public void writeXaStartUnitOfWork(NetConnection conn) throws SqlException { 53 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 54 Xid xid = callInfo.xid_; 55 int xaFlags = callInfo.xaFlags_; 56 57 createCommand(); 59 60 markLengthBytes(CodePoint.SYNCCTL); 62 63 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_NEW_UOW); 65 66 if (xid.getFormatId() != -1) { 67 writeXID(CodePoint.XID, xid); 68 } else 69 { 71 writeNullXID(CodePoint.XID); 72 } 73 74 writeXAFlags(CodePoint.XAFLAGS, xaFlags); 75 updateLengthBytes(); 76 } 77 78 public void writeXaEndUnitOfWork(NetConnection conn) throws SqlException { 79 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 80 Xid xid = callInfo.xid_; 81 int xaFlags = callInfo.xaFlags_; 82 83 createCommand(); 84 85 markLengthBytes(CodePoint.SYNCCTL); 87 88 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_END_UOW); 90 91 if (xid.getFormatId() != -1) { 92 writeXID(CodePoint.XID, xid); 93 } else 94 { 96 writeNullXID(CodePoint.XID); 97 } 98 99 writeXAFlags(CodePoint.XAFLAGS, xaFlags); 100 101 updateLengthBytes(); 102 } 103 104 protected void writeXaPrepare(NetConnection conn) throws SqlException { 105 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 106 Xid xid = callInfo.xid_; 107 int xaFlags = XAResource.TMNOFLAGS; 109 110 createCommand(); 111 112 markLengthBytes(CodePoint.SYNCCTL); 114 115 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_PREPARE); 117 118 if (xid.getFormatId() != -1) { 119 writeXID(CodePoint.XID, xid); 120 } else 121 { 123 writeNullXID(CodePoint.XID); 124 } 125 126 writeXAFlags(CodePoint.XAFLAGS, xaFlags); 127 updateLengthBytes(); 128 } 129 130 protected void writeXaCommit(NetConnection conn, Xid xid) throws SqlException { 131 NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_]; 132 int xaFlags = callInfo.xaFlags_; 133 134 createCommand(); 136 137 markLengthBytes(CodePoint.SYNCCTL); 139 140 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_COMMITTED); 142 143 if (xid.getFormatId() != -1) { 144 writeXID(CodePoint.XID, xid); 145 } else 146 { 148 writeNullXID(CodePoint.XID); 149 } 150 151 writeXAFlags(CodePoint.XAFLAGS, xaFlags); 152 updateLengthBytes(); 153 } 154 155 protected void writeXaRollback(NetConnection conn, Xid xid) throws SqlException { 156 int xaFlags = XAResource.TMNOFLAGS; 157 158 createCommand(); 160 161 markLengthBytes(CodePoint.SYNCCTL); 163 164 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_ROLLBACK); 166 167 if (xid.getFormatId() != -1) { 168 writeXID(CodePoint.XID, xid); 169 } else 170 { 172 writeNullXID(CodePoint.XID); 173 } 174 175 writeXAFlags(CodePoint.XAFLAGS, xaFlags); 176 updateLengthBytes(); 177 } 178 179 protected void writeXaRecover(NetConnection conn, int flag) throws SqlException { 180 createCommand(); 182 183 markLengthBytes(CodePoint.SYNCCTL); 185 186 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_INDOUBT); 188 writeXAFlags(CodePoint.XAFLAGS, flag); 189 updateLengthBytes(); 190 } 191 192 protected void writeXaForget(NetConnection conn, Xid xid) throws SqlException { 193 194 createCommand(); 196 197 markLengthBytes(CodePoint.SYNCCTL); 199 200 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_REQ_FORGET); 202 203 writeXID(CodePoint.XID, xid); 204 205 updateLengthBytes(); 206 } 207 208 public void writeSYNCType(int codepoint, int syncType) { 209 writeScalar1Byte(codepoint, syncType); 210 } 211 212 public void writeForget(int codepoint, int value) { 213 writeScalar1Byte(codepoint, value); 214 } 215 216 public void writeReleaseConversation(int codepoint, int value) { 217 writeScalar1Byte(codepoint, value); 218 } 219 220 void writeNullXID(int codepoint) { 221 int nullXID = -1; 222 writeScalar4Bytes(codepoint, nullXID); 223 } 224 225 void writeXID(int codepoint, Xid xid) throws SqlException { 226 int len = 0; 227 int formatId = xid.getFormatId(); 228 byte[] gtrid = xid.getGlobalTransactionId(); 229 byte[] bqual = xid.getBranchQualifier(); 230 231 markLengthBytes(codepoint); 232 233 len = 4; len += (bqual.length + 4); len += (gtrid.length + 4); 237 write4Bytes(formatId); 238 write4Bytes(gtrid.length); 239 write4Bytes(bqual.length); 240 241 ensureLength(offset_ + gtrid.length); 243 System.arraycopy(gtrid, 0, bytes_, offset_, gtrid.length); 244 offset_ += gtrid.length; 245 246 ensureLength(offset_ + bqual.length); 247 System.arraycopy(bqual, 0, bytes_, offset_, bqual.length); 248 offset_ += bqual.length; 249 250 updateLengthBytes(); 251 252 } 253 254 255 void writeXAFlags(int codepoint, int xaFlags) { 256 writeScalar4Bytes(codepoint, xaFlags); 257 } 258 259 260 265 266 267 268 269 void buildSYNCCTLMigrate() throws SqlException { 270 } 271 272 void buildSYNCCTLCommit(int xaFlags, Xid xid) throws SqlException { 273 createCommand(); 274 275 markLengthBytes(CodePoint.SYNCCTL); 277 278 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_COMMITTED); 280 281 if (xid.getFormatId() != -1) { 282 writeXID(CodePoint.XID, xid); 283 } else 284 { 286 writeNullXID(CodePoint.XID); 287 } 288 289 writeXAFlags(CodePoint.XAFLAGS, xaFlags); 290 291 updateLengthBytes(); 292 } 293 294 void buildSYNCCTLRollback(int xaFlags) throws SqlException { 295 createCommand(); 296 297 markLengthBytes(CodePoint.SYNCCTL); 299 300 writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_ROLLBACK); 302 303 writeNullXID(CodePoint.XID); 305 writeXAFlags(CodePoint.XAFLAGS, xaFlags); 306 updateLengthBytes(); 307 } 308 309 } 310 311 312 313 | Popular Tags |