⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 embedresultset.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*   Derby - Class org.apache.derby.impl.jdbc.EmbedResultSet   Copyright 1997, 2005 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.jdbc;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.conn.StatementContext;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.sql.Row;import org.apache.derby.iapi.sql.ParameterValueSet;import org.apache.derby.iapi.sql.execute.ExecCursorTableReference;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.NoPutResultSet;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.execute.CursorActivation;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.VariableSizeDataValue;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.services.io.StreamStorable;import org.apache.derby.iapi.services.io.LimitInputStream;import org.apache.derby.iapi.services.io.NewByteArrayInputStream;import org.apache.derby.iapi.services.io.LimitReader;import org.apache.derby.iapi.error.ExceptionSeverity;import org.apache.derby.iapi.reference.JDBC20Translation;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.util.StringUtil;/* can't import these due to name overlap:import java.sql.ResultSet;*/import java.sql.Blob;import java.sql.Clob;import java.sql.Statement;import java.sql.SQLException;import java.sql.SQLWarning;import java.sql.ResultSetMetaData;import java.sql.Date;import java.sql.Time;import java.sql.Timestamp;import java.sql.Types;import java.io.InputStream;import java.io.IOException;import java.net.URL;import java.util.Calendar;/** * A EmbedResultSet for results from the EmbedStatement family.     <P><B>Supports</B>   <UL>   <LI> JSR 169   </UL> * @author ames */public abstract class EmbedResultSet extends ConnectionChild     implements java.sql.ResultSet, Comparable {	// cursor movement	protected static final int FIRST = 1;	protected static final int NEXT = 2;	protected static final int LAST = 3;	protected static final int PREVIOUS = 4;	protected static final int BEFOREFIRST = 5;	protected static final int AFTERLAST = 6;	protected static final int ABSOLUTE = 7;	protected static final int RELATIVE = 8;	// mutable state	protected ExecRow currentRow;	//deleteRow & updateRow make rowData null so that ResultSet is not positioned on deleted/updated row.	private DataValueDescriptor[] rowData;	protected boolean wasNull;	protected boolean isClosed;	private Object	currentStream;	// immutable state	private ResultSet theResults;	private boolean forMetaData;	private ResultSetMetaData rMetaData;	private SQLWarning topWarning;	// This activation is set by EmbedStatement	// for a single execution Activation. Ie.	// a ResultSet from a Statement.executeQuery().	// In this case the finalization of the ResultSet	// will mark the Activation as unused.	// c.f. EmbedPreparedStatement.finalize().	Activation finalizeActivation;	// Order of creation 	final int order;  	private final ResultDescription resultDescription;    // max rows limit for this result set    private int maxRows;    // The Maximum field size limt set for this result set    private final int maxFieldSize;    /*     * Incase of forward only cursors we limit the number of rows     * returned if the maxRows is set. The following varible is used     * to keep the count of number of rows returned to the user.     */    private int NumberofFetchedRows;	/**     * The statement object that originally created us.		we hang on to the statement to prevent GC from		closing it under us	 */	private final EmbedStatement stmt;        /**     * The statement that currently owns this ResultSet.     * Statements created in procedures are passed off     * to the Statement that called the procedure.     * This is to avoid the ResultSet being closed     * due to the Statement within the procedure     * or the nested Connection being closed.     */	private EmbedStatement owningStmt;        /**     * Statement object the application used to     * create this ResultSet.     */    private Statement applicationStmt;    	private final boolean isAtomic;	private final int concurrencyOfThisResultSet;	//copyOfDatabaseRow will keep the original contents of the columns of the current row which got updated.	//These will be used if user decides to cancel the changes made to the row using cancelRowUpdates.	private DataValueDescriptor[] copyOfDatabaseRow;	private boolean[] columnGotUpdated; //these are the columns which have been updated so far. Used to build UPDATE...WHERE CURRENT OF sql	private boolean currentRowHasBeenUpdated; //Gets set to true after first updateXXX on a row. Gets reset to false when the cursor moves off the row    private int fetchDirection;    private int fetchSize;	/**	 * This class provides the glue between the Cloudscape	 * resultset and the JDBC resultset, mapping calls-to-calls.	 */	public EmbedResultSet(EmbedConnection conn, ResultSet resultsToWrap,		boolean forMetaData, EmbedStatement stmt, boolean isAtomic)        throws SQLException {		super(conn);		if (SanityManager.DEBUG)		SanityManager.ASSERT(resultsToWrap!=null);		theResults = resultsToWrap;		this.forMetaData = forMetaData;        this.applicationStmt = this.stmt = owningStmt = stmt;		this.isAtomic = isAtomic;		//If the Statement object has CONCUR_READ_ONLY set on it then the concurrency on the ResultSet object will be CONCUR_READ_ONLY also.		//But, if the Statement object has CONCUR_UPDATABLE set on it, then the concurrency on the ResultSet object can be		//CONCUR_READ_ONLY or CONCUR_UPDATABLE depending on whether the underlying language resultset is updateable or not.		//If the underlying language resultset is not updateable, then the concurrency of the ResultSet object will be CONCUR_READ_ONLY		//and a warning will be issued on the ResultSet object.		if (stmt == null) concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY;		else if (stmt.getResultSetConcurrency() == JDBC20Translation.CONCUR_READ_ONLY)			concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY;		else {			if (!isForUpdate()) { //language resultset not updatable				concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY;				SQLWarning w = StandardException.newWarning(SQLState.QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);				if (topWarning == null)					topWarning = w;				else					topWarning.setNextWarning(w);			} else					concurrencyOfThisResultSet = JDBC20Translation.CONCUR_UPDATABLE;		}		// Fill in the column types		resultDescription = theResults.getResultDescription();		//initialize arrays related to updateRow implementation		columnGotUpdated = new boolean[getMetaData().getColumnCount()];		copyOfDatabaseRow = new DataValueDescriptor[columnGotUpdated.length];        // assign the max rows and maxfiled size limit for this result set        if (stmt != null)        {           // At connectivity level we handle only for forward only cursor           if (stmt.resultSetType == JDBC20Translation.TYPE_FORWARD_ONLY)               maxRows = stmt.maxRows;           maxFieldSize = stmt.MaxFieldSize;        }		else			maxFieldSize = 0;		order = conn.getResultSetOrderId();	}	/**		JDBC states that a ResultSet is closed when garbage collected.		We simply mark the activation as unused. Some later use		of the connection will clean everything up.		@exception Throwable Allows any exception to be thrown during finalize	*/	protected void finalize() throws Throwable {		super.finalize();		if (finalizeActivation != null) {			finalizeActivation.markUnused();		}			}	// onRow protects us from making requests of	// resultSet that would fail with NullPointerExceptions	// or milder problems due to not having a row.	protected final DataValueDescriptor[] checkOnRow() throws SQLException	{		DataValueDescriptor[] theCurrentRow = rowData;		if (theCurrentRow == null)			throw newSQLException(SQLState.NO_CURRENT_ROW);		return theCurrentRow;	}	/**		Check the column is in range *and* return the JDBC type of the column.		@exception SQLException ResultSet is not on a row or columnIndex is out of range.	*/	final int getColumnType(int columnIndex) throws SQLException {		checkOnRow(); // first make sure there's a row				if (columnIndex < 1 ||		    columnIndex > resultDescription.getColumnCount())			throw newSQLException(SQLState.COLUMN_NOT_FOUND,                          new Integer(columnIndex));		return resultDescription.getColumnDescriptor(columnIndex).getType().getJDBCTypeId();	}	/*	 * java.sql.ResultSet interface	 */    /**     * A ResultSet is initially positioned before its first row; the     * first call to next makes the first row the current row; the     * second call makes the second row the current row, etc.     *     * <P>If an input stream from the previous row is open, it is     * implicitly closed. The ResultSet's warning chain is cleared     * when a new row is read.     *     * @return true if the new current row is valid; false if there     * are no more rows	 * @exception SQLException thrown on failure.     */    public boolean next() throws SQLException 	{        // we seem to have some trigger paths which don't have        // statement initialized, may not need this check in those cases        if (maxRows !=0 )        {            NumberofFetchedRows++;                // check whether we hit the maxRows limit             if (NumberofFetchedRows > maxRows)             {                //we return false for the next call when maxRows is hit                closeCurrentStream();                return false;            }        }	    //since we are moving off of the current row, need to initialize state corresponding to updateRow implementation	    for (int i=0; i < columnGotUpdated.length; i++)            columnGotUpdated[i] = false;	    currentRowHasBeenUpdated = false;	    return movePosition(NEXT, 0, "next");	}	protected boolean movePosition(int position, String positionText)		throws SQLException	{		return movePosition(position, 0, positionText);	}	protected boolean movePosition(int position, int row, String positionText)		throws SQLException	{		closeCurrentStream();	// closing currentStream does not depend on the								// underlying connection.  Do this outside of								// the connection synchronization.		checkExecIfClosed(positionText);	// checking result set closure does not depend								// on the underlying connection.  Do this								// outside of the connection synchronization.		synchronized (getConnectionSynchronization()) {					setupContextStack();		    try {				LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();		    try {				/* Push and pop a StatementContext around a next call				 * so that the ResultSet will get correctly closed down				 * on an error.				 * (Cache the LanguageConnectionContext)				 */				StatementContext statementContext = lcc.pushStatementContext(isAtomic, getSQLText(),														getParameterValueSet(), false);				switch (position)				{					case BEFOREFIRST:						currentRow = theResults.setBeforeFirstRow();						break;					case FIRST:						currentRow = theResults.getFirstRow();						break;					case NEXT:						currentRow = theResults.getNextRow();						break;					case LAST:						currentRow = theResults.getLastRow();						break;					case AFTERLAST:						currentRow = theResults.setAfterLastRow();						break;					case PREVIOUS:						currentRow = theResults.getPreviousRow();						break;					case ABSOLUTE:						currentRow = theResults.getAbsoluteRow(row);						break;					case RELATIVE:						currentRow = theResults.getRelativeRow(row);						break;					default:						if (SanityManager.DEBUG)						{							SanityManager.THROWASSERT(								"Unexpected value for position - " + position);						}				}				lcc.popStatementContext(statementContext, null);						    } catch (Throwable t) {				/*				 * Need to close the result set here because the error might				 * cause us to lose the current connection if this is an XA				 * connection and we won't be able to do the close later				 */				throw closeOnTransactionError(t);			}         			SQLWarning w = theResults.getWarnings();			if (w != null) {				if (topWarning == null)					topWarning = w;				else					topWarning.setNextWarning(w);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -