001: /*
002:
003: Derby - Class org.apache.derby.client.net.NetPackageReply
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.client.net;
023:
024: import org.apache.derby.client.am.DisconnectException;
025: import org.apache.derby.client.am.ClientMessageId;
026: import org.apache.derby.shared.common.reference.SQLState;
027:
028: public class NetPackageReply extends NetConnectionReply {
029: NetPackageReply(NetAgent netAgent, int bufferSize) {
030: super (netAgent, bufferSize);
031: }
032:
033: NetSqlca parseSqlErrorCondition() throws DisconnectException {
034: parseSQLERRRM();
035: parseTypdefsOrMgrlvlovrs();
036: NetSqlca netSqlca = parseSQLCARD(null);
037: return netSqlca;
038: }
039:
040: // Also called by NetStatementReply
041: void parseDTAMCHRM() throws DisconnectException {
042: boolean svrcodReceived = false;
043: int svrcod = CodePoint.SVRCOD_INFO;
044: boolean rdbnamReceived = false;
045: String rdbnam = null;
046:
047: parseLengthAndMatchCodePoint(CodePoint.DTAMCHRM);
048: pushLengthOnCollectionStack();
049: int peekCP = peekCodePoint();
050:
051: while (peekCP != Reply.END_OF_COLLECTION) {
052:
053: boolean foundInPass = false;
054:
055: if (peekCP == CodePoint.SVRCOD) {
056: foundInPass = true;
057: svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
058: svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR,
059: CodePoint.SVRCOD_ERROR);
060: peekCP = peekCodePoint();
061: }
062:
063: if (peekCP == CodePoint.RDBNAM) {
064: foundInPass = true;
065: rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
066: rdbnam = parseRDBNAM(true);
067: peekCP = peekCodePoint();
068: }
069:
070: if (!foundInPass) {
071: doPrmnsprmSemantics(peekCP);
072: }
073:
074: }
075: popCollectionStack();
076: checkRequiredObjects(svrcodReceived, rdbnamReceived);
077:
078: netAgent_.setSvrcod(svrcod);
079: doDtamchrmSemantics();
080: }
081:
082: // RDB Update Reply Message indicates that a DDM command resulted
083: // in an update at the target relational database. If a command
084: // generated multiple reply messages including an RDBUPDRM, then
085: // the RDBUPDRM must be the first reply message for the command.
086: // For each target server, the RDBUPDRM must be returned the first
087: // time an update is made to the target RDB within a unit of work.
088: // The target server may optionally return the RDBUPDRM after subsequent
089: // updates within the UOW. If multiple target RDBs are involved with
090: // the current UOW and updates are made with any of them, then the RDBUPDRM
091: // must be returned in response to the first update at each of them.
092: protected void parseRDBUPDRM() throws DisconnectException {
093: boolean svrcodReceived = false;
094: int svrcod = CodePoint.SVRCOD_INFO;
095: boolean rdbnamReceived = false;
096: String rdbnam = null;
097:
098: parseLengthAndMatchCodePoint(CodePoint.RDBUPDRM);
099: 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,
118: CodePoint.SVRCOD_INFO);
119: peekCP = peekCodePoint();
120: }
121:
122: if (peekCP == CodePoint.RDBNAM) {
123: foundInPass = true;
124: rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
125: rdbnam = parseRDBNAM(true);
126: peekCP = peekCodePoint();
127: }
128:
129: if (!foundInPass) {
130: doPrmnsprmSemantics(peekCP);
131: }
132:
133: }
134: popCollectionStack();
135: checkRequiredObjects(svrcodReceived, rdbnamReceived);
136:
137: // call an event to indicate the server has been updated
138: netAgent_.setSvrcod(svrcod);
139:
140: }
141:
142: // SQL Error Condition Reply Message indicates that an SQL error
143: // has occurred. It may be sent even though no reply message
144: // precedes the SQLCARD object that is the normal
145: // response to a command when an exception occurs.
146: // The SQLERRM is also used when a BNDSQLSTT command is terminated
147: // by an INTRRDBRQS command.
148: // This reply message must precede an SQLCARD object.
149: // The SQLSTATE is returned in the SQLCARD.
150: //
151: // Returned from Server:
152: // SVRCOD - required (8 - ERROR)
153: // RDBNAM - optional
154: //
155: // Also called by NetResultSetReply and NetStatementReply
156: void parseSQLERRRM() throws DisconnectException {
157: boolean svrcodReceived = false;
158: int svrcod = CodePoint.SVRCOD_INFO;
159: boolean rdbnamReceived = false;
160: String rdbnam = null;
161:
162: parseLengthAndMatchCodePoint(CodePoint.SQLERRRM);
163: pushLengthOnCollectionStack();
164: int peekCP = peekCodePoint();
165:
166: while (peekCP != Reply.END_OF_COLLECTION) {
167:
168: boolean foundInPass = false;
169:
170: if (peekCP == CodePoint.SVRCOD) {
171: foundInPass = true;
172: svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
173: svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR,
174: CodePoint.SVRCOD_ERROR);
175: peekCP = peekCodePoint();
176: }
177:
178: if (peekCP == CodePoint.RDBNAM) {
179: foundInPass = true;
180: rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
181: rdbnam = parseRDBNAM(true);
182: peekCP = peekCodePoint();
183: }
184:
185: if (!foundInPass) {
186: doPrmnsprmSemantics(peekCP);
187: }
188:
189: }
190: popCollectionStack();
191: checkRequiredObjects(svrcodReceived);
192:
193: // move into a method
194: netAgent_.setSvrcod(svrcod);
195: }
196:
197: //--------------------- parse DDM Reply Data--------------------------------------
198:
199: //------------------------parse DDM Scalars-----------------------------
200:
201: // RDB Package Name and Consistency token Scalar Object specifies the
202: // fully qualified name of a relational database package and its
203: // consistency token.
204: protected Object parsePKGNAMCT(boolean skip)
205: throws DisconnectException {
206: parseLengthAndMatchCodePoint(CodePoint.PKGNAMCT);
207: if (skip) {
208: skipBytes();
209: return null;
210: }
211: agent_
212: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
213: agent_, new ClientMessageId(
214: SQLState.DRDA_COMMAND_NOT_IMPLEMENTED),
215: "parsePKGNAMCT"));
216: return null; // to make compiler happy
217: }
218: }
|