1 21 22 package org.apache.derby.client.net; 23 24 import org.apache.derby.client.am.Agent; 25 import org.apache.derby.client.am.Blob; 26 import org.apache.derby.client.am.Clob; 27 import org.apache.derby.client.am.DisconnectException; 28 import org.apache.derby.client.am.SignedBinary; 29 import org.apache.derby.client.am.SqlException; 30 import org.apache.derby.client.am.ClientMessageId; 31 import org.apache.derby.client.am.SqlWarning; 32 import org.apache.derby.client.am.Types; 33 import org.apache.derby.client.am.SqlCode; 34 import org.apache.derby.shared.common.reference.SQLState; 35 import org.apache.derby.shared.common.sanity.SanityManager; 36 37 public class NetCursor extends org.apache.derby.client.am.Cursor { 38 39 NetResultSet netResultSet_; 40 NetAgent netAgent_; 41 42 Typdef qrydscTypdef_; 43 44 int targetSqlamForTypdef_; 45 46 47 int numMddOverrides_; 49 int maximumRowSize_; 50 boolean blocking_; 52 int[] typeToUseForComputingDataLength_; 54 boolean[] isGraphic_; 55 56 java.util.HashMap extdtaPositions_; 58 java.util.ArrayList extdtaData_; 60 61 boolean rtnextrow_ = true; 62 63 65 private boolean qryclsimpEnabled_; 66 67 69 71 NetCursor(NetAgent netAgent) { 72 super(netAgent); 73 netAgent_ = netAgent; 74 numMddOverrides_ = 0; 75 maximumRowSize_ = 0; 76 extdtaPositions_ = new java.util.HashMap (); 77 extdtaData_ = new java.util.ArrayList (); 78 } 79 80 NetCursor(NetAgent netAgent, 81 int qryprctyp) { 83 this(netAgent); 84 if (qryprctyp == CodePoint.FIXROWPRC) { 85 blocking_ = false; 86 } else if (qryprctyp == CodePoint.LMTBLKPRC) { 87 blocking_ = true; 88 } 89 } 90 92 123 protected 124 boolean calculateColumnOffsetsForRow_(int rowIndex, 125 boolean allowServerFetch) 126 throws SqlException, DisconnectException 127 { 128 int daNullIndicator = CodePoint.NULLDATA; 129 int colNullIndicator = CodePoint.NULLDATA; 130 int length; 131 132 int[] columnDataPosition = null; 133 int[] columnDataComputedLength = null; 134 boolean[] columnDataIsNull = null; 135 boolean receivedDeleteHoleWarning = false; 136 boolean receivedRowUpdatedWarning = false; 137 138 if ((position_ == lastValidBytePosition_) && 139 (netResultSet_ != null) && (netResultSet_.scrollable_)) { 140 return false; 141 } 142 143 if (hasLobs_) { 144 extdtaPositions_.clear(); } 146 147 NetSqlca[] netSqlca = this.parseSQLCARD(qrydscTypdef_); 148 149 if (netSqlca != null) { 150 for (int i=0;i<netSqlca.length; i++) { 151 int sqlcode = netSqlca[i].getSqlCode(); 152 if (sqlcode < 0) { 153 throw new SqlException(netAgent_.logWriter_, 154 netSqlca[i]); 155 } else { 156 if (sqlcode == SqlCode.END_OF_DATA.getCode()) { 157 setAllRowsReceivedFromServer(true); 158 if (netResultSet_ != null && 159 netSqlca[i].containsSqlcax()) { 160 netResultSet_.setRowCountEvent( 161 netSqlca[i].getRowCount( 162 qrydscTypdef_)); 163 } 164 } else if (netResultSet_ != null && sqlcode > 0) { 165 String sqlState = netSqlca[i].getSqlState(); 166 if (!sqlState.equals(SQLState.ROW_DELETED) && 167 !sqlState.equals(SQLState.ROW_UPDATED)) { 168 netResultSet_.accumulateWarning( 169 new SqlWarning(agent_.logWriter_, 170 netSqlca[i])); 171 } else { 172 receivedDeleteHoleWarning 173 |= sqlState.equals(SQLState.ROW_DELETED); 174 receivedRowUpdatedWarning 175 |= sqlState.equals(SQLState.ROW_UPDATED); 176 } 177 } 178 } 179 } 180 } 181 182 setIsUpdataDeleteHole(rowIndex, receivedDeleteHoleWarning); 183 setIsRowUpdated(receivedRowUpdatedWarning); 184 185 daNullIndicator = readFdocaOneByte(); 189 190 198 202 if (allRowsReceivedFromServer() && 203 (position_ == lastValidBytePosition_)) { 204 markNextRowPosition(); 205 makeNextRowPositionCurrent(); 206 return false; 207 } 208 209 if (daNullIndicator == 0x0) { 211 212 if (SanityManager.DEBUG && receivedDeleteHoleWarning) { 213 SanityManager.THROWASSERT("Delete hole warning received: nulldata expected"); 214 } 215 incrementRowsReadEvent(); 216 217 if (netResultSet_ != null && netResultSet_.scrollable_) { 221 columnDataPosition = allocateColumnDataPositionArray(rowIndex); 222 columnDataComputedLength = allocateColumnDataComputedLengthArray(rowIndex); 223 columnDataIsNull = allocateColumnDataIsNullArray(rowIndex); 224 setIsUpdataDeleteHole(rowIndex, false); 227 } else { 228 if (columnDataPosition_ == null || columnDataComputedLength_ == null || isNull_ == null) { 231 allocateColumnOffsetAndLengthArrays(); 232 } 233 columnDataPosition = columnDataPosition_; 234 columnDataComputedLength = columnDataComputedLength_; 235 columnDataIsNull = isNull_; 236 } 237 238 for (int index = 0; index < columns_; index++) { 240 if (nullable_[index]) 242 245 { 249 colNullIndicator = readFdocaOneByte(index); 250 } 251 252 if (!nullable_[index] || (colNullIndicator >= 0 && colNullIndicator <= 127)) { 254 255 columnDataIsNull[index] = false; 257 258 switch (typeToUseForComputingDataLength_[index]) { 259 case Typdef.FIXEDLENGTH: 261 columnDataPosition[index] = position_; 262 if (isGraphic_[index]) { 263 columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index] * 2, index); 264 } else { 265 columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index], index); 266 } 267 break; 268 269 case Typdef.TWOBYTELENGTH: 272 columnDataPosition[index] = position_; 273 length = readFdocaTwoByteLength(index); 274 if (isGraphic_[index]) { 276 columnDataComputedLength[index] = skipFdocaBytes(length * 2, index) + 2; 277 } else { 278 columnDataComputedLength[index] = skipFdocaBytes(length, index) + 2; 279 } 280 break; 281 282 case Typdef.DECIMALLENGTH: 284 columnDataPosition[index] = position_; 285 columnDataComputedLength[index] = skipFdocaBytes(getDecimalLength(index), index); 286 break; 287 288 case Typdef.LOBLENGTH: 289 columnDataPosition[index] = position_; 290 columnDataComputedLength[index] = this.skipFdocaBytes(fdocaLength_[index] & 0x7fff, index); 291 break; 292 293 case Typdef.ONEBYTELENGTH: 296 columnDataPosition[index] = position_; 297 length = readFdocaOneByte(index); 298 if (isGraphic_[index]) { 300 columnDataComputedLength[index] = skipFdocaBytes(length * 2, index) + 1; 301 } else { 302 columnDataComputedLength[index] = skipFdocaBytes(length, index) + 1; 303 } 304 break; 305 306 default: 307 columnDataPosition[index] = position_; 308 if (isGraphic_[index]) { 309 columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index] * 2, index); 310 } else { 311 columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index], index); 312 } 313 break; 314 } 315 } else if ((colNullIndicator & 0x80) == 0x80) { 316 columnDataIsNull[index] = true; 318 } 319 } 320 321 columnDataPosition_ = columnDataPosition; 323 columnDataComputedLength_ = columnDataComputedLength; 324 isNull_ = columnDataIsNull; 325 326 if (!allRowsReceivedFromServer()) { 327 calculateLobColumnPositionsForRow(); 328 if (blocking_ && rtnextrow_ && 333 !netResultSet_.scrollable_ && 334 !extdtaPositions_.isEmpty()) { 335 if (allowServerFetch) { 336 netResultSet_.flowFetch(); 337 } else { 338 return false; 339 } 340 } 341 } 342 } else { 343 if (netResultSet_ != null && netResultSet_.scrollable_) { 344 if (receivedDeleteHoleWarning) { 345 setIsUpdataDeleteHole(rowIndex, true); 346 } else { 347 if (SanityManager.DEBUG) { 348 SanityManager 351 .THROWASSERT("Delete hole warning expected"); 352 } 353 } 354 } 355 } 356 357 if (!blocking_ && allRowsReceivedFromServer() && 364 daNullIndicator == 0xFF) { 365 return false; 366 } else { 367 return true; 368 } 369 } 370 371 379 void scanDataBufferForEndOfData() throws SqlException { 380 while (!allRowsReceivedFromServer() && 381 (position_ != lastValidBytePosition_)) { 382 stepNext(false); 383 } 384 } 385 386 protected boolean isDataBufferNull() { 387 if (dataBuffer_ == null) { 388 return true; 389 } else { 390 return false; 391 } 392 } 393 394 protected void allocateDataBuffer() { 395 int length; 396 if (maximumRowSize_ > DssConstants.MAX_DSS_LEN) { 397 length = maximumRowSize_; 398 } else { 399 length = DssConstants.MAX_DSS_LEN; 400 } 401 402 dataBuffer_ = new byte[length]; 403 position_ = 0; 404 lastValidBytePosition_ = 0; 405 } 406 407 protected void allocateDataBuffer(int length) { 408 dataBuffer_ = new byte[length]; 409 } 410 411 412 private int readFdocaInt() throws org.apache.derby.client.am.DisconnectException, SqlException { 413 if ((position_ + 4) > lastValidBytePosition_) { 414 checkAndThrowReceivedEndqryrm(); 416 417 int lastValidByteBeforeFetch = completeSplitRow(); 419 420 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 423 } 424 425 int i = SignedBinary.getInt(dataBuffer_, position_); 426 position_ += 4; 427 return i; 428 } 429 430 private long readFdocaLong() throws 434 org.apache.derby.client.am.DisconnectException, SqlException { 435 if ((position_ + 8) > lastValidBytePosition_) { 436 checkAndThrowReceivedEndqryrm(); 438 439 int lastValidByteBeforeFetch = completeSplitRow(); 441 442 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 445 } 446 447 long i = SignedBinary.getLong(dataBuffer_, position_); 448 position_ += 8; 449 return i; 450 } 451 452 private int readFdocaOneByte() throws org.apache.derby.client.am.DisconnectException, SqlException { 455 if (position_ == lastValidBytePosition_) { 458 checkAndThrowReceivedEndqryrm(); 460 461 int lastValidByteBeforeFetch = completeSplitRow(); 463 464 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 467 } 468 return dataBuffer_[position_++] & 0xff; 469 } 470 471 private int readFdocaOneByte(int index) throws org.apache.derby.client.am.DisconnectException, SqlException { 474 if (position_ == lastValidBytePosition_) { 477 checkAndThrowReceivedEndqryrm(); 479 480 int lastValidByteBeforeFetch = completeSplitRow(index); 482 483 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 486 } 487 return dataBuffer_[position_++] & 0xff; 488 } 489 490 private byte[] readFdocaBytes(int length) throws org.apache.derby.client.am.DisconnectException, SqlException { 495 byte[] b = new byte[length]; 496 ; 497 498 if ((position_ + length) > lastValidBytePosition_) { 501 checkAndThrowReceivedEndqryrm(); 503 504 int lastValidByteBeforeFetch = completeSplitRow(); 506 507 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 510 } 511 512 for (int i = 0; i < length; i++) { 513 b[i] = dataBuffer_[position_++]; 514 } 515 516 return b; 517 } 518 519 private int readFdocaTwoByteLength() throws org.apache.derby.client.am.DisconnectException, SqlException { 523 if ((position_ + 2) > lastValidBytePosition_) { 526 checkAndThrowReceivedEndqryrm(); 528 529 int lastValidByteBeforeFetch = completeSplitRow(); 531 532 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 535 } 536 537 return 538 ((dataBuffer_[position_++] & 0xff) << 8) + 539 ((dataBuffer_[position_++] & 0xff) << 0); 540 } 541 542 private int readFdocaTwoByteLength(int index) throws org.apache.derby.client.am.DisconnectException, SqlException { 543 if ((position_ + 2) > lastValidBytePosition_) { 546 checkAndThrowReceivedEndqryrm(); 548 549 int lastValidByteBeforeFetch = completeSplitRow(index); 551 552 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 555 } 556 557 return 558 ((dataBuffer_[position_++] & 0xff) << 8) + 559 ((dataBuffer_[position_++] & 0xff) << 0); 560 } 561 562 private int skipFdocaBytes(int length) throws org.apache.derby.client.am.DisconnectException, SqlException { 567 if ((position_ + length) > lastValidBytePosition_) { 570 checkAndThrowReceivedEndqryrm(); 572 573 int lastValidByteBeforeFetch = completeSplitRow(); 575 576 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 579 } 580 position_ += length; 581 return length; 582 } 583 584 private int skipFdocaBytes(int length, int index) throws org.apache.derby.client.am.DisconnectException, SqlException { 585 if ((position_ + length) > lastValidBytePosition_) { 588 checkAndThrowReceivedEndqryrm(); 590 591 int lastValidByteBeforeFetch = completeSplitRow(index); 593 594 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 597 } 598 599 position_ += length; 600 return length; 601 } 602 603 private void shiftPartialRowToBeginning() { 608 int length = lastValidBytePosition_ - currentRowPosition_; 610 611 dataBufferStream_.reset(); 613 if (dataBuffer_ != null) { 614 dataBufferStream_.write(dataBuffer_, currentRowPosition_, length); 615 } 616 617 for (int i = 0; i < length; i++) { 618 dataBuffer_[i] = dataBuffer_[currentRowPosition_ + i]; 619 } 620 621 position_ = length - (lastValidBytePosition_ - position_); 622 lastValidBytePosition_ = length; 623 } 624 625 private void adjustColumnOffsetsForColumnsPreviouslyCalculated(int index) { 626 for (int j = 0; j <= index; j++) { 627 columnDataPosition_[j] -= currentRowPosition_; 628 } 629 } 630 631 private void resetCurrentRowPosition() { 632 currentRowPosition_ = 0; 633 } 634 635 void calculateLobColumnPositionsForRow() { 639 int currentPosition = 0; 640 641 for (int i = 0; i < columns_; i++) { 642 if (isNonTrivialDataLob(i)) 643 { 646 extdtaPositions_.put(new Integer (i + 1), new Integer (currentPosition++)); 647 } 648 } 649 } 650 651 boolean isNonTrivialDataLob(int index) { 653 long length = 0L; 654 655 if (isNull_[index] || 656 (jdbcTypes_[index] != Types.BLOB && 657 jdbcTypes_[index] != Types.CLOB)) { 658 return false; 659 } 660 661 int position = columnDataPosition_[index]; 662 663 if (((dataBuffer_[position]) & 0x80) == 0x80) { 665 length = -1; 666 } else { 667 668 byte[] lengthBytes = new byte[columnDataComputedLength_[index]]; 669 byte[] longBytes = new byte[8]; 670 671 System.arraycopy(dataBuffer_, 672 position, 673 lengthBytes, 674 0, 675 columnDataComputedLength_[index]); 676 677 int j = 0; 679 for (int i = 8 - columnDataComputedLength_[index]; i < 8; i++) { 680 longBytes[i] = lengthBytes[j]; 681 j++; 682 } 683 length = SignedBinary.getLong(longBytes, 0); 684 } 685 return (length != 0L) ? true : false; 686 } 687 688 protected void clearLobData_() { 689 extdtaData_.clear(); 690 extdtaPositions_.clear(); 691 } 692 693 NetSqlca[] parseSQLCARD(Typdef typdef) throws org.apache.derby.client.am.DisconnectException, SqlException { 699 return parseSQLCAGRP(typdef); 700 } 701 702 private NetSqlca[] parseSQLCAGRP(Typdef typdef) throws org.apache.derby.client.am.DisconnectException, SqlException { 718 if (readFdocaOneByte() == CodePoint.NULLDATA) { 719 return null; 720 } 721 int sqlcode = readFdocaInt(); 722 byte[] sqlstate = readFdocaBytes(5); 723 byte[] sqlerrproc = readFdocaBytes(8); 724 NetSqlca netSqlca = new NetSqlca(netAgent_.netConnection_, sqlcode, sqlstate, sqlerrproc); 725 726 parseSQLCAXGRP(typdef, netSqlca); 727 728 NetSqlca[] sqlCa = parseSQLDIAGGRP(); 729 730 NetSqlca[] ret_val; 731 if (sqlCa != null) { 732 ret_val = new NetSqlca[sqlCa.length + 1]; 733 System.arraycopy(sqlCa, 0, ret_val, 1, sqlCa.length); 734 } else { 735 ret_val = new NetSqlca[1]; 736 } 737 ret_val[0] = netSqlca; 738 739 return ret_val; 740 } 741 742 private void parseSQLCAXGRP(Typdef typdef, NetSqlca netSqlca) throws DisconnectException, SqlException { 789 if (readFdocaOneByte() == CodePoint.NULLDATA) { 790 netSqlca.setContainsSqlcax(false); 791 return; 792 } 793 794 795 int[] sqlerrd = new int[6]; 797 for (int i = 0; i < sqlerrd.length; i++) { 798 sqlerrd[i] = readFdocaInt(); 799 } 800 801 byte[] sqlwarn = readFdocaBytes(11); 803 804 parseVCS(typdef); 807 808 int varcharLength = readFdocaTwoByteLength(); byte[] sqlerrmc = null; 812 int sqlerrmcCcsid = 0; 813 if (varcharLength != 0) { sqlerrmc = readFdocaBytes(varcharLength); sqlerrmcCcsid = typdef.getCcsidMbc(); 816 skipFdocaBytes(2); } else { 818 varcharLength = readFdocaTwoByteLength(); sqlerrmc = readFdocaBytes(varcharLength); sqlerrmcCcsid = typdef.getCcsidSbc(); 821 } 822 823 netSqlca.setSqlerrd(sqlerrd); 824 netSqlca.setSqlwarnBytes(sqlwarn); 825 netSqlca.setSqlerrmcBytes(sqlerrmc, sqlerrmcCcsid); 826 } 827 828 private NetSqlca[] parseSQLDIAGGRP() throws DisconnectException, SqlException { 830 if (readFdocaOneByte() == CodePoint.NULLDATA) { 831 return null; 832 } 833 834 parseSQLDIAGSTT(); 835 NetSqlca[] sqlca = parseSQLDIAGCI(); 836 parseSQLDIAGCN(); 837 838 return sqlca; 839 } 840 841 private void parseSQLDIAGSTT() throws DisconnectException, SqlException { 844 if (readFdocaOneByte() == CodePoint.NULLDATA) { 845 return; 846 } 847 848 netAgent_.accumulateChainBreakingReadExceptionAndThrow( 850 new DisconnectException(netAgent_, 851 new ClientMessageId(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED), 852 "parseSQLDIAGSTT")); 853 } 854 855 private NetSqlca[] parseSQLDIAGCI() 859 throws DisconnectException, SqlException { 860 int num = readFdocaTwoByteLength(); NetSqlca[] ret_val = null; 862 if (num != 0) { 863 ret_val = new NetSqlca[num]; 864 } 865 866 for (int i = 0; i < num; i++) { 867 ret_val[i] = parseSQLDCROW(); 868 } 869 return ret_val; 870 } 871 872 private void parseSQLDIAGCN() throws DisconnectException, SqlException { 875 if (readFdocaOneByte() == CodePoint.NULLDATA) { 876 return; 877 } 878 879 netAgent_.accumulateChainBreakingReadExceptionAndThrow( 881 new DisconnectException(netAgent_, 882 new ClientMessageId(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED), 883 "parseSQLDIAGCN")); 884 } 885 886 private NetSqlca parseSQLDCGRP() 914 throws DisconnectException, SqlException { 915 916 int sqldcCode = readFdocaInt(); String sqldcState = readFdocaString(5, 918 netAgent_.targetTypdef_.getCcsidSbcEncoding()); int sqldcReason = readFdocaInt(); 921 skipFdocaBytes(12); 923 NetSqlca sqlca = new NetSqlca(netAgent_.netConnection_, 924 sqldcCode, 925 sqldcState, 926 (byte[]) null); 927 928 skipFdocaBytes(49); parseSQLDCTOKS(); 932 String sqldcMsg = parseVCS(qrydscTypdef_); 934 if (sqldcMsg != null) { 935 sqlca.setSqlerrmcBytes(sqldcMsg.getBytes(), 936 netAgent_.targetTypdef_.getByteOrder()); 937 } 938 939 skipFdocaBytes(12); 941 parseSQLDCXGRP(); return sqlca; 943 } 944 945 private NetSqlca parseSQLDCROW() throws DisconnectException, SqlException { 948 return parseSQLDCGRP(); 949 } 950 951 void parseSQLDCTOKS() throws DisconnectException, SqlException { 954 if (readFdocaOneByte() == CodePoint.NULLDATA) { 955 return; 956 } 957 958 netAgent_.accumulateChainBreakingReadExceptionAndThrow( 960 new DisconnectException(netAgent_, 961 new ClientMessageId(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED), 962 "parseSQLDCTOKS")); 963 } 964 965 private void parseSQLDCXGRP() throws DisconnectException, SqlException { 968 if (readFdocaOneByte() == CodePoint.NULLDATA) { 969 return; 970 } 971 972 netAgent_.accumulateChainBreakingReadExceptionAndThrow( 974 new DisconnectException(netAgent_, 975 new ClientMessageId(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED), 976 "parseSQLDCXGRP")); 977 } 978 979 private String parseVCS(Typdef typdefInEffect) throws DisconnectException, SqlException { 980 return readFdocaString(readFdocaTwoByteLength(), 981 typdefInEffect.getCcsidSbcEncoding()); 982 } 983 984 private String readFdocaString(int length, String encoding) throws DisconnectException, SqlException { 986 if (length == 0) { 987 return null; 988 } 989 990 if ((position_ + length) > lastValidBytePosition_) { 993 checkAndThrowReceivedEndqryrm(); 995 996 int lastValidByteBeforeFetch = completeSplitRow(); 998 999 checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); 1002 } 1003 1004 String s = null; 1005 1006 try { 1007 s = new String (dataBuffer_, position_, length, encoding); 1008 } catch (java.io.UnsupportedEncodingException e) { 1009 netAgent_.accumulateChainBreakingReadExceptionAndThrow( 1010 new org.apache.derby.client.am.DisconnectException( 1011 netAgent_, 1012 new ClientMessageId(SQLState.NET_ENCODING_NOT_SUPPORTED), 1013 e)); 1014 } 1015 1016 position_ += length; 1017 return s; 1018 } 1019 1020 void allocateColumnOffsetAndLengthArrays() { 1021 columnDataPosition_ = new int[columns_]; 1022 columnDataComputedLength_ = new int[columns_]; 1023 isNull_ = new boolean[columns_]; 1024 } 1025 1026 void setBlocking(int queryProtocolType) { 1027 if (queryProtocolType == CodePoint.LMTBLKPRC) { 1028 blocking_ = true; 1029 } else { 1030 blocking_ = false; 1031 } 1032 } 1033 1034 protected byte[] findExtdtaData(int column) { 1035 byte[] data = null; 1036 1037 Integer key = new Integer (column); 1039 1040 if (extdtaPositions_.containsKey(key)) { 1041 int extdtaQueuePosition = ((Integer ) extdtaPositions_.get(key)).intValue(); 1043 data = (byte[]) (extdtaData_.get(extdtaQueuePosition)); 1044 } 1045 1046 return data; 1047 } 1048 1049 public Blob getBlobColumn_(int column, Agent agent) throws SqlException { 1050 int index = column - 1; 1051 int dataOffset; 1052 byte[] data; 1053 Blob blob = null; 1054 1055 data = findExtdtaData(column); 1057 1058 if (data != null) { 1059 if (!nullable_[index]) { 1062 dataOffset = 0; 1063 } else { 1064 dataOffset = 1; 1065 } 1066 1067 blob = new Blob(data, agent, dataOffset); 1068 } else { 1069 blob = new Blob(new byte[0], agent, 0); 1070 } 1071 1072 return blob; 1073 } 1074 1075 1076 public Clob getClobColumn_(int column, Agent agent) throws SqlException { 1077 int index = column - 1; 1078 int dataOffset; 1079 byte[] data; 1080 Clob clob = null; 1081 1082 data = findExtdtaData(column); 1084 1085 if (data != null) { 1086 if (!nullable_[index]) { 1089 dataOffset = 0; 1090 } else { 1091 dataOffset = 1; 1092 } 1093 clob = new Clob(agent, data, charsetName_[index], dataOffset); 1094 } else { 1095 clob = new Clob(agent, ""); 1097 } 1098 1099 return clob; 1100 } 1101 1102 public byte[] getClobBytes_(int column, int[] dataOffset ) throws SqlException { 1103 int index = column - 1; 1104 byte[] data = null; 1105 1106 data = findExtdtaData(column); 1108 1109 if (data != null) { 1110 if (!nullable_[index]) { 1113 dataOffset[0] = 0; 1114 } else { 1115 dataOffset[0] = 1; 1116 } 1117 } 1118 1119 return data; 1120 } 1121 1122 void initializeColumnInfoArrays(Typdef typdef, 1124 int columnCount, int targetSqlamForTypdef) throws DisconnectException { 1125 qrydscTypdef_ = typdef; 1126 1127 setNumberOfColumns(columnCount); 1129 fdocaLength_ = new int[columnCount]; 1130 isGraphic_ = new boolean[columnCount]; 1131 typeToUseForComputingDataLength_ = new int[columnCount]; 1132 targetSqlamForTypdef_ = targetSqlamForTypdef; 1133 } 1134 1135 1136 int ensureSpaceForDataBuffer(int ddmLength) { 1137 if (dataBuffer_ == null) { 1138 allocateDataBuffer(); 1139 } 1140 1145 int bytesAvailableInDataBuffer = dataBuffer_.length - lastValidBytePosition_; 1146 1147 if (bytesAvailableInDataBuffer < ddmLength) { 1150 1151 int newBufferSize = 2 * dataBuffer_.length; 1154 1155 while (newBufferSize < ddmLength) { 1156 newBufferSize = 2 * newBufferSize; 1157 } 1158 1159 byte[] tempBuffer = new byte[newBufferSize]; 1160 1161 System.arraycopy(dataBuffer_, 1162 0, 1163 tempBuffer, 1164 0, 1165 lastValidBytePosition_); 1166 1167 dataBuffer_ = tempBuffer; 1169 1170 bytesAvailableInDataBuffer = dataBuffer_.length - lastValidBytePosition_; 1172 } 1173 return bytesAvailableInDataBuffer; 1174 } 1175 1176 protected void getMoreData_() throws SqlException { 1177 if (netResultSet_.resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY) { 1181 resetDataBuffer(); 1182 } 1183 netResultSet_.flowFetch(); 1184 } 1185 1186 public void nullDataForGC() { 1188 super.nullDataForGC(); 1189 qrydscTypdef_ = null; 1190 typeToUseForComputingDataLength_ = null; 1191 isGraphic_ = null; 1192 1193 if (extdtaPositions_ != null) { 1194 extdtaPositions_.clear(); 1195 } 1196 extdtaPositions_ = null; 1197 1198 if (extdtaData_ != null) { 1199 extdtaData_.clear(); 1200 } 1201 extdtaData_ = null; 1202 } 1203 1204 private void checkAndThrowReceivedEndqryrm() throws SqlException { 1211 if (!netResultSet_.openOnServer_) { 1214 SqlException sqlException = null; 1215 int sqlcode = org.apache.derby.client.am.Utils.getSqlcodeFromSqlca(netResultSet_.queryTerminatingSqlca_); 1216 if (sqlcode < 0) { 1217 sqlException = new SqlException(agent_.logWriter_, netResultSet_.queryTerminatingSqlca_); 1218 } else { 1219 sqlException = new SqlException(agent_.logWriter_, 1220 new ClientMessageId(SQLState.NET_QUERY_PROCESSING_TERMINATED)); 1221 } 1222 try { 1223 netResultSet_.closeX(); } catch (SqlException e) { 1225 sqlException.setNextException(e); 1226 } 1227 throw sqlException; 1228 } 1229 } 1230 1231 private void checkAndThrowReceivedEndqryrm(int lastValidBytePositionBeforeFetch) throws SqlException { 1232 if (lastValidBytePosition_ > lastValidBytePositionBeforeFetch) { 1234 return; 1235 } 1236 checkAndThrowReceivedEndqryrm(); 1237 } 1238 1239 private int completeSplitRow() throws DisconnectException, SqlException { 1240 int lastValidBytePositionBeforeFetch = 0; 1241 if (netResultSet_ != null && netResultSet_.scrollable_) { 1242 lastValidBytePositionBeforeFetch = lastValidBytePosition_; 1243 netResultSet_.flowFetchToCompleteRowset(); 1244 } else { 1245 shiftPartialRowToBeginning(); 1247 resetCurrentRowPosition(); 1248 lastValidBytePositionBeforeFetch = lastValidBytePosition_; 1249 netResultSet_.flowFetch(); 1250 } 1251 return lastValidBytePositionBeforeFetch; 1252 } 1253 1254 private int completeSplitRow(int index) throws DisconnectException, SqlException { 1255 int lastValidBytePositionBeforeFetch = 0; 1256 if (netResultSet_ != null && netResultSet_.scrollable_) { 1257 lastValidBytePositionBeforeFetch = lastValidBytePosition_; 1258 netResultSet_.flowFetchToCompleteRowset(); 1259 } else { 1260 shiftPartialRowToBeginning(); 1262 adjustColumnOffsetsForColumnsPreviouslyCalculated(index); 1263 resetCurrentRowPosition(); 1264 lastValidBytePositionBeforeFetch = lastValidBytePosition_; 1265 netResultSet_.flowFetch(); 1266 } 1267 return lastValidBytePositionBeforeFetch; 1268 } 1269 1270 private int[] allocateColumnDataPositionArray(int row) { 1271 int[] columnDataPosition; 1272 if (columnDataPositionCache_.size() == row) { 1273 columnDataPosition = new int[columns_]; 1274 columnDataPositionCache_.add(columnDataPosition); 1275 } else { 1276 columnDataPosition = (int[]) columnDataPositionCache_.get(row); 1277 } 1278 return columnDataPosition; 1279 } 1280 1281 private int[] allocateColumnDataComputedLengthArray(int row) { 1282 int[] columnDataComputedLength; 1283 if (columnDataLengthCache_.size() == row) { 1284 columnDataComputedLength = new int[columns_]; 1285 columnDataLengthCache_.add(columnDataComputedLength); 1286 } else { 1287 columnDataComputedLength = (int[]) columnDataLengthCache_.get(row); 1288 } 1289 return columnDataComputedLength; 1290 } 1291 1292 private boolean[] allocateColumnDataIsNullArray(int row) { 1293 boolean[] columnDataIsNull; 1294 if (columnDataIsNullCache_.size() <= row) { 1295 columnDataIsNull = new boolean[columns_]; 1296 columnDataIsNullCache_.add(columnDataIsNull); 1297 } else { 1298 columnDataIsNull = (boolean[]) columnDataIsNullCache_.get(row); 1299 } 1300 return columnDataIsNull; 1301 } 1302 1303 protected int getDecimalLength(int index) { 1304 return (((fdocaLength_[index] >> 8) & 0xff) + 2) / 2; 1305 } 1306 1307 1313 public final void setAllRowsReceivedFromServer(boolean b) { 1314 if (b && qryclsimpEnabled_) { 1315 netResultSet_.markClosedOnServer(); 1316 } 1317 super.setAllRowsReceivedFromServer(b); 1318 } 1319 1320 1325 final void setQryclsimpEnabled(boolean flag) { 1326 qryclsimpEnabled_ = flag; 1327 } 1328 1329 1334 final boolean getQryclsimpEnabled() { 1335 return qryclsimpEnabled_; 1336 } 1337} 1338 | Popular Tags |