001: /*
002:
003: Derby - Class org.apache.derby.client.net.NetSqldta
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: public class NetSqldta extends NetCursor {
025: private NetConnection netConnection_;
026:
027: public NetSqldta(NetAgent netAgent) {
028: super (netAgent);
029: netConnection_ = netAgent.netConnection_;
030: }
031:
032: public boolean next()
033: throws org.apache.derby.client.am.SqlException {
034: if (allRowsReceivedFromServer()) {
035: return false;
036: } else {
037: setAllRowsReceivedFromServer(true);
038: return true;
039: }
040: }
041:
042: protected boolean calculateColumnOffsetsForRow() {
043: int colNullIndicator = CodePoint.NULLDATA;
044: int length;
045:
046: extdtaPositions_.clear(); // reset positions for this row
047:
048: // read the da null indicator
049: if (readFdocaOneByte() == 0xff) {
050: return false;
051: }
052:
053: incrementRowsReadEvent();
054: // Use the arrays defined on the Cursor for forward-only cursors.
055: // can they ever be null
056: if (columnDataPosition_ == null
057: || columnDataComputedLength_ == null || isNull_ == null) {
058: allocateColumnOffsetAndLengthArrays();
059: }
060:
061: // Loop through the columns
062: for (int index = 0; index < columns_; index++) {
063: // If column is nullable, read the 1-byte null indicator.
064: if (nullable_[index])
065: // Need to pass the column index so all previously calculated offsets can be
066: // readjusted if the query block splits on a column null indicator.
067:
068: // null indicators from FD:OCA data
069: // 0 to 127: a data value will flow.
070: // -1 to -128: no data value will flow.
071: {
072: colNullIndicator = readFdocaOneByte();
073: }
074:
075: // If non-null column data
076: if (!nullable_[index]
077: || (colNullIndicator >= 0 && colNullIndicator <= 127)) {
078: isNull_[index] = false;
079:
080: switch (typeToUseForComputingDataLength_[index]) {
081: // for variable character string and variable byte string,
082: // there are 2-byte of length in front of the data
083: case Typdef.TWOBYTELENGTH:
084: columnDataPosition_[index] = position_;
085: length = readFdocaTwoByteLength();
086: // skip length + the 2-byte length field
087: if (isGraphic_[index]) {
088: columnDataComputedLength_[index] = skipFdocaBytes(length * 2) + 2;
089: } else {
090: columnDataComputedLength_[index] = skipFdocaBytes(length) + 2;
091: }
092: break;
093:
094: // for short variable character string and short variable byte string,
095: // there is a 1-byte length in front of the data
096: case Typdef.ONEBYTELENGTH:
097: columnDataPosition_[index] = position_;
098: length = readFdocaOneByte();
099: // skip length + the 1-byte length field
100: if (isGraphic_[index]) {
101: columnDataComputedLength_[index] = skipFdocaBytes(length * 2) + 1;
102: } else {
103: columnDataComputedLength_[index] = skipFdocaBytes(length) + 1;
104: }
105: break;
106:
107: // For decimal columns, determine the precision, scale, and the representation
108: case Typdef.DECIMALLENGTH:
109: columnDataPosition_[index] = position_;
110: columnDataComputedLength_[index] = skipFdocaBytes(getDecimalLength(index));
111: break;
112:
113: case Typdef.LOBLENGTH:
114: columnDataPosition_[index] = position_;
115: columnDataComputedLength_[index] = this
116: .skipFdocaBytes(fdocaLength_[index] & 0x7fff);
117: break;
118:
119: default:
120: columnDataPosition_[index] = position_;
121: if (isGraphic_[index]) {
122: columnDataComputedLength_[index] = skipFdocaBytes(fdocaLength_[index] * 2);
123: } else {
124: columnDataComputedLength_[index] = skipFdocaBytes(fdocaLength_[index]);
125: }
126: break;
127: }
128: } else if ((colNullIndicator & 0x80) == 0x80) {
129: // Null data. Set the isNull indicator to true.
130: isNull_[index] = true;
131: }
132: }
133:
134: if (!allRowsReceivedFromServer()) {
135: calculateLobColumnPositionsForRow();
136: }
137:
138: return true; // hardwired for now, this means the current row position is a valid position
139: }
140:
141: private int skipFdocaBytes(int length) {
142: position_ += length;
143: return length;
144: }
145:
146: private int readFdocaOneByte() {
147: return dataBuffer_[position_++] & 0xff;
148: }
149:
150: private int readFdocaTwoByteLength() {
151: return ((dataBuffer_[position_++] & 0xff) << 8)
152: + ((dataBuffer_[position_++] & 0xff) << 0);
153: }
154:
155: }
|