org.apache.derby.impl.sql.compile
Class DeleteNode

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.StatementNode
          extended by org.apache.derby.impl.sql.compile.DMLStatementNode
              extended by org.apache.derby.impl.sql.compile.DMLModStatementNode
                  extended by org.apache.derby.impl.sql.compile.DeleteNode
All Implemented Interfaces:
Visitable

public class DeleteNode
extends DMLModStatementNode

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.


Field Summary
private  boolean cascadeDelete
           
private static java.lang.String COLUMNNAME
           
protected  boolean deferred
           
private  ConstantAction[] dependentConstantActions
           
private  StatementNode[] dependentNodes
           
protected  ExecRow emptyHeapRow
           
protected  FKInfo fkInfo
           
protected  FormatableBitSet readColsBitSet
           
protected  FromTable targetTable
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.DMLModStatementNode
fkColArrays, fkColDescriptors, fkIndexConglomNumbers, fkRefActions, fkTableNames, graphHashTable, indexConglomerateNumbers, indexNames, indicesToMaintain, isDependentTable, lockMode, relevantCdl, relevantTriggers, resultColumnList, synonymTableName, targetTableDescriptor, targetTableName, targetVTI, triggerInfo
 
Fields inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
resultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.StatementNode
NEED_CURSOR_ACTIVATION, NEED_DDL_ACTIVATION, NEED_NOTHING_ACTIVATION, NEED_PARAM_ACTIVATION, NEED_ROW_ACTIVATION
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
DeleteNode()
           
 
Method Summary
 void bindStatement()
          Bind this DeleteNode.
private  void correlateAddedColumns(ResultColumnList rcl, FromTable fromTable)
           
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Code generation for delete.
private static FormatableBitSet getDeleteReadMap(TableDescriptor baseTable, java.util.Vector conglomVector, GenericDescriptorList relevantTriggers, boolean[] needsDeferredProcessing)
          Builds a bitmap of all columns which should be read from the Store in order to satisfy an DELETE statement. 1) finds all indices on this table 2) adds the index columns to a bitmap of affected columns 3) adds the index descriptors to a list of conglomerate descriptors. 4) finds all DELETE triggers on the table 5) if there are any DELETE triggers, then do one of the following a)If all of the triggers have MISSING referencing clause, then that means that the trigger actions do not have access to before and after values.
private  StatementNode getDependentTableNode(java.lang.String tableName, int refAction, ColumnDescriptorList cdl)
          In case of referential actions, we require to perform DML (UPDATE or DELETE) on the dependent tables.
private  StatementNode getEmptyDeleteNode(java.lang.String schemaName, java.lang.String targetTableName)
           
private  StatementNode getEmptyUpdateNode(java.lang.String schemaName, java.lang.String targetTableName, ColumnDescriptorList cdl)
           
(package private)  int getPrivType()
          Return default privilege needed for this node.
 FormatableBitSet getReadMap(DataDictionary dd, TableDescriptor baseTable)
          Gets the map of all columns which must be read out of the base table.
private  ResultColumnList getSetClause(TableName tabName, ColumnDescriptorList cdl)
           
protected  int getStatementType()
          Return the type of statement, something from StatementType.
 void init(java.lang.Object targetTableName, java.lang.Object queryExpression)
          Initializer for a DeleteNode.
 ConstantAction makeConstantAction()
          Compile constants that Execution will use
 void optimizeStatement()
          Generate an optimized QueryTree from a bound QueryTree.
 boolean referencesSessionSchema()
          Return true if the node references SESSION schema tables (temporary or permanent)
 java.lang.String statementToString()
           
 
Methods inherited from class org.apache.derby.impl.sql.compile.DMLModStatementNode
acceptChildren, adjustDeferredFlag, bindConstraints, bindRowScopedExpression, generateCheckConstraints, generateCheckConstraints, generateCodeForTemporaryTable, generateGenerationClauses, getAffectedIndexes, getAllRelevantConstraints, getAllRelevantTriggers, getCheckConstraints, getFKInfo, getReadColMap, getResultColumnList, getResultColumnList, getSchemaDescriptor, getTriggerInfo, getXAffectedIndexes, hasCheckConstraints, hasGenerationClauses, init, isAtomic, markAffectedIndexes, normalizeSynonymColumns, parseAndBindGenerationClauses, parseCheckConstraint, parseGenerationClause, printSubNodes, requiresDeferredProcessing, setRefActionInfo, setTarget, verifyTargetTable
 
Methods inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
activationKind, bind, bindExpressions, bindExpressionsWithTables, bindResultSetsWithTables, bindTables, generateParameterValueSet, getResultSetNode, makeResultDescription
 
Methods inherited from class org.apache.derby.impl.sql.compile.StatementNode
executeSchemaName, executeStatementName, generate, getSPSName, lockTableForCompilation, needsSavepoint, toString
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, stackPrint, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COLUMNNAME

private static final java.lang.String COLUMNNAME
See Also:
Constant Field Values

deferred

protected boolean deferred

emptyHeapRow

protected ExecRow emptyHeapRow

targetTable

protected FromTable targetTable

fkInfo

protected FKInfo fkInfo

readColsBitSet

protected FormatableBitSet readColsBitSet

dependentConstantActions

private ConstantAction[] dependentConstantActions

cascadeDelete

private boolean cascadeDelete

dependentNodes

private StatementNode[] dependentNodes
Constructor Detail

DeleteNode

public DeleteNode()
Method Detail

init

public void init(java.lang.Object targetTableName,
                 java.lang.Object queryExpression)
Initializer for a DeleteNode.

Overrides:
init in class DMLModStatementNode
Parameters:
targetTableName - The name of the table to delete from
queryExpression - The query expression that will generate the rows to delete from the given table

statementToString

public java.lang.String statementToString()
Overrides:
statementToString in class DMLModStatementNode

bindStatement

public void bindStatement()
                   throws StandardException
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.

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.

Overrides:
bindStatement in class StatementNode
Throws:
StandardException - Thrown on error

getPrivType

int getPrivType()
Description copied from class: DMLStatementNode
Return default privilege needed for this node. Other DML nodes can override this method to set their own default privilege.

Overrides:
getPrivType in class DMLStatementNode
Returns:
true if the statement is atomic

referencesSessionSchema

public boolean referencesSessionSchema()
                                throws StandardException
Return true if the node references SESSION schema tables (temporary or permanent)

Overrides:
referencesSessionSchema in class QueryTreeNode
Returns:
true if references SESSION schema tables, else false
Throws:
StandardException - Thrown on error

makeConstantAction

public ConstantAction makeConstantAction()
                                  throws StandardException
Compile constants that Execution will use

Overrides:
makeConstantAction in class QueryTreeNode
Throws:
StandardException - Thrown on failure

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Code generation for delete. The generated code will contain: o A static member for the (xxx)ResultSet with the RowLocations o The static member will be assigned the appropriate ResultSet within the nested calls to get the ResultSets. (The appropriate cast to the (xxx)ResultSet will be generated.) o The CurrentRowLocation() in SelectNode's select list will generate a new method for returning the RowLocation as well as a call to that method which will be stuffed in the call to the ProjectRestrictResultSet. o In case of referential actions, this function generate an array of resultsets on its dependent tables.

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The execute() method to be built
Throws:
StandardException - Thrown on error

getStatementType

protected final int getStatementType()
Return the type of statement, something from StatementType.

Overrides:
getStatementType in class QueryTreeNode
Returns:
the type of statement

getReadMap

public FormatableBitSet getReadMap(DataDictionary dd,
                                   TableDescriptor baseTable)
                            throws StandardException
Gets the map of all columns which must be read out of the base table. These are the columns needed to: o maintain indices o maintain foreign keys The returned map is a FormatableBitSet with 1 bit for each column in the table plus an extra, unsued 0-bit. If a 1-based column id must be read from the base table, then the corresponding 1-based bit is turned ON in the returned FormatableBitSet.

Parameters:
dd - the data dictionary to look in
baseTable - the base table descriptor
Returns:
a FormatableBitSet of columns to be read out of the base table
Throws:
StandardException - Thrown on error

getDependentTableNode

private StatementNode getDependentTableNode(java.lang.String tableName,
                                            int refAction,
                                            ColumnDescriptorList cdl)
                                     throws StandardException
In case of referential actions, we require to perform DML (UPDATE or DELETE) on the dependent tables. Following function returns the DML Node for the dependent table.

Throws:
StandardException

getEmptyDeleteNode

private StatementNode getEmptyDeleteNode(java.lang.String schemaName,
                                         java.lang.String targetTableName)
                                  throws StandardException
Throws:
StandardException

getEmptyUpdateNode

private StatementNode getEmptyUpdateNode(java.lang.String schemaName,
                                         java.lang.String targetTableName,
                                         ColumnDescriptorList cdl)
                                  throws StandardException
Throws:
StandardException

getSetClause

private ResultColumnList getSetClause(TableName tabName,
                                      ColumnDescriptorList cdl)
                               throws StandardException
Throws:
StandardException

optimizeStatement

public void optimizeStatement()
                       throws StandardException
Description copied from class: DMLModStatementNode
Generate an optimized QueryTree from a bound QueryTree. Actually, it can annotate the tree in place rather than generate a new tree, but this interface allows the root node of the optimized QueryTree to be different from the root node of the bound QueryTree. For non-optimizable statements, this method is a no-op. Throws an exception if the tree is not bound, or if the binding is out of date.

Overrides:
optimizeStatement in class DMLModStatementNode
Throws:
StandardException - Thrown on failure

getDeleteReadMap

private static FormatableBitSet getDeleteReadMap(TableDescriptor baseTable,
                                                 java.util.Vector conglomVector,
                                                 GenericDescriptorList relevantTriggers,
                                                 boolean[] needsDeferredProcessing)
                                          throws StandardException
Builds a bitmap of all columns which should be read from the Store in order to satisfy an DELETE statement. 1) finds all indices on this table 2) adds the index columns to a bitmap of affected columns 3) adds the index descriptors to a list of conglomerate descriptors. 4) finds all DELETE triggers on the table 5) if there are any DELETE triggers, then do one of the following a)If all of the triggers have MISSING referencing clause, then that means that the trigger actions do not have access to before and after values. In that case, there is no need to blanketly decide to include all the columns in the read map just because there are triggers defined on the table. b)Since one/more triggers have REFERENCING clause on them, get all the columns because we don't know what the user will ultimately reference. 6) adds the triggers to an evolving list of triggers

Parameters:
conglomVector - OUT: vector of affected indices
relevantTriggers - IN/OUT. Passed in as an empty list. Filled in as we go.
needsDeferredProcessing - IN/OUT. true if the statement already needs deferred processing. set while evaluating this routine if a trigger requires deferred processing
Returns:
a FormatableBitSet of columns to be read out of the base table
Throws:
StandardException - Thrown on error

correlateAddedColumns

private void correlateAddedColumns(ResultColumnList rcl,
                                   FromTable fromTable)
                            throws StandardException
Throws:
StandardException

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.