1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.services.io.FormatableBitSet; 27 import org.apache.derby.iapi.services.i18n.MessageService; 28 29 import org.apache.derby.iapi.services.loader.GeneratedMethod; 30 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 33 import org.apache.derby.iapi.error.StandardException; 34 35 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 36 import org.apache.derby.iapi.sql.conn.StatementContext; 37 38 import org.apache.derby.iapi.sql.depend.DependencyManager; 39 40 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement; 41 import org.apache.derby.iapi.sql.execute.ExecRow; 42 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 43 import org.apache.derby.iapi.sql.execute.ExecutionContext; 44 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 45 import org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory; 46 import org.apache.derby.iapi.sql.execute.TargetResultSet; 47 48 import org.apache.derby.iapi.sql.Activation; 49 import org.apache.derby.iapi.sql.ResultDescription; 50 51 import org.apache.derby.iapi.store.access.Qualifier; 52 import org.apache.derby.iapi.store.access.RowLocationRetRowSource; 53 import org.apache.derby.iapi.store.access.RowSource; 54 55 import org.apache.derby.iapi.types.DataValueDescriptor; 56 57 import org.apache.derby.iapi.types.Orderable; 58 import org.apache.derby.iapi.types.RowLocation; 59 60 import java.sql.Timestamp ; 61 62 63 77 abstract class NoPutResultSetImpl 78 extends BasicNoPutResultSetImpl 79 { 80 81 public final int resultSetNumber; 82 83 84 protected String indent; 85 protected String subIndent; 86 protected int sourceDepth; 87 88 private boolean needsRowLocation; 90 protected ExecRow clonedExecRow; 91 GeneratedMethod checkGM; 92 long heapConglomerate; 93 protected TargetResultSet targetResultSet; 94 95 98 protected int[] checkNullCols; 99 protected int cncLen; 100 101 110 NoPutResultSetImpl(Activation activation, 111 int resultSetNumber, 112 double optimizerEstimatedRowCount, 113 double optimizerEstimatedCost) 114 { 115 super(null, 116 activation, 117 optimizerEstimatedRowCount, 118 optimizerEstimatedCost); 119 120 if (SanityManager.DEBUG) { 121 SanityManager.ASSERT(activation!=null, "activation expected to be non-null"); 122 SanityManager.ASSERT(resultSetNumber >= 0, "resultSetNumber expected to be >= 0"); 123 } 124 this.resultSetNumber = resultSetNumber; 125 } 126 127 129 132 public ResultDescription getResultDescription() { 133 return activation.getResultDescription(); 134 } 135 136 139 public String getCursorName() { 140 141 String cursorName = activation.getCursorName(); 142 if ((cursorName == null) && isForUpdate()) { 143 144 activation.setCursorName(activation.getLanguageConnectionContext().getUniqueCursorName()); 145 146 cursorName = activation.getCursorName(); 147 } 148 149 return cursorName; 150 } 151 152 153 public int resultSetNumber() { 154 return resultSetNumber; 155 } 156 157 162 public void close() throws StandardException 163 { 164 if (!isOpen) 165 return; 166 167 171 if (isTopResultSet) 172 { 173 int staLength = (subqueryTrackingArray == null) ? 0 : 174 subqueryTrackingArray.length; 175 176 for (int index = 0; index < staLength; index++) 177 { 178 if (subqueryTrackingArray[index] == null) 179 { 180 continue; 181 } 182 if (subqueryTrackingArray[index].isClosed()) 183 { 184 continue; 185 } 186 subqueryTrackingArray[index].close(); 187 } 188 } 189 190 194 if (activation.getResultSet() == this) 195 { 196 activation.clearResultSet(); 197 } 198 199 isOpen = false; 200 201 } 202 203 204 public void setTargetResultSet(TargetResultSet trs) 205 { 206 targetResultSet = trs; 207 } 208 209 210 public void setNeedsRowLocation(boolean needsRowLocation) 211 { 212 this.needsRowLocation = needsRowLocation; 213 } 214 215 217 220 public FormatableBitSet getValidColumns() 221 { 222 return null; 224 } 225 226 230 public DataValueDescriptor[] getNextRowFromRowSource() 231 throws StandardException 232 { 233 ExecRow execRow = getNextRowCore(); 234 if (execRow != null) 235 { 236 242 clonedExecRow = targetResultSet.preprocessSourceRow(execRow); 243 244 return execRow.getRowArray(); 245 } 246 247 return null; 248 } 249 250 253 public boolean needsToClone() 254 { 255 return(true); 256 } 257 258 261 public void closeRowSource() 262 { 263 } 265 266 267 269 272 public boolean needsRowLocation() 273 { 274 return needsRowLocation; 275 } 276 277 281 public void rowLocation(RowLocation rl) 282 throws StandardException 283 { 284 targetResultSet.changedRow(clonedExecRow, rl); 285 } 286 287 288 290 297 protected void clearOrderableCache(Qualifier[][] qualifiers) throws StandardException 298 { 299 if (qualifiers != null) 301 { 302 Qualifier qual; 303 for (int term = 0; term < qualifiers.length; term++) 304 { 305 for (int index = 0; index < qualifiers[term].length; index++) 306 { 307 qual = qualifiers[term][index]; 308 qual.clearOrderableCache(); 309 312 if (((GenericQualifier) qual).variantType != Qualifier.VARIANT) 313 qual.getOrderable(); } 315 } 316 } 317 } 318 319 323 324 329 protected void setCheckConstraints(GeneratedMethod checkGM) 330 { 331 this.checkGM = checkGM; 332 } 333 334 339 protected void setHeapConglomerate(long heapConglomerate) 340 { 341 this.heapConglomerate = heapConglomerate; 342 } 343 344 350 public final void setCurrentRow(ExecRow row) 351 { 352 activation.setCurrentRow(row, resultSetNumber); 353 currentRow = row; 354 } 355 356 360 public final void clearCurrentRow() 361 { 362 currentRow = null; 363 activation.clearCurrentRow(resultSetNumber); 364 } 365 366 372 public boolean isForUpdate() 373 { 374 return false; 375 } 376 377 388 protected boolean skipScan(ExecIndexRow startPosition, ExecIndexRow stopPosition) 389 throws StandardException 390 { 391 int nStartCols = (startPosition == null) ? 0 : startPosition.nColumns(); 392 int nStopCols = (stopPosition == null) ? 0 : stopPosition.nColumns(); 393 394 400 boolean startKeyLonger = false; 401 int size = nStopCols; 402 if (nStartCols > nStopCols) 403 { 404 startKeyLonger = true; 405 size = nStartCols; 406 } 407 if (size == 0) 408 return false; 409 if ((checkNullCols == null) || (checkNullCols.length < size)) 410 checkNullCols = new int[size]; 411 cncLen = 0; 412 413 boolean returnValue = false; 414 for (int position = 0; position < nStartCols; position++) 415 { 416 if ( ! startPosition.areNullsOrdered(position)) 417 { 418 if (startKeyLonger) 419 checkNullCols[cncLen++] = position + 1; 420 if (startPosition.getColumn(position + 1).isNull()) 421 { 422 returnValue = true; 423 if (! startKeyLonger) 424 break; 425 } 426 } 427 } 428 if (startKeyLonger && returnValue) 429 return true; 430 for (int position = 0; position < nStopCols; position++) 431 { 432 if ( ! stopPosition.areNullsOrdered(position)) 433 { 434 if (! startKeyLonger) 435 checkNullCols[cncLen++] = position + 1; 436 if (returnValue) 437 continue; 438 if (stopPosition.getColumn(position + 1).isNull()) 439 { 440 returnValue = true; 441 if (startKeyLonger) 442 break; 443 } 444 } 445 } 446 447 return returnValue; 448 } 449 450 459 protected boolean skipRow(ExecRow row) throws StandardException 460 { 461 for (int i = 0; i < cncLen; i++) 462 { 463 if (row.getColumn(checkNullCols[i]).isNull()) 464 return true; 465 } 466 467 return false; 468 } 469 470 473 public static String printQualifiers(Qualifier[][] qualifiers) 474 { 475 String idt = ""; 476 477 String output = ""; 478 if (qualifiers == null) 479 { 480 return idt + MessageService.getTextMessage(SQLState.LANG_NONE); 481 } 482 483 for (int term = 0; term < qualifiers.length; term++) 484 { 485 for (int i = 0; i < qualifiers[term].length; i++) 486 { 487 Qualifier qual = qualifiers[term][i]; 488 489 output = idt + output + 490 MessageService.getTextMessage( 491 SQLState.LANG_COLUMN_ID_ARRAY, 492 String.valueOf(term), String.valueOf(i)) + 493 ": " + qual.getColumnId() + "\n"; 494 495 int operator = qual.getOperator(); 496 String opString = null; 497 switch (operator) 498 { 499 case Orderable.ORDER_OP_EQUALS: 500 opString = "="; 501 break; 502 503 case Orderable.ORDER_OP_LESSOREQUALS: 504 opString = "<="; 505 break; 506 507 case Orderable.ORDER_OP_LESSTHAN: 508 opString = "<"; 509 break; 510 511 default: 512 if (SanityManager.DEBUG) 513 { 514 SanityManager.THROWASSERT("Unknown operator " + operator); 515 } 516 517 opString = "unknown value (" + operator + ")"; 520 break; 521 } 522 output = output + 523 idt + MessageService.getTextMessage(SQLState.LANG_OPERATOR) + 524 ": " + opString + "\n" + 525 idt + 526 MessageService.getTextMessage( 527 SQLState.LANG_ORDERED_NULLS) + 528 ": " + qual.getOrderedNulls() + "\n" + 529 idt + 530 MessageService.getTextMessage( 531 SQLState.LANG_UNKNOWN_RETURN_VALUE) + 532 ": " + qual.getUnknownRV() + "\n" + 533 idt + 534 MessageService.getTextMessage( 535 SQLState.LANG_NEGATE_COMPARISON_RESULT) + 536 ": " + qual.negateCompareResult() + "\n"; 537 } 538 } 539 540 return output; 541 } 542 543 549 public void updateRow(ExecRow row) throws StandardException { 550 } 554 555 561 public void markRowAsDeleted() throws StandardException { 562 } 566 567 573 public void positionScanAtRowLocation(RowLocation rl) 574 throws StandardException 575 { 576 } 580 581 582 } 583 | Popular Tags |