1 21 22 package org.apache.derby.client.net; 23 24 import org.apache.derby.client.am.DisconnectException; 25 import org.apache.derby.client.am.ResultSet; 26 import org.apache.derby.client.am.ResultSetCallbackInterface; 27 import org.apache.derby.client.am.SqlException; 28 import org.apache.derby.client.am.ClientMessageId; 29 30 import org.apache.derby.shared.common.reference.SQLState; 31 import org.apache.derby.shared.common.reference.MessageId; 32 33 public class NetResultSetReply extends NetStatementReply implements ResultSetReplyInterface { 34 public NetResultSetReply(NetAgent netAgent, int bufferSize) { 35 super(netAgent, bufferSize); 36 } 37 38 40 public void readFetch(ResultSetCallbackInterface resultSet) throws DisconnectException { 41 startSameIdChainParse(); 42 parseCNTQRYreply(resultSet, true); endOfSameIdChainData(); 44 } 45 46 public void readPositioningFetch(ResultSetCallbackInterface resultSet) throws DisconnectException { 47 startSameIdChainParse(); 48 parseCNTQRYreply(resultSet, false); endOfSameIdChainData(); 50 } 51 52 public void readScrollableFetch(ResultSetCallbackInterface resultSet) throws DisconnectException { 53 startSameIdChainParse(); 54 parseCNTQRYreply(resultSet, true); endOfSameIdChainData(); 56 } 57 58 public void readCursorClose(ResultSetCallbackInterface resultSet) throws DisconnectException { 59 startSameIdChainParse(); 60 parseCLSQRYreply(resultSet); 61 endOfSameIdChainData(); 62 } 63 64 66 68 72 private void parseCLSQRYreply(ResultSetCallbackInterface resultSet) throws DisconnectException { 76 int peekCP = parseTypdefsOrMgrlvlovrs(); 77 78 if (peekCP == CodePoint.SQLCARD) { 79 NetSqlca netSqlca = parseSQLCARD(null); resultSet.completeSqlca(netSqlca); 82 } else { 83 parseCloseError(resultSet); 84 } 85 } 86 87 private void parseCNTQRYreply(ResultSetCallbackInterface resultSetI, 91 boolean doCopyQrydta) throws DisconnectException { 92 boolean found = false; 93 int peekCP = peekCodePoint(); 94 if (peekCP == CodePoint.RDBUPDRM) { 95 found = true; 96 parseRDBUPDRM(); 97 peekCP = peekCodePoint(); 98 } 99 100 if (peekCP == CodePoint.QRYDTA) { 101 found = true; 102 if (!doCopyQrydta) { 103 parseLengthAndMatchCodePoint(CodePoint.QRYDTA); 104 if (longValueForDecryption_ != null) { 106 longValueForDecryption_ = null; 107 } 108 if (longBufferForDecryption_ != null) { 109 longBufferForDecryption_ = null; 110 } 111 112 int ddmLength = getDdmLength(); 113 ensureBLayerDataInBuffer(ddmLength); 114 ((ResultSet) resultSetI).expandRowsetSqlca(); 115 NetSqlca sqlca = parseSQLCARDrow(((ResultSet) resultSetI).rowsetSqlca_); 116 int daNullIndicator = readFastByte(); 117 adjustLengths(getDdmLength()); 118 if (sqlca != null && sqlca.containsSqlcax()) { 121 ((ResultSet) resultSetI).setRowCountEvent(sqlca.getRowCount(netAgent_.targetTypdef_)); 122 } 123 124 peekCP = peekCodePoint(); 125 if (peekCP == CodePoint.RDBUPDRM) { 126 parseRDBUPDRM(); 127 peekCP = peekCodePoint(); 128 } 129 return; 130 } 131 do { 132 parseQRYDTA((NetResultSet) resultSetI); 133 peekCP = peekCodePoint(); 134 } while (peekCP == CodePoint.QRYDTA); 135 } 136 137 if (peekCP == CodePoint.EXTDTA) { 138 found = true; 139 do { 140 copyEXTDTA((NetCursor) ((ResultSet) resultSetI).cursor_); 141 if (longBufferForDecryption_ != null) { buffer_ = longBufferForDecryption_; 143 pos_ = longPosForDecryption_; 144 if (longBufferForDecryption_ != null && count_ > longBufferForDecryption_.length) { 145 count_ = longBufferForDecryption_.length; 146 } 147 } 148 149 peekCP = peekCodePoint(); 150 } while (peekCP == CodePoint.EXTDTA); 151 } 152 153 if (peekCP == CodePoint.SQLCARD) { 154 found = true; 155 ((ResultSet) resultSetI).expandRowsetSqlca(); 156 NetSqlca netSqlca = parseSQLCARD(((ResultSet) resultSetI).rowsetSqlca_); 157 if (((ResultSet) resultSetI).sensitivity_ != ResultSet.sensitivity_sensitive_dynamic__) { 161 if (netSqlca != null && netSqlca.containsSqlcax() && netSqlca.getRowsetRowCount() == 0) { 162 ((ResultSet) resultSetI).setRowCountEvent(netSqlca.getRowCount(netAgent_.targetTypdef_)); 163 } 164 } 165 resultSetI.completeSqlca(netSqlca); 166 peekCP = peekCodePoint(); 167 } 168 169 if (peekCP == CodePoint.ENDQRYRM) { 170 found = true; 171 parseEndQuery(resultSetI); 172 peekCP = peekCodePoint(); 173 } 174 175 if (peekCP == CodePoint.RDBUPDRM) { 176 found = true; 177 parseRDBUPDRM(); 178 } 179 180 if (!found) { 181 parseFetchError(resultSetI); 182 } 183 184 if (longBufferForDecryption_ != null) { 185 buffer_ = new byte[DEFAULT_BUFFER_SIZE]; 187 longBufferForDecryption_ = null; 188 } 189 } 190 191 void parseCloseError(ResultSetCallbackInterface resultSetI) throws DisconnectException { 192 int peekCP = peekCodePoint(); 193 switch (peekCP) { 194 case CodePoint.ABNUOWRM: 195 { 196 NetSqlca sqlca = parseAbnormalEndUow(resultSetI); 200 resultSetI.completeSqlca(sqlca); 201 break; 202 } 203 case CodePoint.CMDCHKRM: 204 parseCMDCHKRM(); 205 break; 206 case CodePoint.QRYNOPRM: 207 parseQRYNOPRM(resultSetI); 208 break; 209 case CodePoint.RDBNACRM: 210 parseRDBNACRM(); 211 break; 212 default: 213 parseCommonError(peekCP); 214 } 215 } 216 217 void parseFetchError(ResultSetCallbackInterface resultSetI) throws DisconnectException { 218 int peekCP = peekCodePoint(); 219 switch (peekCP) { 220 case CodePoint.ABNUOWRM: 221 { 222 NetSqlca sqlca = parseAbnormalEndUow(resultSetI); 226 resultSetI.completeSqlca(sqlca); 227 break; 228 } 229 case CodePoint.CMDCHKRM: 230 parseCMDCHKRM(); 231 break; 232 case CodePoint.CMDNSPRM: 233 parseCMDNSPRM(); 234 break; 235 case CodePoint.QRYNOPRM: 236 parseQRYNOPRM(resultSetI); 237 break; 238 case CodePoint.RDBNACRM: 239 parseRDBNACRM(); 240 break; 241 default: 242 parseCommonError(peekCP); 243 } 244 } 245 246 248 private void parseQRYNOPRM(ResultSetCallbackInterface resultSet) throws DisconnectException { 290 boolean svrcodReceived = false; 291 int svrcod = CodePoint.SVRCOD_INFO; 292 boolean rdbnamReceived = false; 293 String rdbnam = null; 294 boolean pkgnamcsnReceived = false; 295 Object pkgnamcsn = null; 296 297 parseLengthAndMatchCodePoint(CodePoint.QRYNOPRM); 298 pushLengthOnCollectionStack(); 299 int peekCP = peekCodePoint(); 300 301 while (peekCP != Reply.END_OF_COLLECTION) { 302 303 boolean foundInPass = false; 304 305 if (peekCP == CodePoint.SVRCOD) { 306 foundInPass = true; 307 svrcodReceived = checkAndGetReceivedFlag(svrcodReceived); 308 svrcod = parseSVRCOD(CodePoint.SVRCOD_WARNING, CodePoint.SVRCOD_ERROR); 309 peekCP = peekCodePoint(); 310 } 311 312 if (peekCP == CodePoint.RDBNAM) { 313 foundInPass = true; 314 rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived); 315 rdbnam = parseRDBNAM(true); 316 peekCP = peekCodePoint(); 317 } 318 319 if (peekCP == CodePoint.PKGNAMCSN) { 320 foundInPass = true; 321 pkgnamcsnReceived = checkAndGetReceivedFlag(pkgnamcsnReceived); 322 pkgnamcsn = parsePKGNAMCSN(true); 323 peekCP = peekCodePoint(); 324 } 325 326 if (!foundInPass) { 327 doPrmnsprmSemantics(peekCP); 328 } 329 330 } 331 popCollectionStack(); 332 checkRequiredObjects(svrcodReceived, rdbnamReceived, pkgnamcsnReceived); 333 334 netAgent_.setSvrcod(svrcod); 336 if (svrcod == CodePoint.SVRCOD_WARNING) { 337 netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, 338 new ClientMessageId(SQLState.DRDA_CURSOR_NOT_OPEN))); 339 } else { 340 agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_, 341 new ClientMessageId(SQLState.DRDA_CONNECTION_TERMINATED), 342 SqlException.getMessageUtil(). 343 getTextMessage(MessageId.CONN_CURSOR_NOT_OPEN))); 344 } 345 } 346 } 347 348 | Popular Tags |