1 21 22 package org.apache.derby.client.net; 23 24 import org.apache.derby.client.am.ColumnMetaData; 25 import org.apache.derby.client.am.ResultSet; 26 import org.apache.derby.client.am.Section; 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 32 public class NetResultSetRequest extends NetStatementRequest 33 implements ResultSetRequestInterface { 34 public NetResultSetRequest(NetAgent netAgent, CcsidManager ccsidManager, int bufferSize) { 35 super(netAgent, ccsidManager, bufferSize); 36 } 37 38 public void writeFetch(NetResultSet resultSet, 40 Section section, 41 int fetchSize) throws SqlException { 42 boolean sendQryrowset = 45 ((NetStatement) resultSet.statement_.materialStatement_).qryrowsetSentOnOpnqry_; 46 47 boolean sendRtnextdta = false; 48 if (sendQryrowset && resultSet.resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY && 49 ((NetCursor) resultSet.cursor_).hasLobs_) { 50 fetchSize = 1; 51 resultSet.fetchSize_ = 1; 52 sendRtnextdta = true; 53 ((NetCursor) resultSet.cursor_).rtnextrow_ = false; 54 } 55 else if (resultSet.fetchSize_ == 0) { 61 sendQryrowset = false; 62 } 63 64 buildCNTQRY(section, 65 sendQryrowset, 66 resultSet.queryInstanceIdentifier_, 67 fetchSize, 68 sendRtnextdta); 69 70 buildOUTOVR(resultSet, 71 resultSet.resultSetMetaData_, 72 resultSet.firstOutovrBuilt_, 73 ((NetCursor) resultSet.cursor_).hasLobs_); 74 } 75 76 public void writeScrollableFetch(NetResultSet resultSet, 77 Section section, 78 int fetchSize, 79 int orientation, 80 long rowToFetch, 81 boolean resetQueryBlocks) throws SqlException { 82 int protocolOrientation = computePROTOCOLOrientation(orientation); 83 84 boolean sendQryrowset = 94 (resultSet.isRowsetCursor_ || 95 (((NetStatement) resultSet.statement_.materialStatement_).qryrowsetSentOnOpnqry_ && 96 (resultSet.sensitivity_ == ResultSet.sensitivity_sensitive_static__ || 97 ((NetCursor) resultSet.cursor_).blocking_))); 98 99 buildScrollCNTQRY(protocolOrientation, 100 rowToFetch, 101 section, 102 sendQryrowset, 103 resultSet.queryInstanceIdentifier_, 104 fetchSize, 105 resetQueryBlocks); 106 107 buildOUTOVR(resultSet, 108 resultSet.resultSetMetaData_, 109 resultSet.firstOutovrBuilt_, 110 ((NetCursor) resultSet.cursor_).hasLobs_); 111 } 112 113 public void writePositioningFetch(NetResultSet resultSet, 114 Section section, 115 int orientation, 116 long rowToFetch) throws SqlException { 117 int protocolOrientation = computePROTOCOLOrientation(orientation); 118 119 boolean sendQryrowset = 121 resultSet.isRowsetCursor_ || 122 (((NetStatement) resultSet.statement_.materialStatement_).qryrowsetSentOnOpnqry_ && 123 resultSet.sensitivity_ != resultSet.sensitivity_sensitive_dynamic__); 124 125 buildPositioningCNTQRY(protocolOrientation, 126 rowToFetch, 127 section, 128 sendQryrowset, 129 resultSet.queryInstanceIdentifier_, 130 resultSet.fetchSize_); 131 132 buildOUTOVR(resultSet, 133 resultSet.resultSetMetaData_, 134 resultSet.firstOutovrBuilt_, 135 ((NetCursor) resultSet.cursor_).hasLobs_); 136 } 137 138 public void writeCursorClose(NetResultSet resultSet, 139 Section section) throws SqlException { 140 buildCLSQRY(section, 141 resultSet.queryInstanceIdentifier_); 142 } 143 144 149 private void buildCLSQRY(Section section, 150 long queryInstanceIdentifier) 151 throws SqlException { 152 createCommand(); 153 markLengthBytes(CodePoint.CLSQRY); 154 buildPKGNAMCSN(section); 155 buildQRYINSID(queryInstanceIdentifier); 156 updateLengthBytes(); 157 } 158 159 private void buildCNTQRY(Section section, 160 boolean sendQryrowset, 161 long queryInstanceIdentifier, 162 int qryrowsetSize, 163 boolean sendRtnextdta) throws SqlException { 164 buildCoreCNTQRY(section, 165 sendQryrowset, 166 queryInstanceIdentifier, 167 qryrowsetSize); 168 169 if (sendRtnextdta) { 175 buildRTNEXTDTA(CodePoint.RTNEXTALL); 176 } 177 178 179 updateLengthBytes(); 180 } 181 182 private void buildCoreCNTQRY(Section section, 184 boolean sendQryrowset, 185 long queryInstanceIdentifier, 186 int qryrowsetSize) 187 throws SqlException { 188 createCommand(); 189 markLengthBytes(CodePoint.CNTQRY); 190 191 buildPKGNAMCSN(section); buildQRYBLKSZ(); 194 if (sendQryrowset) { 196 buildMAXBLKEXT(-1); } 198 199 buildQRYINSID(queryInstanceIdentifier); 201 202 if (sendQryrowset) { 203 buildQRYROWSET(qryrowsetSize); } 205 } 206 207 private void buildScrollCNTQRY(int scrollOrientation, 209 long rowNumber, 210 Section section, 211 boolean sendQryrowset, 212 long queryInstanceIdentifier, 213 int qryrowsetSize, 214 boolean resetQueryBlocks) 215 throws SqlException { 216 buildCoreCNTQRY(section, 217 sendQryrowset, 218 queryInstanceIdentifier, 219 qryrowsetSize); 220 221 buildQRYSCRORN(scrollOrientation); 223 if (scrollOrientation == CodePoint.QRYSCRABS || scrollOrientation == CodePoint.QRYSCRREL) { 224 buildQRYROWNBR(rowNumber); 225 } 226 227 if (resetQueryBlocks) { 228 buildQRYBLKRST(0xF1); } else { 230 buildQRYBLKRST(0xF0); } 232 233 buildQRYRTNDTA(0xF1); 235 updateLengthBytes(); 236 } 237 238 private void buildPositioningCNTQRY(int scrollOrientation, 240 long rowNumber, 241 Section section, 242 boolean sendQryrowset, 243 long queryInstanceIdentifier, 244 int qryrowsetSize) 245 throws SqlException { 246 createCommand(); 247 markLengthBytes(CodePoint.CNTQRY); 248 249 buildPKGNAMCSN(section); buildQRYBLKSZ(); 252 buildQRYINSID(queryInstanceIdentifier); 254 if (sendQryrowset) { 255 buildQRYROWSET(qryrowsetSize); } 257 258 buildQRYSCRORN(scrollOrientation); 260 if (scrollOrientation == CodePoint.QRYSCRABS || scrollOrientation == CodePoint.QRYSCRREL) { 261 buildQRYROWNBR(rowNumber); } 263 264 buildQRYBLKRST(0xF1); buildQRYRTNDTA(0xF0); 267 268 updateLengthBytes(); } 270 271 private void buildOUTOVR(ResultSet resultSet, 272 ColumnMetaData resultSetMetaData, 273 boolean firstOutovrBuilt, 274 boolean hasLobs) throws SqlException { 275 return; 276 } 277 278 private void buildRTNEXTDTA(int rtnextdta) throws SqlException { 279 writeScalar1Byte(CodePoint.RTNEXTDTA, rtnextdta); 280 } 281 282 private void buildQRYSCRORN(int scrollOrientation) throws SqlException { 283 writeScalar1Byte(CodePoint.QRYSCRORN, scrollOrientation); 284 } 285 286 private void buildQRYBLKRST(int qryblkrst) throws SqlException { 287 writeScalar1Byte(CodePoint.QRYBLKRST, qryblkrst); 288 } 289 290 private void buildQRYROWNBR(long rowNumber) throws SqlException { 291 writeScalar8Bytes(CodePoint.QRYROWNBR, rowNumber); 292 } 293 294 private void buildQRYRTNDTA(int qryrtndta) throws SqlException { 295 writeScalar1Byte(CodePoint.QRYRTNDTA, qryrtndta); 296 } 297 298 303 private int computePROTOCOLOrientation(int orientation) throws SqlException { 305 switch (orientation) { 306 case ResultSet.scrollOrientation_absolute__: 307 return CodePoint.QRYSCRABS; 308 309 case ResultSet.scrollOrientation_after__: 310 return CodePoint.QRYSCRAFT; 311 312 case ResultSet.scrollOrientation_before__: 313 return CodePoint.QRYSCRBEF; 314 315 case ResultSet.scrollOrientation_relative__: 316 return CodePoint.QRYSCRREL; 317 318 default: 319 throw new SqlException(netAgent_.logWriter_, 320 new ClientMessageId(SQLState.NET_INVALID_SCROLL_ORIENTATION)); 321 } 322 } 323 324 } 325 | Popular Tags |