1 21 22 package org.apache.derby.impl.drda; 23 24 import java.sql.ResultSet ; 25 import java.sql.ResultSetMetaData ; 26 import java.sql.SQLException ; 27 import java.sql.Types ; 28 import java.util.ArrayList ; 29 30 import org.apache.derby.iapi.jdbc.EngineResultSet; 31 32 35 class DRDAResultSet 36 { 37 42 protected static final int NOT_OPENED = 1; 44 protected static final int SUSPENDED = 2; 45 public static final int QRYCLSIMP_DEFAULT = CodePoint.QRYCLSIMP_NO; 46 47 boolean explicitlyClosed = false; 48 49 int state; 50 protected boolean hasdata = true; 51 protected int[] rsLens; private int[] rsDRDATypes; private int[] rsPrecision; private int[] rsScale; 56 protected int [] outovr_drdaType; 58 protected int withHoldCursor; protected int scrollType = ResultSet.TYPE_FORWARD_ONLY; protected int concurType; protected long rowCount; private ResultSet rs; 64 protected int blksize; protected int maxblkext; protected int outovropt; protected int qryclsimp; protected boolean qryrelscr; protected long qryrownbr; protected boolean qryrfrtbl; protected int qryscrorn; protected boolean qryrowsns; protected boolean qryblkrst; protected boolean qryrtndta; protected int qryrowset; private int qryprctyp; private boolean gotPrctyp; protected int rtnextdta; protected int nbrrow; protected byte [] rslsetflg; 82 private ArrayList extDtaObjects; 86 private ArrayList rsExtPositions; 87 88 protected ConsistencyToken pkgcnstkn; 90 private byte []splitQRYDTA; 96 97 DRDAResultSet() 98 { 99 state = NOT_OPENED; 100 qryclsimp = CodePoint.QRYCLSIMP_NO; 104 } 105 106 112 113 protected void setResultSet(ResultSet value) throws SQLException 114 { 115 int numCols; 116 rs = value; 117 gotPrctyp = false; 118 if (value != null) 119 { 120 numCols= rs.getMetaData().getColumnCount(); 121 rsDRDATypes = new int[numCols]; 122 } 123 explicitlyClosed = false; 124 } 125 126 127 131 protected void setPkgcnstkn(ConsistencyToken pkgcnstkn) 132 { 133 this.pkgcnstkn = pkgcnstkn; 134 } 135 136 137 141 protected ResultSet getResultSet() 142 { 143 return rs; 144 } 145 146 public void setSplitQRYDTA(byte []data) 147 { 148 splitQRYDTA = data; 149 } 150 public byte[]getSplitQRYDTA() 151 { 152 return splitQRYDTA; 153 } 154 155 159 protected void setRsDRDATypes(int [] value) 160 { 161 rsDRDATypes = value; 162 163 } 164 165 168 169 protected int[] getRsDRDATypes() 170 { 171 if (outovr_drdaType != null) 173 return outovr_drdaType; 174 return rsDRDATypes; 175 } 176 177 183 protected void setRsPrecision(int index, int precision) 184 { 185 if (rsPrecision == null) 186 rsPrecision = new int[rsDRDATypes.length]; 187 rsPrecision[index -1] = precision; 188 } 189 190 195 protected int getRsPrecision(int index) 196 { 197 if (rsPrecision == null) 198 return 0; 199 return rsPrecision[index-1]; 200 } 201 202 208 protected void setRsScale(int index, int scale) 209 { 210 if (rsScale == null) 211 rsScale = new int[rsDRDATypes.length]; 212 rsScale[index-1] = scale; 213 } 214 215 220 protected int getRsScale(int index) 221 { 222 if (rsScale == null) 223 return 0; 224 225 return rsScale[index -1]; 226 } 227 228 229 235 protected void setRsDRDAType(int index, int type) 236 { 237 rsDRDATypes[index -1] = type; 238 239 } 240 241 247 protected int getRsDRDAType(int index) 248 { 249 return rsDRDATypes[index -1]; 250 } 251 252 253 259 protected void setRsLen(int index, int value) 260 { 261 if (rsLens == null) 262 rsLens = new int[rsDRDATypes.length]; 263 rsLens[index -1] = value; 264 265 } 266 267 272 protected int getRsLen(int index) 273 { 274 return rsLens[index -1]; 275 } 276 277 278 282 protected void addExtDtaObject (Object o, int jdbcIndex ) 283 { 284 if (extDtaObjects == null) 285 extDtaObjects = new java.util.ArrayList (); 286 extDtaObjects.add (o); 287 288 if (rsExtPositions == null) 289 rsExtPositions = new java.util.ArrayList (); 290 291 rsExtPositions.add (new Integer (jdbcIndex -1 )); 293 294 } 295 296 297 300 protected void clearExtDtaObjects () 301 { 302 if (extDtaObjects != null) 303 extDtaObjects.clear(); 304 if (rsExtPositions != null) 305 rsExtPositions.clear(); 306 307 } 308 309 314 protected boolean isExtDtaValueNullable(int index) 315 { 316 if ((rsExtPositions == null) || 317 rsExtPositions.get(index) == null) 318 return false; 319 320 321 int colnum = ((Integer ) rsExtPositions.get(index)).intValue(); 322 323 if (FdocaConstants.isNullable((getRsDRDATypes())[colnum])) 324 return true; 325 else 326 return false; 327 } 328 329 330 335 protected ArrayList getExtDtaObjects() 336 { 337 return extDtaObjects; 338 } 339 340 343 protected void setExtDtaObjects(ArrayList a) 344 { 345 extDtaObjects =a; 346 } 347 348 349 355 protected void close() throws SQLException 356 { 357 if (rs != null) 358 rs.close(); 359 rs = null; 360 outovr_drdaType = null; 361 rsLens = null; 362 rsDRDATypes = null; 363 rsPrecision = null; 364 rsScale = null; 365 extDtaObjects = null; 366 splitQRYDTA = null; 367 rsExtPositions = null; 368 } 369 370 375 protected void reset() { 376 explicitlyClosed = false; 377 state = NOT_OPENED; 378 hasdata = true; 379 rsLens = null; 380 rsDRDATypes = null; 381 rsPrecision = null; 382 rsScale = null; 383 384 outovr_drdaType = null; 385 386 withHoldCursor = 0; 387 scrollType = ResultSet.TYPE_FORWARD_ONLY; 388 concurType = 0; 389 rowCount = 0; 390 rs = null; 391 392 blksize = 0; 393 maxblkext = 0; 394 outovropt = 0; 395 qryclsimp = CodePoint.QRYCLSIMP_NO; 396 qryrelscr = false; 397 qryrownbr = 0; 398 qryrfrtbl = false; 399 qryscrorn = 0; 400 qryrowsns = false; 401 qryblkrst = false; 402 qryrtndta = false; 403 qryrowset = 0; 404 qryprctyp = 0; 405 gotPrctyp = false; 406 rtnextdta = 0; 407 nbrrow = 0; 408 rslsetflg = null; 409 410 extDtaObjects = null; 411 rsExtPositions = null; 412 pkgcnstkn = null; 413 splitQRYDTA = null; 414 } 415 416 417 421 protected void CLSQRY() 422 { 423 explicitlyClosed = true; 424 } 425 426 430 protected boolean wasExplicitlyClosed() 431 { 432 return explicitlyClosed; 433 } 434 435 436 442 443 protected boolean hasLobColumns() throws SQLException 444 { 445 ResultSetMetaData rsmd = rs.getMetaData(); 446 int ncols = rsmd.getColumnCount(); 447 for (int i = 1; i <= ncols; i++) 448 { 449 int type = rsmd.getColumnType(i); 450 if (type == Types.BLOB || type == Types.CLOB) 451 return true; 452 } 453 return false; 454 } 455 456 459 public String getResultSetCursorName() throws SQLException 460 { 461 462 if (rs != null) 463 return rs.getCursorName(); 464 else 465 return null; 466 } 467 468 protected int getQryprctyp() 469 throws SQLException 470 { 471 if (!gotPrctyp && qryprctyp == CodePoint.LMTBLKPRC) 472 { 473 gotPrctyp = true; 474 if (rs == null || ((EngineResultSet)rs).isForUpdate() || 475 479 hasLobColumns()) 480 { 481 qryprctyp = CodePoint.FIXROWPRC; 482 } 483 } 484 return qryprctyp; 485 } 486 487 protected void setQryprctyp(int qryprctyp) 488 { 489 this.qryprctyp = qryprctyp; 490 } 491 492 496 protected boolean isClosed() 497 { 498 return (state == NOT_OPENED); 499 } 500 501 504 protected void suspend() 505 { 506 state = SUSPENDED; 507 } 508 509 510 protected String toDebugString(String indent) 511 { 512 String s = indent + "***** DRDASResultSet toDebugString ******\n"; 513 s += indent + "State:" + getStateString(state)+ "\n"; 514 s += indent + "pkgcnstkn: {" + pkgcnstkn + "}\n"; 515 s += indent + "cursor Name: "; 516 String cursorName = null; 517 try { 518 if (rs != null) 519 cursorName = rs.getCursorName(); 520 } 521 catch (SQLException se ) 522 { 523 cursorName = "invalid rs"; 524 } 525 s += indent + cursorName + "\n"; 526 527 return s; 528 } 529 530 531 private String getStateString( int i ) 532 { 533 switch (i) 534 { 535 case NOT_OPENED: 536 return "NOT_OPENED"; 537 case SUSPENDED: 538 return "SUSPENDED"; 539 default: 540 return "UNKNOWN_STATE"; 541 } 542 543 } 544 545 556 protected void setOPNQRYOptions(int blksize, int qryblkctl, 557 int maxblkext, int outovropt,int qryrowset,int qryclsimpl) 558 { 559 this.blksize = blksize; 560 setQryprctyp(qryblkctl); 561 this.maxblkext = maxblkext; 562 this.outovropt = outovropt; 563 this.qryrowset = qryrowset; 564 this.qryclsimp = (qryclsimpl == CodePoint.QRYCLSIMP_SERVER_CHOICE) 565 ? DRDAResultSet.QRYCLSIMP_DEFAULT : qryclsimpl; 566 567 qryrtndta = true; 570 571 qryscrorn = CodePoint.QRYSCRREL; 575 qryrownbr = 1; 576 } 577 } 578 | Popular Tags |