KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > net > NetXAConnectionReply


1 /*
2
3    Derby - Class org.apache.derby.client.net.NetXAConnectionReply
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.net;
23
24 import javax.transaction.xa.XAResource JavaDoc;
25 import javax.transaction.xa.Xid JavaDoc;
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     //----------------------------- entry points ---------------------------------
35

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) { // xaretval of read-only, make sure flag agrees
86
callInfo.setReadOnlyTransactionFlag(true);
87         } else { // xaretval NOT read-only, make sure flag agrees
88
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     //----------------------helper methods----------------------------------------
128

129     //--------------------- parse DDM Reply Data--------------------------------------
130

131
132     // The SYNCCRD Reply Mesage
133
//
134
// Returned from Server:
135
// XARETVAL - required
136
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 JavaDoc 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     // Process XA return value
192
protected int parseXARETVAL() throws DisconnectException {
193         parseLengthAndMatchCodePoint(CodePoint.XARETVAL);
194         return readInt();
195     }
196
197     // Process XA return value
198
protected byte parseSYNCTYPE() throws DisconnectException {
199         parseLengthAndMatchCodePoint(CodePoint.SYNCTYPE);
200         return readByte();
201     }
202
203     // This method handles the parsing of all command replies and reply data
204
// for the SYNNCTL command.
205
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 JavaDoc s = parseSQLSTT();
218             //JCFTMP, need to null out the client list?
219
netAgent_.netConnection_.xares_.addSpecialRegisters(s);
220             peekCP = peekCodePoint();
221         }
222
223         return retval;
224     }
225
226
227     //------------------------parse DDM Scalars-----------------------------
228

229
230
231
232     private String JavaDoc parseSQLSTT() throws DisconnectException {
233         parseLengthAndMatchCodePoint(CodePoint.SQLSTT);
234         return parseSQLSTTGRPNOCMorNOCS();
235     }
236
237     private String JavaDoc parseSQLSTTGRPNOCMorNOCS() throws DisconnectException {
238         int mixedNullInd = readUnsignedByte();
239         int singleNullInd = 0;
240         String JavaDoc sqlsttString = null;
241         int stringLength = 0;
242
243         if (mixedNullInd == CodePoint.NULLDATA) {
244             singleNullInd = readUnsignedByte();
245             if (singleNullInd == CodePoint.NULLDATA) {
246                 // throw DTAMCHRM
247
doDtamchrmSemantics();
248             }
249             // read 4-byte length
250
stringLength = readInt();
251             // read sqlstt string
252
sqlsttString = readString(stringLength, netAgent_.targetTypdef_.getCcsidSbcEncoding());
253         } else {
254             // read 4-byte length
255
stringLength = readInt();
256             // read sqlstt string
257
sqlsttString = readString(stringLength, netAgent_.targetTypdef_.getCcsidMbcEncoding());
258             // read null indicator
259
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 JavaDoc 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 JavaDoc parseIndoubtList() throws DisconnectException {
282         boolean found = false;
283         int port = 0;
284         int numXid = 0;
285         String JavaDoc 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 JavaDoc indoubtTransactions = new java.util.Hashtable JavaDoc();
296         while (peekCP == CodePoint.XID) {
297             Xid JavaDoc 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