📄 basicnoputresultsetimpl.java
字号:
/* Derby - Class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.sql.execute;import org.apache.derby.iapi.services.context.ContextService;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.stream.HeaderPrintWriter;import org.apache.derby.iapi.services.stream.InfoStreams;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.i18n.MessageService;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.conn.StatementContext;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.NoPutResultSet;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.sql.Row;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.services.io.FormatableBitSet;import java.sql.Timestamp;import java.sql.SQLWarning;/** * Abstract ResultSet for for operations that return rows but * do not allow the caller to put data on output pipes. This * basic implementation does not include support for an Activiation. * See NoPutResultSetImpl.java for an implementaion with support for * an activiation. * <p> * This abstract class does not define the entire ResultSet * interface, but leaves the 'get' half of the interface * for subtypes to implement. It is package-visible only, * with its methods being public for exposure by its subtypes. * <p> */abstract class BasicNoPutResultSetImplimplements NoPutResultSet{ /* Modified during the life of this object */ protected boolean isOpen; protected boolean finished; protected ExecRow currentRow; protected boolean isTopResultSet; protected LanguageConnectionContext lcc; private SQLWarning warnings; /* Run time statistics variables */ public int numOpens; public int rowsSeen; public int rowsFiltered; protected long startExecutionTime; protected long endExecutionTime; public long beginTime; public long constructorTime; public long openTime; public long nextTime; public long closeTime; public double optimizerEstimatedRowCount; public double optimizerEstimatedCost; // set on demand during execution private StatementContext statementContext; public NoPutResultSet[] subqueryTrackingArray; ExecRow compactRow; // Set in the constructor and not modified protected Activation activation; private boolean statisticsTimingOn; ResultDescription resultDescription; private transient ExecutionFactory exFactory; private transient TransactionController tc; private int[] baseColumnMap; /** * Constructor. <BR> Sets beginTime for all children to use to measue constructor time. * * @param resultDescription the result description. May be null. * @param activation The activation * @param optimizerEstimatedRowCount The optimizer's estimate of the * total number of rows for this * result set * @param optimizerEstimatedCost The optimizer's estimated cost for * this result set */ BasicNoPutResultSetImpl(ResultDescription resultDescription, Activation activation, double optimizerEstimatedRowCount, double optimizerEstimatedCost) { this.activation = activation; statisticsTimingOn = (activation != null && getLanguageConnectionContext().getStatisticsTiming()); beginTime = startExecutionTime = getCurrentTimeMillis(); this.resultDescription = resultDescription; this.optimizerEstimatedRowCount = optimizerEstimatedRowCount; this.optimizerEstimatedCost = optimizerEstimatedCost; } // NoPutResultSet interface /** * @see NoPutResultSet#openCore * @exception StandardException thrown if cursor finished. */ public abstract void openCore() throws StandardException; /** * This is the default implementation of reopenCore(). * It simply does a close() followed by an open(). If * there are optimizations to be made (caching, etc), this * is a good place to do it -- this will be overridden * by a number of resultSet imlementations. and SHOULD * be overridden by any node that can get between a base * table and a join. * * @see NoPutResultSet#openCore * @exception StandardException thrown if cursor finished. */ public void reopenCore() throws StandardException { close(); openCore(); } /** * @see NoPutResultSet#getNextRowCore * @exception StandardException thrown if cursor finished. */ public abstract ExecRow getNextRowCore() throws StandardException; /** * @see NoPutResultSet#getPointOfAttachment */ public int getPointOfAttachment() { if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "getPointOfAttachment() not expected to be called for " + getClass().getName()); } return -1; } /** * Mark the ResultSet as the topmost one in the ResultSet tree. * Useful for closing down the ResultSet on an error. * * @return Nothing. */ public void markAsTopResultSet() { isTopResultSet = true; } /** * @see NoPutResultSet#getScanIsolationLevel */ public int getScanIsolationLevel() { if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "getScanIsolationLevel() not expected to be called for " + getClass().getName()); } return 0; } /** @see NoPutResultSet#getEstimatedRowCount */ public double getEstimatedRowCount() { return optimizerEstimatedRowCount; } /** * @see NoPutResultSet#requiresRelocking */ public boolean requiresRelocking() { if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "requiresRelocking() not expected to be called for " + getClass().getName()); } return false; } // ResultSet interface /** * open a scan on the table. scan parameters are evaluated * at each open, so there is probably some way of altering * their values... * * NOTE: This method should only be called on the top ResultSet * of a ResultSet tree to ensure that the entire ResultSet * tree gets closed down on an error. the openCore() method * will be called for all other ResultSets in the tree. * * @exception StandardException thrown if cursor finished. */ public final void open() throws StandardException { if (SanityManager.DEBUG) { if (!isTopResultSet) SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } finished = false; attachStatementContext(); try { openCore(); } catch (StandardException se) { activation.checkStatementValidity(); throw se; } activation.checkStatementValidity(); } /** * Returns the row at the absolute position from the query, * and returns NULL when there is no such position. * (Negative position means from the end of the result set.) * Moving the cursor to an invalid position leaves the cursor * positioned either before the first row (negative position) * or after the last row (positive position). * NOTE: An exception will be thrown on 0. * * @param row The position. * @return The row at the absolute position, or NULL if no such position. * * @exception StandardException Thrown on failure * @see Row */ public ExecRow getAbsoluteRow(int row) throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, ABSOLUTE); } attachStatementContext(); if (SanityManager.DEBUG) { if (!isTopResultSet) { SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } SanityManager.THROWASSERT( "getAbsoluteRow() not expected to be called for " + getClass().getName()); } return null; } /** * Returns the row at the relative position from the current * cursor position, and returns NULL when there is no such position. * (Negative position means toward the beginning of the result set.) * Moving the cursor to an invalid position leaves the cursor * positioned either before the first row (negative position) * or after the last row (positive position). * NOTE: 0 is valid. * NOTE: An exception is thrown if the cursor is not currently * positioned on a row. * * @param row The position. * @return The row at the relative position, or NULL if no such position. * * @exception StandardException Thrown on failure * @see Row */ public ExecRow getRelativeRow(int row) throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, RELATIVE); } attachStatementContext(); if (SanityManager.DEBUG) { if (!isTopResultSet) { SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } SanityManager.THROWASSERT( "getRelativeRow() not expected to be called for " + getClass().getName()); } return null; } /** * Sets the current position to before the first row and returns NULL * because there is no current row. * * @return NULL. * * @exception StandardException Thrown on failure * @see Row */ public ExecRow setBeforeFirstRow() throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, FIRST); } if (SanityManager.DEBUG) { if (!isTopResultSet) { SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } SanityManager.THROWASSERT( "setBeforeFirstRow() not expected to be called for " + getClass().getName()); } return null; } /** * Determine if the cursor is before the first row in the result * set. * * @return true if before the first row, false otherwise. Returns * false when the result set contains no rows. */ public boolean checkRowPosition(int isType) throws StandardException { return false; } /** * Returns the row number of the current row. Row * numbers start from 1 and go to 'n'. Corresponds * to row numbering used to position current row * in the result set (as per JDBC). * * @return the row number, or 0 if not on a row * */ public int getRowNumber() { return 0; } /** * Returns the first row from the query, and returns NULL when there * are no rows. * * @return The first row, or NULL if no rows. * * @exception StandardException Thrown on failure * @see Row */ public ExecRow getFirstRow() throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, FIRST); } attachStatementContext(); if (SanityManager.DEBUG) { if (!isTopResultSet) { SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } SanityManager.THROWASSERT( "getFirstRow() not expected to be called for " + getClass().getName()); } return null; } /** * Return the requested values computed * from the next row (if any) for which * the restriction evaluates to true. * <p> * restriction and projection parameters * are evaluated for each row. * * NOTE: This method should only be called on the top ResultSet * of a ResultSet tree to ensure that the entire ResultSet * tree gets closed down on an error. the getNextRowCore() method * will be called for all other ResultSets in the tree. * * @exception StandardException thrown on failure. * @exception StandardException ResultSetNotOpen thrown if not yet open. * * @return the next row in the result */ public final ExecRow getNextRow() throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, NEXT); } if (SanityManager.DEBUG) { if (!isTopResultSet) SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } attachStatementContext(); return getNextRowCore(); } /** * Returns the previous row from the query, and returns NULL when there * are no more previous rows. * * @return The previous row, or NULL if no more previous rows. * * @exception StandardException Thrown on failure * @see Row */ public ExecRow getPreviousRow() throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, PREVIOUS); } attachStatementContext(); if (SanityManager.DEBUG) { if (!isTopResultSet) { SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } SanityManager.THROWASSERT( "getPreviousRow() not expected to be called."); } return null; } /** * Returns the last row from the query, and returns NULL when there * are no rows. * * @return The last row, or NULL if no rows. * * @exception StandardException Thrown on failure * @see Row */ public ExecRow getLastRow() throws StandardException { if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, LAST); } attachStatementContext(); if (SanityManager.DEBUG) { if (!isTopResultSet) { SanityManager.THROWASSERT( this + "expected to be the top ResultSet"); } SanityManager.THROWASSERT( "getLastRow() not expected to be called."); } return null; } /** * Sets the current position to after the last row and returns NULL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -