1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.monitor.Monitor; 25 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 29 import org.apache.derby.iapi.services.stream.InfoStreams; 30 31 import org.apache.derby.iapi.error.StandardException; 32 import org.apache.derby.iapi.services.i18n.MessageService; 33 34 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 35 import org.apache.derby.iapi.sql.conn.StatementContext; 36 37 import org.apache.derby.iapi.reference.SQLState; 38 39 40 import org.apache.derby.iapi.sql.execute.ExecRow; 41 import org.apache.derby.iapi.sql.execute.ExecutionContext; 42 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 43 import org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory; 44 45 import org.apache.derby.iapi.sql.Activation; 46 import org.apache.derby.iapi.sql.ResultSet; 47 import org.apache.derby.iapi.sql.ResultDescription; 48 import org.apache.derby.iapi.sql.Row; 49 50 import org.apache.derby.iapi.services.loader.GeneratedMethod; 51 52 import org.apache.derby.iapi.types.DataValueDescriptor; 53 54 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 55 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 56 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 57 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 58 59 import java.sql.Timestamp ; 60 import java.sql.SQLWarning ; 61 62 81 abstract class NoRowsResultSetImpl implements ResultSet 82 { 83 final Activation activation; 84 private boolean dumpedStats; 85 NoPutResultSet[] subqueryTrackingArray; 86 87 private final boolean statisticsTimingOn; 88 private boolean isClosed; 89 90 91 protected String indent; 92 protected String subIndent; 93 protected int sourceDepth; 94 95 96 final LanguageConnectionContext lcc; 97 protected long beginTime; 98 protected long endTime; 99 protected long beginExecutionTime; 100 protected long endExecutionTime; 101 102 NoRowsResultSetImpl(Activation activation) 103 throws StandardException 104 { 105 this.activation = activation; 106 107 if (SanityManager.DEBUG) { 108 if (activation == null) 109 SanityManager.THROWASSERT("activation is null in result set " + getClass()); 110 } 111 112 lcc = activation.getLanguageConnectionContext(); 113 statisticsTimingOn = lcc.getStatisticsTiming(); 114 115 119 beginTime = getCurrentTimeMillis(); 120 beginExecutionTime = beginTime; 121 122 StatementContext sc = lcc.getStatementContext(); 123 sc.setTopResultSet(this, (NoPutResultSet[]) null); 124 125 if (subqueryTrackingArray == null) 127 { 128 subqueryTrackingArray = sc.getSubqueryTrackingArray(); 129 } 130 } 131 132 135 public final boolean returnsRows() { return false; } 136 137 140 public int modifiedRowCount() { return 0; } 141 142 145 public ResultDescription getResultDescription() 146 { 147 return (ResultDescription)null; 148 } 149 150 public final Activation getActivation() 151 { 152 return activation; 153 } 154 155 170 public ExecRow getAbsoluteRow(int row) throws StandardException 171 { 172 176 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "absolute"); 177 } 178 179 196 public ExecRow getRelativeRow(int row) throws StandardException 197 { 198 202 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "relative"); 203 } 204 205 214 public ExecRow setBeforeFirstRow() 215 throws StandardException 216 { 217 221 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "beforeFirst"); 222 } 223 224 233 public ExecRow getFirstRow() 234 throws StandardException 235 { 236 240 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "first"); 241 } 242 243 251 public ExecRow getNextRow() throws StandardException 252 { 253 257 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "next"); 258 } 259 260 269 public ExecRow getPreviousRow() 270 throws StandardException 271 { 272 276 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "previous"); 277 } 278 279 288 public ExecRow getLastRow() 289 throws StandardException 290 { 291 295 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "last"); 296 } 297 298 307 public ExecRow setAfterLastRow() 308 throws StandardException 309 { 310 314 throw StandardException.newException(SQLState.LANG_DOES_NOT_RETURN_ROWS, "afterLast"); 315 } 316 317 322 public final void clearCurrentRow() 323 { 324 325 } 326 327 334 public boolean checkRowPosition(int isType) 335 { 336 return false; 337 } 338 339 348 public int getRowNumber() 349 { 350 return 0; 351 } 352 353 358 public void close() throws StandardException 359 { 360 isClosed = true; 361 } 362 363 372 public boolean isClosed() { 373 return isClosed; 374 } 376 377 384 public void finish() throws StandardException { 385 if (! dumpedStats) 386 { 387 395 if (lcc.getRunTimeStatisticsMode() && 396 ! doesCommit()) 397 { 398 endExecutionTime = getCurrentTimeMillis(); 399 400 ExecutionContext ec = lcc.getExecutionContext(); 401 ResultSetStatisticsFactory rssf; 402 rssf = ec.getResultSetStatisticsFactory(); 403 404 lcc.setRunTimeStatisticsObject( 405 rssf.getRunTimeStatistics(activation, this, subqueryTrackingArray)); 406 407 HeaderPrintWriter istream = lcc.getLogQueryPlan() ? Monitor.getStream() : null; 408 if (istream != null) 409 { 410 istream.printlnWithHeader(LanguageConnectionContext.xidStr + 411 lcc.getTransactionExecute().getTransactionIdString() + 412 "), " + 413 LanguageConnectionContext.lccStr + 414 lcc.getInstanceNumber() + 415 "), " + 416 lcc.getRunTimeStatisticsObject().getStatementText() + " ******* " + 417 lcc.getRunTimeStatisticsObject().getStatementExecutionPlanText()); 418 } 419 } 420 dumpedStats = true; 421 } 422 423 426 int staLength = (subqueryTrackingArray == null) ? 0 : 427 subqueryTrackingArray.length; 428 429 for (int index = 0; index < staLength; index++) 430 { 431 if (subqueryTrackingArray[index] == null) 432 { 433 continue; 434 } 435 if (subqueryTrackingArray[index].isClosed()) 436 { 437 continue; 438 } 439 subqueryTrackingArray[index].close(); 440 } 441 } 442 443 448 public long getExecuteTime() 449 { 450 return endTime - beginTime; 451 } 452 453 458 public Timestamp getBeginExecutionTimestamp() 459 { 460 if (beginExecutionTime == 0) 461 { 462 return null; 463 } 464 else 465 { 466 return new Timestamp (beginExecutionTime); 467 } 468 } 469 470 475 public Timestamp getEndExecutionTimestamp() 476 { 477 if (endExecutionTime == 0) 478 { 479 return null; 480 } 481 else 482 { 483 return new Timestamp (endExecutionTime); 484 } 485 } 486 487 495 public String getQueryPlanText(int depth) 496 { 497 return MessageService.getTextMessage( 498 SQLState.LANG_GQPT_NOT_SUPPORTED, 499 getClass().getName()); 500 } 501 502 510 public long getTimeSpent(int type) 511 { 512 513 return 0; 514 } 515 516 519 public final NoPutResultSet[] getSubqueryTrackingArray(int numSubqueries) 520 { 521 if (subqueryTrackingArray == null) 522 { 523 subqueryTrackingArray = new NoPutResultSet[numSubqueries]; 524 } 525 526 return subqueryTrackingArray; 527 } 528 529 532 public ResultSet getAutoGeneratedKeysResultset() 533 { 534 return (ResultSet)null; 536 } 537 538 543 public String getCursorName() { 544 return null; 545 } 546 547 549 555 protected final long getCurrentTimeMillis() 556 { 557 if (statisticsTimingOn) 558 { 559 return System.currentTimeMillis(); 560 } 561 else 562 { 563 return 0; 564 } 565 } 566 567 578 public static void evaluateACheckConstraint 579 ( 580 GeneratedMethod checkGM, 581 String checkName, 582 long heapConglom, 583 Activation activation 584 ) 585 throws StandardException 586 { 587 if (checkGM != null) 588 { 589 DataValueDescriptor checkBoolean; 590 591 checkBoolean = (DataValueDescriptor) checkGM.invoke(activation); 592 593 596 if ((checkBoolean != null) && 597 (! checkBoolean.isNull()) && 598 (! checkBoolean.getBoolean())) 599 { 600 604 DataDictionary dd = activation.getLanguageConnectionContext().getDataDictionary(); 605 ConglomerateDescriptor cd = dd.getConglomerateDescriptor( heapConglom ); 606 TableDescriptor td = dd.getTableDescriptor(cd.getTableID()); 607 608 StandardException se = StandardException.newException(SQLState.LANG_CHECK_CONSTRAINT_VIOLATED, 609 td.getQualifiedName(), checkName); 610 611 throw se; 612 } 613 } 614 615 } 616 617 626 public static void evaluateCheckConstraints 627 ( 628 GeneratedMethod checkGM, 629 Activation activation 630 ) 631 throws StandardException 632 { 633 if (checkGM != null) 634 { 635 checkGM.invoke(activation); 639 } 640 641 } 642 643 648 public boolean doesCommit() 649 { 650 return false; 651 } 652 653 public java.sql.SQLWarning getWarnings() { 654 return null; 655 } 656 657 } 658 | Popular Tags |