📄 basicnoputresultsetimpl.java
字号:
* because there is no current row. * * @return NULL. * * @exception StandardException Thrown on failure * @see Row */ public ExecRow setAfterLastRow() throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, LAST); } if (SanityManager.DEBUG) { if (!isTopResultSet) { SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } SanityManager.THROWASSERT( "setAfterLastRow() not expected to be called."); } return null; } /** * Returns true. */ public boolean returnsRows() { return true; } public final int modifiedRowCount() { return 0; } /** * Clean up on error * @exception StandardException Thrown on failure * */ public void cleanUp() throws StandardException { if (isOpen) { close(); } } /** Report if closed. */ public boolean isClosed() { return ( ! isOpen ); } public void finish() throws StandardException { finishAndRTS(); } /** * @exception StandardException on error */ protected final void finishAndRTS() throws StandardException { if (!finished) { /* ** If run time statistics tracing is turned on, then now is the ** time to dump out the information. */ if (isTopResultSet) { LanguageConnectionContext lcc = getLanguageConnectionContext(); if (lcc.getRunTimeStatisticsMode()) { endExecutionTime = getCurrentTimeMillis(); lcc.setRunTimeStatisticsObject( lcc.getExecutionContext().getResultSetStatisticsFactory().getRunTimeStatistics(activation, this, subqueryTrackingArray)); HeaderPrintWriter istream = lcc.getLogQueryPlan() ? Monitor.getStream() : null; if (istream != null) { istream.printlnWithHeader(LanguageConnectionContext.xidStr + lcc.getTransactionExecute().getTransactionIdString() + "), " + LanguageConnectionContext.lccStr + lcc.getInstanceNumber() + "), " + lcc.getRunTimeStatisticsObject().getStatementText() + " ******* " + lcc.getRunTimeStatisticsObject().getStatementExecutionPlanText()); } } } if (!isClosed()) close(); finished = true; if (isTopResultSet && activation.isSingleExecution()) activation.close(); } } /* The following methods are common to almost all sub-classes. * They are overriden in selected cases. */ /** * Returns the description of the table's rows */ public ResultDescription getResultDescription() { return resultDescription; } /** * Get the execution time in milliseconds. * * @return long The execution time in milliseconds. */ public long getExecuteTime() { return getTimeSpent(ResultSet.ENTIRE_RESULTSET_TREE); } /** * Get the Timestamp for the beginning of execution. * * @return Timestamp The Timestamp for the beginning of execution. */ public Timestamp getBeginExecutionTimestamp() { if (startExecutionTime == 0) { return null; } else { return new Timestamp(startExecutionTime); } } /** * Get the Timestamp for the end of execution. * * @return Timestamp The Timestamp for the end of execution. */ public Timestamp getEndExecutionTimestamp() { if (endExecutionTime == 0) { return null; } else { return new Timestamp(endExecutionTime); } } /** * @see ResultSet#getSubqueryTrackingArray */ public final NoPutResultSet[] getSubqueryTrackingArray(int numSubqueries) { if (subqueryTrackingArray == null) { subqueryTrackingArray = new NoPutResultSet[numSubqueries]; } return subqueryTrackingArray; } /** * Return the current time in milliseconds, if DEBUG and RunTimeStats is * on, else return 0. (Only pay price of system call if need to.) * * @return long Current time in milliseconds. */ protected final long getCurrentTimeMillis() { if (statisticsTimingOn) { return System.currentTimeMillis(); } else { return 0; } } /** * @see ResultSet#getAutoGeneratedKeysResultset */ public ResultSet getAutoGeneratedKeysResultset() { //A non-null resultset would be returned only for an insert statement return (ResultSet)null; } /** * Return the elapsed time in milliseconds, between now and the beginTime, if * DEBUG and RunTimeStats is on, else return 0. * (Only pay price of system call if need to.) * * @return long Elapsed time in milliseconds. */ protected final long getElapsedMillis(long beginTime) { if (statisticsTimingOn) { return (System.currentTimeMillis() - beginTime); } else { return 0; } } /** * Dump out the time information for run time stats. * * @return Nothing. */ protected final String dumpTimeStats(String indent, String subIndent) { return indent + MessageService.getTextMessage(SQLState.LANG_TIME_SPENT_THIS) + " " + getTimeSpent(ResultSet.CURRENT_RESULTSET_ONLY) + "\n" + indent + MessageService.getTextMessage( SQLState.LANG_TIME_SPENT_THIS_AND_BELOW) + " " + getTimeSpent(NoPutResultSet.ENTIRE_RESULTSET_TREE) + "\n" + indent + MessageService.getTextMessage( SQLState.LANG_TOTAL_TIME_BREAKDOWN) + "\n" + subIndent + MessageService.getTextMessage(SQLState.LANG_CONSTRUCTOR_TIME) + " " + constructorTime + "\n" + subIndent + MessageService.getTextMessage(SQLState.LANG_OPEN_TIME) + " " + openTime + "\n" + subIndent + MessageService.getTextMessage(SQLState.LANG_NEXT_TIME) + " " + nextTime + "\n" + subIndent + MessageService.getTextMessage(SQLState.LANG_CLOSE_TIME) + " " + closeTime; } /** * Attach this result set to the top statement context on the stack. * Result sets can be directly read from the JDBC layer. The JDBC layer * will push and pop a statement context around each ResultSet.getNext(). * There's no guarantee that the statement context used for the last * getNext() will be the context used for the current getNext(). The * last statement context may have been popped off the stack and so * will not be available for cleanup if an error occurs. To make sure * that we will be cleaned up, we always attach ourselves to the top * context. * * The fun and games occur in nested contexts: using JDBC result sets inside * user code that is itself invoked from queries or CALL statements. * * * @exception StandardException thrown if cursor finished. */ protected void attachStatementContext() throws StandardException { if (isTopResultSet) { if (statementContext == null || !statementContext.onStack() ) { statementContext = getLanguageConnectionContext().getStatementContext(); } statementContext.setTopResultSet(this, subqueryTrackingArray); // Pick up any materialized subqueries if (subqueryTrackingArray == null) { subqueryTrackingArray = statementContext.getSubqueryTrackingArray(); } } } /** * Cache the language connection context. Return it. * * @return the language connection context */ protected final LanguageConnectionContext getLanguageConnectionContext() { if ( lcc == null ) { /* We don't always have an activation. Get the LCC * from the activation when we have one. */ if (activation != null) { lcc = activation.getLanguageConnectionContext(); } else { lcc = (LanguageConnectionContext) ContextService.getContext(LanguageConnectionContext.CONTEXT_ID); } } return lcc; } /** @see NoPutResultSet#resultSetNumber() */ public int resultSetNumber() { if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "resultSetNumber() should not be called on a " + this.getClass().getName() ); } return 0; } ////////////////////////////////////////////////////// // // UTILS // ////////////////////////////////////////////////////// /** * Get a execution factory * * @return the execution factory */ final ExecutionFactory getExecutionFactory() { if (exFactory == null) { exFactory = activation.getExecutionFactory(); } if (SanityManager.DEBUG) SanityManager.ASSERT(exFactory!=null,"unable to get execution factory"); return exFactory; } /** * Get the current transaction controller. * */ final TransactionController getTransactionController() { if (tc == null) { tc = getLanguageConnectionContext().getTransactionExecute(); } return tc; } /** * Get a compacted version of the candidate row according to the * columns specified in the bit map. Share the holders between rows. * If there is no bit map, use the candidate row as the compact row. * * Also, create an array of ints mapping base column positions to * compact column positions, to make it cheaper to copy columns to * the compact row, if we ever have to do it again. * * @param candidate The row to get the columns from * @param accessedCols A bit map of the columns that are accessed in * the candidate row * @param otherCols An bit map of other column ids - this is used * in case columns from an index row will be * copied into a heap row - in this case, we * need to be sure there are enough columns in * the compact row. This parameter is null if * columns will not be copied from an index row * to a compact heap row. The column numbers in * the bit map are zero-based. * @param isKeyed Tells whether to return a ValueRow or an IndexRow * * @return A compact row. */ protected ExecRow getCompactRow(ExecRow candidate, FormatableBitSet accessedCols, FormatableBitSet otherCols, boolean isKeyed) throws StandardException { int numCandidateCols = candidate.nColumns(); if (accessedCols == null) { compactRow = candidate; baseColumnMap = new int[numCandidateCols]; for (int i = 0; i < baseColumnMap.length; i++) baseColumnMap[i] = i; } else { FormatableBitSet allCols; if (otherCols == null) { allCols = accessedCols; } else { allCols = new FormatableBitSet(accessedCols); allCols.or(otherCols); } int numCols = allCols.getNumBitsSet(); baseColumnMap = new int[numCols]; if (compactRow == null) { ExecutionFactory ex = lcc.getExecutionContext().getExecutionFactory(); if (isKeyed) { compactRow = ex.getIndexableRow(numCols); } else { compactRow = ex.getValueRow(numCols); } } int position = 0; for (int i = allCols.anySetBit(); i != -1; i = allCols.anySetBit(i)) { // Stop looking if there are columns beyond the columns // in the candidate row. This can happen due to the // otherCols bit map. if (i >= numCandidateCols) break; DataValueDescriptor sc = candidate.getColumn(i+1); if (sc != null) { compactRow.setColumn( position + 1, sc ); } baseColumnMap[position] = i; position++; } } return compactRow; } /** * Copy columns from the candidate row from the store to the given * compact row. If there is no column map, just use the candidate row. * * This method assumes the above method (getCompactRow()) was called * first. getCompactRow() sets up the baseColumnMap. * * @param candidateRow The candidate row from the store * @param compactRow The compact row to fill in * * @return The compact row to use */ protected ExecRow setCompactRow(ExecRow candidateRow, ExecRow compactRow) { ExecRow retval; //System.out.println("base col map " + baseColumnMap); if (baseColumnMap == null) { retval = candidateRow; } else { retval = compactRow; setCompatRow(compactRow, candidateRow.getRowArray()); } return retval; } protected final void setCompatRow(ExecRow compactRow, Object[] sourceRow) { Object[] destRow = compactRow.getRowArray(); int[] lbcm = baseColumnMap; for (int i = 0; i < lbcm.length; i++) { destRow[i] = sourceRow[lbcm[i]]; } } /** * Is this ResultSet or it's source result set for update * This method will be overriden in the inherited Classes * if it is true * @return Whether or not the result set is for update. */ public boolean isForUpdate() { return false; } protected final void addWarning(SQLWarning w) { if (isTopResultSet) { if (warnings == null) warnings = w; else warnings.setNextWarning(w); return; } if (activation != null) { ResultSet rs = activation.getResultSet(); if (rs instanceof BasicNoPutResultSetImpl) { ((BasicNoPutResultSetImpl) rs).addWarning(w); } } } public final SQLWarning getWarnings() { SQLWarning w = warnings; warnings = null; return w; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -