1 | /* |
2 | |
3 | Derby - Class org.apache.derby.client.net.NetPackageReply |
4 | |
5 | Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.client.net; |
22 | |
23 | import org.apache.derby.client.am.DisconnectException; |
24 | import org.apache.derby.client.am.ClientMessageId; |
25 | import org.apache.derby.shared.common.reference.SQLState; |
26 | |
27 | public class NetPackageReply extends NetConnectionReply { |
28 | NetPackageReply(NetAgent netAgent, int bufferSize) { |
29 | super(netAgent, bufferSize); |
30 | } |
31 | |
32 | |
33 | NetSqlca parseSqlErrorCondition() throws DisconnectException { |
34 | parseSQLERRRM(); |
35 | parseTypdefsOrMgrlvlovrs(); |
36 | NetSqlca netSqlca = parseSQLCARD(null); |
37 | return netSqlca; |
38 | } |
39 | |
40 | |
41 | // Also called by NetStatementReply |
42 | void parseDTAMCHRM() throws DisconnectException { |
43 | boolean svrcodReceived = false; |
44 | int svrcod = CodePoint.SVRCOD_INFO; |
45 | boolean rdbnamReceived = false; |
46 | String rdbnam = null; |
47 | |
48 | parseLengthAndMatchCodePoint(CodePoint.DTAMCHRM); |
49 | pushLengthOnCollectionStack(); |
50 | int peekCP = peekCodePoint(); |
51 | |
52 | while (peekCP != Reply.END_OF_COLLECTION) { |
53 | |
54 | boolean foundInPass = false; |
55 | |
56 | if (peekCP == CodePoint.SVRCOD) { |
57 | foundInPass = true; |
58 | svrcodReceived = checkAndGetReceivedFlag(svrcodReceived); |
59 | svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR, CodePoint.SVRCOD_ERROR); |
60 | peekCP = peekCodePoint(); |
61 | } |
62 | |
63 | if (peekCP == CodePoint.RDBNAM) { |
64 | foundInPass = true; |
65 | rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived); |
66 | rdbnam = parseRDBNAM(true); |
67 | peekCP = peekCodePoint(); |
68 | } |
69 | |
70 | if (!foundInPass) { |
71 | doPrmnsprmSemantics(peekCP); |
72 | } |
73 | |
74 | } |
75 | popCollectionStack(); |
76 | checkRequiredObjects(svrcodReceived, rdbnamReceived); |
77 | |
78 | netAgent_.setSvrcod(svrcod); |
79 | doDtamchrmSemantics(); |
80 | } |
81 | |
82 | // RDB Update Reply Message indicates that a DDM command resulted |
83 | // in an update at the target relational database. If a command |
84 | // generated multiple reply messages including an RDBUPDRM, then |
85 | // the RDBUPDRM must be the first reply message for the command. |
86 | // For each target server, the RDBUPDRM must be returned the first |
87 | // time an update is made to the target RDB within a unit of work. |
88 | // The target server may optionally return the RDBUPDRM after subsequent |
89 | // updates within the UOW. If multiple target RDBs are involved with |
90 | // the current UOW and updates are made with any of them, then the RDBUPDRM |
91 | // must be returned in response to the first update at each of them. |
92 | protected void parseRDBUPDRM() throws DisconnectException { |
93 | boolean svrcodReceived = false; |
94 | int svrcod = CodePoint.SVRCOD_INFO; |
95 | boolean rdbnamReceived = false; |
96 | String rdbnam = null; |
97 | |
98 | parseLengthAndMatchCodePoint(CodePoint.RDBUPDRM); |
99 | pushLengthOnCollectionStack(); |
100 | |
101 | // in XA Global transaction we need to know if we have a read-only |
102 | // transaction, if we get a RDBUPDRM this is NOT a read-only transaction |
103 | // currently only XAConnections care about read-only transactions, if |
104 | // non-XA wants this information they will need to initialize the flag |
105 | // at start of UOW |
106 | netAgent_.netConnection_.setReadOnlyTransactionFlag(false); |
107 | |
108 | int peekCP = peekCodePoint(); |
109 | |
110 | while (peekCP != Reply.END_OF_COLLECTION) { |
111 | |
112 | boolean foundInPass = false; |
113 | |
114 | if (peekCP == CodePoint.SVRCOD) { |
115 | foundInPass = true; |
116 | svrcodReceived = checkAndGetReceivedFlag(svrcodReceived); |
117 | svrcod = parseSVRCOD(CodePoint.SVRCOD_INFO, CodePoint.SVRCOD_INFO); |
118 | peekCP = peekCodePoint(); |
119 | } |
120 | |
121 | if (peekCP == CodePoint.RDBNAM) { |
122 | foundInPass = true; |
123 | rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived); |
124 | rdbnam = parseRDBNAM(true); |
125 | peekCP = peekCodePoint(); |
126 | } |
127 | |
128 | if (!foundInPass) { |
129 | doPrmnsprmSemantics(peekCP); |
130 | } |
131 | |
132 | } |
133 | popCollectionStack(); |
134 | checkRequiredObjects(svrcodReceived, rdbnamReceived); |
135 | |
136 | // call an event to indicate the server has been updated |
137 | netAgent_.setSvrcod(svrcod); |
138 | |
139 | } |
140 | |
141 | // SQL Error Condition Reply Message indicates that an SQL error |
142 | // has occurred. It may be sent even though no reply message |
143 | // precedes the SQLCARD object that is the normal |
144 | // response to a command when an exception occurs. |
145 | // The SQLERRM is also used when a BNDSQLSTT command is terminated |
146 | // by an INTRRDBRQS command. |
147 | // This reply message must precede an SQLCARD object. |
148 | // The SQLSTATE is returned in the SQLCARD. |
149 | // |
150 | // Returned from Server: |
151 | // SVRCOD - required (8 - ERROR) |
152 | // RDBNAM - optional |
153 | // |
154 | // Also called by NetResultSetReply and NetStatementReply |
155 | void parseSQLERRRM() throws DisconnectException { |
156 | boolean svrcodReceived = false; |
157 | int svrcod = CodePoint.SVRCOD_INFO; |
158 | boolean rdbnamReceived = false; |
159 | String rdbnam = null; |
160 | |
161 | parseLengthAndMatchCodePoint(CodePoint.SQLERRRM); |
162 | pushLengthOnCollectionStack(); |
163 | int peekCP = peekCodePoint(); |
164 | |
165 | while (peekCP != Reply.END_OF_COLLECTION) { |
166 | |
167 | boolean foundInPass = false; |
168 | |
169 | if (peekCP == CodePoint.SVRCOD) { |
170 | foundInPass = true; |
171 | svrcodReceived = checkAndGetReceivedFlag(svrcodReceived); |
172 | svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR, CodePoint.SVRCOD_ERROR); |
173 | peekCP = peekCodePoint(); |
174 | } |
175 | |
176 | if (peekCP == CodePoint.RDBNAM) { |
177 | foundInPass = true; |
178 | rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived); |
179 | rdbnam = parseRDBNAM(true); |
180 | peekCP = peekCodePoint(); |
181 | } |
182 | |
183 | if (!foundInPass) { |
184 | doPrmnsprmSemantics(peekCP); |
185 | } |
186 | |
187 | } |
188 | popCollectionStack(); |
189 | checkRequiredObjects(svrcodReceived); |
190 | |
191 | // move into a method |
192 | netAgent_.setSvrcod(svrcod); |
193 | } |
194 | |
195 | //--------------------- parse DDM Reply Data-------------------------------------- |
196 | |
197 | //------------------------parse DDM Scalars----------------------------- |
198 | |
199 | // RDB Package Name and Consistency token Scalar Object specifies the |
200 | // fully qualified name of a relational database package and its |
201 | // consistency token. |
202 | protected Object parsePKGNAMCT(boolean skip) throws DisconnectException { |
203 | parseLengthAndMatchCodePoint(CodePoint.PKGNAMCT); |
204 | if (skip) { |
205 | skipBytes(); |
206 | return null; |
207 | } |
208 | agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_, |
209 | new ClientMessageId(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED), |
210 | "parsePKGNAMCT")); |
211 | return null; // to make compiler happy |
212 | } |
213 | } |