Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class DeleteNode

extends DMLModStatementNode
Class Inheritance
Imports
java.lang.reflect.Modifier, java.util.ArrayList, .HashSet, .List, .Properties, org.apache.derby.catalog.UUID, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, .SQLState, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.LocalField, .MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.io.FormatableBitSet, .FormatableProperties, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.ResultDescription, .StatementType, org.apache.derby.iapi.sql.compile.CompilerContext, .IgnoreFilter, .ScopeFilter, org.apache.derby.iapi.sql.conn.Authorizer, org.apache.derby.iapi.sql.dictionary.ColumnDescriptor, .ColumnDescriptorList, .ConglomerateDescriptor, .DataDictionary, .TriggerDescriptorList, .TableDescriptor, .TriggerDescriptor, org.apache.derby.iapi.sql.execute.ConstantAction, org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo, .TransactionController, org.apache.derby.vti.DeferModification

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

Modifier and TypeField and Description
private boolean
private static final String
private boolean
private ConstantAction[]
private StatementNode[]
private FormatableBitSet
private FromTable
Inherited from org.apache.derby.impl.sql.compile.DMLModStatementNode:
dependentTablesfkColArraysfkColDescriptorsfkIndexConglomNumbersfkInfofkRefActionsfkSchemaNamesfkTableNamesindexConglomerateNumbersindexNamesindicesToMaintainisDependentTablelockModematchingClauserelevantCdlrelevantTriggersresultColumnListsynonymTableNametargetTableDescriptortargetTableNametargetVTItriggerInfo

Constructor Summary

AccessConstructor and Description
pack-priv
DeleteNode(TableName
The name of the table to delete from
targetTableName
,
ResultSetNode
The query expression that will generate the rows to delete from the given table
queryExpression
,
MatchingClauseNode
Non-null if this DML is part of a MATCHED clause of a MERGE statement.
matchingClause
,
ContextManager
The context manager
cm
)

Constructor for a DeleteNode.

Method Summary

Modifier and TypeMethod and Description
public void
private void
pack-priv void
generate(ActivationClassBuilder
The ActivationClassBuilder for the class being built
acb
,
MethodBuilder
The execute() method to be built
mb
)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.generate.

Code generation for delete.

private static FormatableBitSet

Returns:

a FormatableBitSet of columns to be read out of the base table
getDeleteReadMap
(TableDescriptor baseTable, List<ConglomerateDescriptor>
OUT: list of affected indices
conglomerates
,
TriggerDescriptorList
IN/OUT. Passed in as an empty list. Filled in as we go.
relevantTriggers
,
boolean[]
IN/OUT. true if the statement already needs deferred processing. set while evaluating this routine if a trigger requires deferred processing
needsDeferredProcessing
)

Builds a bitmap of all columns which should be read from the Store in order to satisfy an DELETE statement.

private StatementNode
getDependentTableNode(String schemaName, String tableName, int refAction, ColumnDescriptorList cdl)

In case of referential actions, we require to perform DML (UPDATE or DELETE) on the dependent tables.

private DeleteNode
getEmptyDeleteNode(String schemaName, String targetTableName)

private UpdateNode
getEmptyUpdateNode(String schemaName, String targetTableName, ColumnDescriptorList cdl)

pack-priv int
getPrivType()

Overrides org.apache.derby.impl.sql.compile.DMLStatementNode.getPrivType.

Return default privilege needed for this node.

public FormatableBitSet

Returns:

a FormatableBitSet of columns to be read out of the base table
getReadMap
(DataDictionary
the data dictionary to look in
dd
,
TableDescriptor
the base table descriptor
baseTable
)

Gets the map of all columns which must be read out of the base table.

private ResultColumnList
protected final int

Returns:

the type of statement
getStatementType
()

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.getStatementType.

Return the type of statement, something from StatementType.

public ConstantAction
makeConstantAction()

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.makeConstantAction.

Compile constants that Execution will use

public void
optimizeStatement()

Overrides org.apache.derby.impl.sql.compile.DMLModStatementNode.optimizeStatement.

Generate an optimized QueryTree from a bound QueryTree.

public boolean

Returns:

true if references SESSION schema tables, else false
referencesSessionSchema
()

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.referencesSessionSchema.

Return true if the node references SESSION schema tables (temporary or permanent)

pack-priv String
Inherited from org.apache.derby.impl.sql.compile.DMLModStatementNode:
acceptChildrenadjustDeferredFlagbindConstraintsbindRowScopedExpressiongenerateCheckConstraintsgenerateCheckConstraintsgenerateCodeForTemporaryTablegenerateGenerationClausesgetAffectedIndexesgetAllRelevantConstraintsgetAllRelevantTriggersgetCheckConstraintsgetFKInfogetReadColMapgetResultColumnListgetResultColumnListgetSchemaDescriptorgetTriggerInfogetXAffectedIndexeshasCheckConstraintshasGenerationClausesinMatchingClauseisAtomicmarkAffectedIndexesnormalizeSynonymColumnsparseAndBindGenerationClausesparseCheckConstraintparseGenerationClauseprintSubNodesrequiresDeferredProcessingsetRefActionInfosetTargetverifyTargetTable

Field Detail

cascadeDeleteback to summary
private boolean cascadeDelete
COLUMNNAMEback to summary
private static final String COLUMNNAME
deferredback to summary
private boolean deferred
dependentConstantActionsback to summary
private ConstantAction[] dependentConstantActions
dependentNodesback to summary
private StatementNode[] dependentNodes
readColsBitSetback to summary
private FormatableBitSet readColsBitSet
targetTableback to summary
private FromTable targetTable

Constructor Detail

DeleteNodeback to summary
pack-priv DeleteNode(TableName targetTableName, ResultSetNode queryExpression, MatchingClauseNode matchingClause, ContextManager cm)

Constructor for a DeleteNode.

Parameters
targetTableName:TableName

The name of the table to delete from

queryExpression:ResultSetNode

The query expression that will generate the rows to delete from the given table

matchingClause:MatchingClauseNode

Non-null if this DML is part of a MATCHED clause of a MERGE statement.

cm:ContextManager

The context manager

Method Detail

bindStatementback to summary
public void bindStatement() throws StandardException

Overrides org.apache.derby.impl.sql.compile.StatementNode.bindStatement.

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.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
correlateAddedColumnsback to summary
private void correlateAddedColumns(ResultColumnList rcl, FromTable fromTable) throws StandardException
generateback to summary
pack-priv void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.generate.

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.

Parameters
acb:ActivationClassBuilder

The ActivationClassBuilder for the class being built

mb:MethodBuilder

The execute() method to be built

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getDeleteReadMapback to summary
private static FormatableBitSet getDeleteReadMap(TableDescriptor baseTable, List<ConglomerateDescriptor> conglomerates, TriggerDescriptorList 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
conglomerates:List<ConglomerateDescriptor>

OUT: list of affected indices

relevantTriggers:TriggerDescriptorList

IN/OUT. Passed in as an empty list. Filled in as we go.

needsDeferredProcessing:boolean[]

IN/OUT. true if the statement already needs deferred processing. set while evaluating this routine if a trigger requires deferred processing

Returns:FormatableBitSet

a FormatableBitSet of columns to be read out of the base table

Exceptions
StandardException:
Thrown on error
getDependentTableNodeback to summary
private StatementNode getDependentTableNode(String schemaName, 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.

getEmptyDeleteNodeback to summary
private DeleteNode getEmptyDeleteNode(String schemaName, String targetTableName) throws StandardException
getEmptyUpdateNodeback to summary
private UpdateNode getEmptyUpdateNode(String schemaName, String targetTableName, ColumnDescriptorList cdl) throws StandardException
getPrivTypeback to summary
pack-priv int getPrivType()

Overrides org.apache.derby.impl.sql.compile.DMLStatementNode.getPrivType.

Doc from org.apache.derby.impl.sql.compile.DMLStatementNode.getPrivType.

Return default privilege needed for this node. Other DML nodes can override this method to set their own default privilege.

Returns:int

true if the statement is atomic

Annotations
@Override
getReadMapback to summary
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:DataDictionary

the data dictionary to look in

baseTable:TableDescriptor

the base table descriptor

Returns:FormatableBitSet

a FormatableBitSet of columns to be read out of the base table

Exceptions
StandardException:
Thrown on error
getSetClauseback to summary
private ResultColumnList getSetClause(ColumnDescriptorList cdl) throws StandardException
getStatementTypeback to summary
protected final int getStatementType()

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.getStatementType.

Return the type of statement, something from StatementType.

Returns:int

the type of statement

Annotations
@Override
makeConstantActionback to summary
public ConstantAction makeConstantAction() throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.makeConstantAction.

Compile constants that Execution will use

Annotations
@Override
Exceptions
StandardException:
Thrown on failure
optimizeStatementback to summary
public void optimizeStatement() throws StandardException

Overrides org.apache.derby.impl.sql.compile.DMLModStatementNode.optimizeStatement.

Doc from org.apache.derby.impl.sql.compile.DMLModStatementNode.optimizeStatement.

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.

Annotations
@Override
Exceptions
StandardException:
Thrown on failure
referencesSessionSchemaback to summary
public boolean referencesSessionSchema() throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.referencesSessionSchema.

Return true if the node references SESSION schema tables (temporary or permanent)

Returns:boolean

true if references SESSION schema tables, else false

Annotations
@Override
Exceptions
StandardException:
Thrown on error
statementToStringback to summary
pack-priv String statementToString()

Overrides org.apache.derby.impl.sql.compile.DMLModStatementNode.statementToString.

Annotations
@Override