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

📄 baseactivation.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.execute.BaseActivation   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.ContextManager;import org.apache.derby.iapi.services.context.Context;import org.apache.derby.iapi.jdbc.ConnectionContext;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.execute.CursorResultSet;import org.apache.derby.iapi.sql.execute.ExecPreparedStatement;import org.apache.derby.iapi.sql.execute.CursorActivation;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.NoPutResultSet;import org.apache.derby.iapi.sql.ParameterValueSet;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.sql.execute.ResultSetFactory;import org.apache.derby.iapi.sql.execute.ConstantAction;import org.apache.derby.iapi.types.DataValueFactory;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.NumberDataValue;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.depend.DependencyManager;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.context.ContextService;import org.apache.derby.iapi.services.loader.GeneratedClass;import org.apache.derby.iapi.services.loader.GeneratedByteCode;import org.apache.derby.iapi.services.loader.GeneratedMethod;import org.apache.derby.iapi.services.loader.ClassFactory;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.property.PropertyUtil;import org.apache.derby.iapi.sql.compile.Optimizer;import org.apache.derby.iapi.reference.Property;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.sql.execute.RunTimeStatistics;import java.sql.Connection;import java.sql.SQLException;import java.sql.SQLWarning;import java.util.ArrayList;import java.util.Enumeration;import java.util.Vector;import java.util.Hashtable;import java.util.HashSet;import org.apache.derby.iapi.util.ReuseFactory;import org.apache.derby.iapi.sql.execute.TemporaryRowHolder;/** * BaseActivation * provides the fundamental support we expect all activations to have. * Doesn't actually implement any of the activation interface, * expects the subclasses to do that. */public abstract class BaseActivation implements CursorActivation, GeneratedByteCode{	protected ResultSetFactory rsFactory;	protected ExecutionFactory exFactory;	protected	DataValueFactory			dvFactory;	protected	LanguageConnectionContext	lcc;	protected ContextManager			cm;	protected /*private*/ ExecutionContext			ec;	protected ExecPreparedStatement preStmt;	protected ResultSet resultSet;	protected ResultDescription resultDescription;	protected boolean closed;	private String cursorName;		protected int numSubqueries;	private boolean singleExecution;	private boolean inUse;	private java.sql.ResultSet targetVTI;	private SQLWarning warnings;	private GeneratedClass gc;	// my Generated class object.	private boolean checkRowCounts;	private HashSet rowCountsCheckedThisExecution = new HashSet(4, 0.9f);	private static final long MAX_SQRT = (long) Math.sqrt(Long.MAX_VALUE);	// When the row count exceeds this number, we should recompile if	// the difference in row counts is greater than 10%.  If it's less	// than this number, we use an entirely different technique to check	// for recompilation.  See comments below, in informOfRowCount()	private static final int TEN_PERCENT_THRESHOLD = 400;	/* Performance optimization for update/delete - only	 * open heap ConglomerateController once when doing	 * index row to base row on search	 */	private ConglomerateController  updateHeapCC;	private ScanController			indexSC;	private long					indexConglomerateNumber = -1;	private TableDescriptor ddlTableDescriptor;	private int maxRows = -1;	private boolean			forCreateTable;	private boolean			scrollable;  	private boolean resultSetHoldability;	//beetle 3865: updateable cursor using index.  A way of communication	//between cursor activation and update activation.	private CursorResultSet forUpdateIndexScan;	//Following three are used for JDBC3.0 auto-generated keys feature.	//autoGeneratedKeysResultSetMode will be set true if at the time of statement execution,	//either Statement.RETURN_GENERATED_KEYS was passed or an array of (column positions or	//column names) was passed	private boolean autoGeneratedKeysResultSetMode;	private int[] autoGeneratedKeysColumnIndexes ;	private String[] autoGeneratedKeysColumnNames ;	//Following is the position of the session table names list in savedObjects in compiler context	//This is updated to be the correct value at cursor generate time if the cursor references any session table names.	//If the cursor does not reference any session table names, this will stay negative	protected int indexOfSessionTableNamesInSavedObjects = -1;	// WARNING: these fields are accessed by code generated in the 	// ExpressionClassBuilder: don't change them unless you 	// make the appropriate changes there.	protected ExecRow[] row;	protected ParameterValueSet pvs;	//	// constructors	//	protected BaseActivation()	{		super();	}	public final void initFromContext(Context context) {		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(context!=null, "NULL context passed to BaseActivation.initFromContext");		}		this.cm = context.getContextManager();		lcc = (LanguageConnectionContext) cm.getContext(LanguageConnectionContext.CONTEXT_ID);		if (SanityManager.DEBUG) {			if (lcc == null)				SanityManager.THROWASSERT("lcc is null in activation type " + getClass());		}		dvFactory = lcc.getDataValueFactory();		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(dvFactory != null,								 "No data value factory in getDataValueFactory");		}		ec = lcc.getExecutionContext();		// look for the execution context and		// get our result set factory from it.		rsFactory = ec.getResultSetFactory();		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(rsFactory!=null, "Unable to find ResultSetFactory");		}		exFactory = ec.getExecutionFactory();		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(exFactory!=null, "Unable to find ExecutionFactory");		}				// mark in use		inUse = true;				// add this activation to the pool for the connection.		lcc.addActivation(this);	}	//	// Activation interface	//	public final ExecPreparedStatement getPreparedStatement() {		return preStmt;	}	public ConstantAction getConstantAction() {		return preStmt.getConstantAction();	}	public final void checkStatementValidity() throws StandardException {		if (preStmt == null)			return;		synchronized (preStmt) {			if ((gc == preStmt.getActivationClass()) && preStmt.upToDate())				return;		}		StandardException se = StandardException.newException(SQLState.LANG_STATEMENT_NEEDS_RECOMPILE);		se.setReport(StandardException.REPORT_NEVER);		throw se;	}	/**		Link this activation with its PreparedStatement.		It can be called with null to break the link with the		PreparedStatement.	*/	public final void setupActivation(ExecPreparedStatement ps, boolean scrollable) {		preStmt = ps;		if (ps != null) {			// get the result set description   			resultDescription = ps.getResultDescription();			this.scrollable = scrollable;		} else {			resultDescription = null;			this.scrollable = false;		}	}	public ResultSet getResultSet() {		return resultSet;	}	public void clearResultSet() {		resultSet = null;	}	/**		Get the saved RowLocation.		@param itemNumber	The saved item number.		@return	A RowLocation template for the conglomerate	 */	public RowLocation getRowLocationTemplate(int itemNumber)	{		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(itemNumber >= 0,				"itemNumber expected to be >= 0");			if (! (getPreparedStatement().getSavedObject(itemNumber) instanceof RowLocation))			{				SanityManager.THROWASSERT(					"getPreparedStatement().getSavedObject(itemNumber) expected to be " +					"instance of RowLocation, not " +					getPreparedStatement().getSavedObject(itemNumber).getClass().getName() +					", query is " + getPreparedStatement().getSource());			}			RowLocation rl = (RowLocation) getPreparedStatement().getSavedObject(itemNumber);			if (! (rl.cloneObject() instanceof RowLocation))			{				SanityManager.THROWASSERT(					"rl.cloneObject() expected to be " +					"instance of RowLocation, not " +					rl.getClass().getName() +					", query is " + getPreparedStatement().getSource());			}		}		/* We have to return a clone of the saved RowLocation due		 * to the shared cache of SPSs.		 */		return (RowLocation)			((RowLocation)(getPreparedStatement().getSavedObject(itemNumber))).cloneObject();	}	/*	 */	public ResultDescription getResultDescription() {		if (SanityManager.DEBUG)	    	SanityManager.ASSERT(resultDescription != null, "Must have a result description");	   	    return resultDescription;	}	/**		This is a partial implementation of reset.		Subclasses will want to reset information		they are aware of, such as parameters.		<p>		All subclasses must call super.reset() and		then do their cleanup.		<p>		The execute call must set the resultSet field		to be the resultSet that it has returned.		@exception StandardException on error	 */	public void reset() throws StandardException	{		// if resultset holdability after commit is false, close it		if (resultSet != null && (!resultSetHoldability || !resultSet.returnsRows())) {			// would really like to check if it is open,			// this is as close as we can approximate that.			resultSet.close();			resultSet = null; // forget about it, prepare for next exec.		}		updateHeapCC = null;		// REMIND: do we need to get them to stop input as well?		if (!isSingleExecution())			clearWarnings();	}	/**		Closing an activation marks it as unusable. Any other		requests made on it will fail.  An activation should be		marked closed when it is expected to not be used any longer,		i.e. when the connection for it is closed, or it has suffered some		sort of severe error.		This should also remove it from the language connection context.		@exception StandardException on error	 */	public final void close() throws StandardException 	{		if (! closed) {							// markUnused();			// we finish the result set before we call reset			// because reset will set it to null.			if (resultSet != null)			{				resultSet.finish();				resultSet = null;			}			// we call reset so that if the actual type of "this"			// is a subclass of BaseActivation, its cleanup will			// also happen -- reset in the actual type is called,			// not reset in BaseActivation.  Subclass reset's			// are supposed to call super.reset() as well.			reset(); // get everything related to executing released			closed = true;			LanguageConnectionContext lcc = getLanguageConnectionContext();			lcc.removeActivation(this);			if (preStmt != null) {				preStmt.finish(lcc);				preStmt = null;			}			try {				closeActivationAction();			} catch (Throwable e) {				throw StandardException.plainWrapException(e);			}		}			}	/**		A generated class can create its own closeActivationAction		method to invoke special logic when the activation is closed.	*/	protected void closeActivationAction() throws Exception {		// no code to be added here as generated code		// will not call super.closeActivationAction()	}	/**		Find out if the activation closed or not.		@return true if the prepared statement has been closed.	 */	public boolean isClosed() {		return closed;	}	/**		Set this Activation for a single execution.		@see Activation#setSingleExecution	*/	public void setSingleExecution() {		singleExecution = true;	}	/**		Returns true if this Activation is only going to be used for		one execution.		@see Activation#isSingleExecution	*/	public boolean isSingleExecution() {		return singleExecution;	}	/**		Get the number of subqueries in the entire query.		@return int	 The number of subqueries in the entire query.	 */	public int getNumSubqueries() {		return numSubqueries;	}	/**	 * @see Activation#isCursorActivation	 */	public boolean isCursorActivation()	{		return false;	}	//	// GeneratedByteCode interface	//	public final void setGC(GeneratedClass gc) {		this.gc = gc;	}	public final GeneratedClass getGC() {		if (SanityManager.DEBUG) {			if (gc == null)				SanityManager.THROWASSERT("move code requiring GC to postConstructor() method!!");		}		return gc;	}	public final GeneratedMethod getMethod(String methodName) throws StandardException {		return getGC().getMethod(methodName);	}	public Object e0() throws StandardException { return null; } 	public Object e1() throws StandardException { return null; }	public Object e2() throws StandardException { return null; }	public Object e3() throws StandardException { return null; }	public Object e4() throws StandardException { return null; } 	public Object e5() throws StandardException { return null; }	public Object e6() throws StandardException { return null; }	public Object e7() throws StandardException { return null; }	public Object e8() throws StandardException { return null; } 	public Object e9() throws StandardException { return null; }	//	// class interface	//	/**	 * Temporary tables can be declared with ON COMMIT DELETE ROWS. But if the table has a held curosr open at	 * commit time, data should not be deleted from the table. This method, (gets called at commit time) checks if this	 * activation held cursor and if so, does that cursor reference the passed temp table name.	 *	 * @return	true if this activation has held cursor and if it references the passed temp table name	 */	public boolean checkIfThisActivationHasHoldCursor(String tableName)	{		if (!inUse)			return false;		if (resultSetHoldability == false) //if this activation is not held over commit, do not need to worry about it			return false;		if (indexOfSessionTableNamesInSavedObjects == -1) //if this activation does not refer to session schema tables, do not need to worry about it			return false;		/* is there an open result set? */		if ((resultSet != null) && !resultSet.isClosed() && resultSet.returnsRows())		{			//If we came here, it means this activation is held over commit and it reference session table names			//Now let's check if it referneces the passed temporary table name which has ON COMMIT DELETE ROWS defined on it.			return ((ArrayList)getPreparedStatement().getSavedObject(indexOfSessionTableNamesInSavedObjects)).contains(tableName);		}		return false;	}	/**	   remember the cursor name	 */	public void	setCursorName(String cursorName)	{		if (isCursorActivation())			this.cursorName = cursorName;	}	/**	  get the cursor name.  For something that isn't

⌨️ 快捷键说明

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