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

📄 deletenode.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.DeleteNode   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.compile;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.GenericDescriptorList;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.sql.StatementType;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.execute.CursorResultSet;import org.apache.derby.iapi.sql.execute.ConstantAction;import org.apache.derby.iapi.sql.execute.ExecPreparedStatement;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.vti.DeferModification;import org.apache.derby.catalog.UUID;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.impl.sql.compile.ActivationClassBuilder;import org.apache.derby.impl.sql.execute.DeleteConstantAction;import org.apache.derby.impl.sql.execute.FKInfo;import java.lang.reflect.Modifier;import org.apache.derby.iapi.services.classfile.VMOpcode;import org.apache.derby.iapi.services.io.FormatableProperties;import java.util.Vector;import java.util.Hashtable;import java.util.Properties;import org.apache.derby.iapi.sql.compile.NodeFactory;import org.apache.derby.iapi.util.ReuseFactory;import org.apache.derby.iapi.sql.depend.Dependent;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.services.compiler.LocalField;/** * A DeleteNode represents a DELETE statement. It is the top-level node * for the statement. * * For positioned delete, there may be no from table specified. * The from table will be derived from the cursor specification of * the named cursor. * * @author Jeff Lichtman */public class DeleteNode extends DMLModStatementNode{	/* Column name for the RowLocation column in the ResultSet */	public static final String COLUMNNAME = "###RowLocationToDelete";	/* Filled in by bind. */	protected boolean				deferred;	protected ExecRow				emptyHeapRow;	protected FromTable				targetTable;	protected FKInfo				fkInfo;	protected FormatableBitSet readColsBitSet;	private ConstantAction[] dependentConstantActions;	private boolean cascadeDelete;	private QueryTreeNode[] dependentNodes;	/**	 * Initializer for a DeleteNode.	 *	 * @param targetTableName	The name of the table to delete from	 * @param queryExpresssion	The query expression that will generate	 *				the rows to delete from the given table	 */	public void init(Object targetTableName,					  Object queryExpression)	{		super.init(queryExpression);		this.targetTableName = (TableName) targetTableName;	}	public String statementToString()	{		return "DELETE";	}	/**	 * Bind this DeleteNode.  This means looking up tables and columns and	 * getting their types, and figuring out the result types of all	 * expressions, as well as doing view resolution, permissions checking,	 * etc.	 * <p>	 * If any indexes need to be updated, we add all the columns in the	 * base table to the result column list, so that we can use the column	 * values as look-up keys for the index rows to be deleted.  Binding a	 * delete will also massage the tree so that the ResultSetNode has 	 * column containing the RowLocation of the base row.	 *	 * @return	The bound query tree	 *	 * @exception StandardException		Thrown on error	 */	public QueryTreeNode bind() throws StandardException	{		FromList					fromList =								(FromList) getNodeFactory().getNode(									C_NodeTypes.FROM_LIST,									getNodeFactory().doJoinOrderOptimization(),									getContextManager());		ResultColumn				rowLocationColumn = null;		CurrentRowLocationNode		rowLocationNode;		TableName					cursorTargetTableName = null;		CurrentOfNode       		currentOfNode = null;                DataDictionary dataDictionary = getDataDictionary();		super.bindTables(dataDictionary);		// wait to bind named target table until the underlying		// cursor is bound, so that we can get it from the		// cursor if this is a positioned delete.		// for positioned delete, get the cursor's target table.		if (SanityManager.DEBUG)		SanityManager.ASSERT(resultSet != null && resultSet instanceof SelectNode,			"Delete must have a select result set");		SelectNode sel;		sel = (SelectNode)resultSet;		targetTable = (FromTable) sel.fromList.elementAt(0);		if (targetTable instanceof CurrentOfNode)		{			currentOfNode = (CurrentOfNode) targetTable;			cursorTargetTableName = currentOfNode.getBaseCursorTargetTableName();			// instead of an assert, we might say the cursor is not updatable.			if (SanityManager.DEBUG)				SanityManager.ASSERT(cursorTargetTableName != null);		}		if (targetTable instanceof FromVTI)		{			targetVTI = (FromVTI) targetTable;			targetVTI.setTarget();		}		else		{			// positioned delete can leave off the target table.			// we get it from the cursor supplying the position.			if (targetTableName == null)			{				// verify we have current of				if (SanityManager.DEBUG)					SanityManager.ASSERT(cursorTargetTableName!=null);				targetTableName = cursorTargetTableName;			}			// for positioned delete, we need to verify that			// the named table is the same as the cursor's target (base table name).			else if (cursorTargetTableName != null)			{				// this match requires that the named table in the delete				// be the same as a base name in the cursor.				if ( !targetTableName.equals(cursorTargetTableName))				{					throw StandardException.newException(SQLState.LANG_CURSOR_DELETE_MISMATCH, 						targetTableName,						currentOfNode.getCursorName());				}			}			/* descriptor must exist, tables already bound.			 * No need to do this for VTI as VTI was bound in			 * super.bindTables() above.			 */			verifyTargetTable();		}		/* Generate a select list for the ResultSetNode - CurrentRowLocation(). */		if (SanityManager.DEBUG)		SanityManager.ASSERT((resultSet.resultColumns == null),							  "resultColumns is expected to be null until bind time");		if (targetTable instanceof FromVTI)		{			getResultColumnList();			resultColumnList = targetTable.getResultColumnsForList(null, resultColumnList, null);			/* Set the new result column list in the result set */			resultSet.setResultColumns(resultColumnList);		}		else		{			/*			** Start off assuming no columns from the base table			** are needed in the rcl.			*/			resultColumnList = new ResultColumnList();			FromBaseTable fbt = getResultColumnList(resultColumnList);			readColsBitSet = getReadMap(dataDictionary,										targetTableDescriptor);			resultColumnList = fbt.addColsToList(resultColumnList, readColsBitSet);			/*			** If all bits are set, then behave as if we chose all			** in the first place			*/			int i = 1;			int size = targetTableDescriptor.getMaxColumnID();			for (; i <= size; i++)			{				if (!readColsBitSet.get(i))				{					break;				}			}			if (i > size)			{				readColsBitSet = null;			}			/*			** Construct an empty heap row for use in our constant action.			*/			emptyHeapRow = targetTableDescriptor.getEmptyExecRow(getContextManager());			/* Generate the RowLocation column */			rowLocationNode = (CurrentRowLocationNode) getNodeFactory().getNode(										C_NodeTypes.CURRENT_ROW_LOCATION_NODE,										getContextManager());			rowLocationColumn =				(ResultColumn) getNodeFactory().getNode(									C_NodeTypes.RESULT_COLUMN,									COLUMNNAME,									rowLocationNode,									getContextManager());			rowLocationColumn.markGenerated();			/* Append to the ResultColumnList */			resultColumnList.addResultColumn(rowLocationColumn);			/* Set the new result column list in the result set */			resultSet.setResultColumns(resultColumnList);		}		/* Bind the expressions before the ResultColumns are bound */		super.bindExpressions();		/* Bind untyped nulls directly under the result columns */		resultSet.			getResultColumns().				bindUntypedNullsToResultColumns(resultColumnList);		if (! (targetTable instanceof FromVTI))		{			/* Bind the new ResultColumn */			rowLocationColumn.bindResultColumnToExpression();			bindConstraints(dataDictionary,							getNodeFactory(),							targetTableDescriptor,							null,							resultColumnList,							(int[]) null,							readColsBitSet,							false,							true);  /* we alway include triggers in core language */			/* If the target table is also a source table, then			 * the delete will have to be in deferred mode			 * For deletes, this means that the target table appears in a			 * subquery.  Also, self-referencing foreign key deletes		 	 * are deferred.  And triggers cause the delete to be deferred.			 */			if (resultSet.subqueryReferencesTarget(									targetTableDescriptor.getName(), true) ||				requiresDeferredProcessing())			{

⌨️ 快捷键说明

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