1 21 package org.apache.derby.client.net; 22 23 import org.apache.derby.client.am.Cursor; 24 import org.apache.derby.client.am.DisconnectException; 25 import org.apache.derby.client.am.Section; 26 import org.apache.derby.client.am.SqlException; 27 28 29 public class NetResultSet extends org.apache.derby.client.am.ResultSet { 30 private final NetConnection netConnection_; 32 33 private final NetStatement netStatement_; 35 36 final NetCursor netCursor_; 38 39 final private NetAgent netAgent_; 41 42 private boolean isFixedRowProtocol = false; 45 46 48 public boolean firstOutovrBuilt_ = false; 50 51 53 55 NetResultSet(NetAgent netAgent, 56 NetStatement netStatement, 57 Cursor cursor, 58 int qryprctyp, int sqlcsrhld, int qryattscr, int qryattsns, int qryattset, long qryinsid, int actualResultSetType, 68 int actualResultSetConcurrency, 69 int actualResultSetHoldability) { 71 super(netAgent, 72 netStatement.statement_, 73 cursor, 75 actualResultSetType, 78 actualResultSetConcurrency, 79 actualResultSetHoldability); 80 81 netAgent_ = netAgent; 82 83 netCursor_ = (NetCursor) cursor_; 85 netStatement_ = netStatement; 86 netConnection_ = netStatement.netConnection_; 87 88 netCursor_.netResultSet_ = this; 89 90 cursorHold_ = (sqlcsrhld != 0xf0); 91 if (qryattscr == 0xF1) { 92 scrollable_ = true; 93 } 94 95 if (qryprctyp == CodePoint.FIXROWPRC) { 98 isFixedRowProtocol = true; 99 fetchSize_ = 1; 100 } else { 101 fetchSize_ = suggestedFetchSize_; 102 } 103 104 switch (qryattsns) { 105 case CodePoint.QRYUNK: 106 sensitivity_ = sensitivity_unknown__; 107 break; 108 case CodePoint.QRYINS: 109 sensitivity_ = sensitivity_insensitive__; 110 break; 111 case CodePoint.QRYSNSSTC: 112 sensitivity_ = sensitivity_sensitive_static__; 113 break; 114 default: break; 116 } 117 118 if (qryattset == 0xF1) { 119 isRowsetCursor_ = true; 120 } 121 122 queryInstanceIdentifier_ = qryinsid; 123 nestingLevel_ = (int) ((queryInstanceIdentifier_ >>> 48) & 0xFFFF); 124 } 125 126 127 129 protected void parseRowset_() throws SqlException { 131 int row = 0; 132 while (netCursor_.calculateColumnOffsetsForRow_(row, true)) { 136 rowsReceivedInCurrentRowset_++; 137 row++; 138 } 139 140 while (rowsReceivedInCurrentRowset_ != fetchSize_ && 147 !netCursor_.allRowsReceivedFromServer() && !isRowsetCursor_ && 148 sensitivity_ != sensitivity_sensitive_dynamic__ && 149 sensitivity_ != sensitivity_sensitive_static__) { 150 flowFetchToCompleteRowset(); 151 while (netCursor_.calculateColumnOffsetsForRow_(row, true)) { 152 rowsReceivedInCurrentRowset_++; 153 row++; 154 } 155 } 156 checkAndThrowReceivedQueryTerminatingException(); 157 } 158 159 public void setFetchSize_(int rows) { 160 suggestedFetchSize_ = (rows == 0) ? 64 : rows; 162 if (!isFixedRowProtocol) { 163 fetchSize_ = suggestedFetchSize_; 164 } 165 } 166 167 169 void flowFetchToCompleteRowset() throws DisconnectException { 170 try { 171 agent_.beginWriteChain(statement_); 172 173 writeScrollableFetch_((generatedSection_ == null) ? statement_.section_ : generatedSection_, 174 fetchSize_ - rowsReceivedInCurrentRowset_, 175 scrollOrientation_relative__, 176 1, 177 false); 180 agent_.flow(statement_); 181 readScrollableFetch_(); 182 agent_.endReadChain(); 183 } catch (SqlException e) { 184 throw new DisconnectException(agent_, e); 185 } 186 } 187 188 void queryDataWasReturnedOnOpen() throws DisconnectException { 189 } 190 191 public void writeFetch_(Section section) throws SqlException { 193 if (resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY && fetchSize_ != 0 && 194 rowsYetToBeReceivedForRowset_ > 0) { 195 netAgent_.resultSetRequest_.writeFetch(this, 196 section, 197 rowsYetToBeReceivedForRowset_); 198 } else { 199 netAgent_.resultSetRequest_.writeFetch(this, 200 section, 201 fetchSize_); 202 } 203 } 204 205 public void readFetch_() throws SqlException { 206 netAgent_.resultSetReply_.readFetch(this); 207 } 208 209 public void writeScrollableFetch_(Section section, 210 int fetchSize, 211 int orientation, 212 long rowToFetch, 213 boolean resetQueryBlocks) throws SqlException { 214 netAgent_.resultSetRequest_.writeScrollableFetch(this, 215 section, 216 fetchSize, 217 orientation, 218 rowToFetch, 219 resetQueryBlocks); 220 } 221 222 public void readScrollableFetch_() throws SqlException { 225 netAgent_.resultSetReply_.readScrollableFetch(this); 226 } 227 228 public void writePositioningFetch_(Section section, 229 int orientation, 230 long rowToFetch) throws SqlException { 231 netAgent_.resultSetRequest_.writePositioningFetch(this, 232 section, 233 orientation, 234 rowToFetch); 235 } 236 237 public void readPositioningFetch_() throws SqlException { 238 netAgent_.resultSetReply_.readPositioningFetch(this); 239 } 240 241 public void writeCursorClose_(Section section) throws SqlException { 242 netAgent_.resultSetRequest_.writeCursorClose(this, section); 243 } 244 245 public void readCursorClose_() throws SqlException { 246 netAgent_.resultSetReply_.readCursorClose(this); 247 } 248 249 258 protected void preClose_() throws SqlException { 259 if (netCursor_.getQryclsimpEnabled()) { 260 netCursor_.scanDataBufferForEndOfData(); 261 } 262 } 263 } 264 | Popular Tags |