KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > net > NetSqldta


1 /*
2
3    Derby - Class org.apache.derby.client.net.NetSqldta
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.net;
23
24
25 public class NetSqldta extends NetCursor {
26     private NetConnection netConnection_;
27
28
29     public NetSqldta(NetAgent netAgent) {
30         super(netAgent);
31         netConnection_ = netAgent.netConnection_;
32     }
33
34     public boolean next() throws org.apache.derby.client.am.SqlException {
35         if (allRowsReceivedFromServer()) {
36             return false;
37         } else {
38             setAllRowsReceivedFromServer(true);
39             return true;
40         }
41     }
42
43     protected boolean calculateColumnOffsetsForRow() {
44         int colNullIndicator = CodePoint.NULLDATA;
45         int length;
46
47         extdtaPositions_.clear(); // reset positions for this row
48

49         // read the da null indicator
50
if (readFdocaOneByte() == 0xff) {
51             return false;
52         }
53
54         incrementRowsReadEvent();
55         // Use the arrays defined on the Cursor for forward-only cursors.
56
// can they ever be null
57
if (columnDataPosition_ == null || columnDataComputedLength_ == null || isNull_ == null) {
58             allocateColumnOffsetAndLengthArrays();
59         }
60
61         // Loop through the columns
62
for (int index = 0; index < columns_; index++) {
63             // If column is nullable, read the 1-byte null indicator.
64
if (nullable_[index])
65             // Need to pass the column index so all previously calculated offsets can be
66
// readjusted if the query block splits on a column null indicator.
67

68             // null indicators from FD:OCA data
69
// 0 to 127: a data value will flow.
70
// -1 to -128: no data value will flow.
71
{
72                 colNullIndicator = readFdocaOneByte();
73             }
74
75             // If non-null column data
76
if (!nullable_[index] || (colNullIndicator >= 0 && colNullIndicator <= 127)) {
77                 isNull_[index] = false;
78
79                 switch (typeToUseForComputingDataLength_[index]) {
80                 // for variable character string and variable byte string,
81
// there are 2-byte of length in front of the data
82
case Typdef.TWOBYTELENGTH:
83                     columnDataPosition_[index] = position_;
84                     length = readFdocaTwoByteLength();
85                     // skip length + the 2-byte length field
86
if (isGraphic_[index]) {
87                         columnDataComputedLength_[index] = skipFdocaBytes(length * 2) + 2;
88                     } else {
89                         columnDataComputedLength_[index] = skipFdocaBytes(length) + 2;
90                     }
91                     break;
92
93                     // for short variable character string and short variable byte string,
94
// there is a 1-byte length in front of the data
95
case Typdef.ONEBYTELENGTH:
96                     columnDataPosition_[index] = position_;
97                     length = readFdocaOneByte();
98                     // skip length + the 1-byte length field
99
if (isGraphic_[index]) {
100                         columnDataComputedLength_[index] = skipFdocaBytes(length * 2) + 1;
101                     } else {
102                         columnDataComputedLength_[index] = skipFdocaBytes(length) + 1;
103                     }
104                     break;
105
106                     // For decimal columns, determine the precision, scale, and the representation
107
case Typdef.DECIMALLENGTH:
108                     columnDataPosition_[index] = position_;
109                     columnDataComputedLength_[index] = skipFdocaBytes(getDecimalLength(index));
110                     break;
111
112                 case Typdef.LOBLENGTH:
113                     columnDataPosition_[index] = position_;
114                     columnDataComputedLength_[index] = this.skipFdocaBytes(fdocaLength_[index] & 0x7fff);
115                     break;
116
117                 default:
118                     columnDataPosition_[index] = position_;
119                     if (isGraphic_[index]) {
120                         columnDataComputedLength_[index] = skipFdocaBytes(fdocaLength_[index] * 2);
121                     } else {
122                         columnDataComputedLength_[index] = skipFdocaBytes(fdocaLength_[index]);
123                     }
124                     break;
125                 }
126             } else if ((colNullIndicator & 0x80) == 0x80) {
127                 // Null data. Set the isNull indicator to true.
128
isNull_[index] = true;
129             }
130         }
131
132         if (!allRowsReceivedFromServer()) {
133             calculateLobColumnPositionsForRow();
134         }
135
136         return true; // hardwired for now, this means the current row position is a valid position
137
}
138
139
140     private int skipFdocaBytes(int length) {
141         position_ += length;
142         return length;
143     }
144
145     private int readFdocaOneByte() {
146         return dataBuffer_[position_++] & 0xff;
147     }
148
149
150     private int readFdocaTwoByteLength() {
151         return
152                 ((dataBuffer_[position_++] & 0xff) << 8) +
153                 ((dataBuffer_[position_++] & 0xff) << 0);
154     }
155
156
157 }
158
159
Popular Tags