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

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.StatementNode
          extended byorg.apache.derby.impl.sql.compile.DMLStatementNode
              extended byorg.apache.derby.impl.sql.compile.DMLModStatementNode
                  extended byorg.apache.derby.impl.sql.compile.UpdateNode
All Implemented Interfaces:
Visitable

public final class UpdateNode
extends DMLModStatementNode

An UpdateNode represents an UPDATE statement. It is the top node of the query tree for that statement. For positioned update, there may be no from table specified. The from table will be derived from the cursor specification of the named cursor.

Author:
Jeff Lichtman

Field Summary
 int[] changedColumnIds
           
 ValueNode checkConstraints
           
static java.lang.String COLUMNNAME
           
 boolean deferred
           
 ExecRow emptyHeapRow
           
 FKInfo fkInfo
           
protected  boolean positionedUpdate
           
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, 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_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset
 
Constructor Summary
UpdateNode()
           
 
Method Summary
 QueryTreeNode bind()
          Bind this UpdateNode.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Code generation for update.
private  int[] getChangedColumnIds(ResultColumnList rcl)
          Construct the changedColumnIds array.
 FormatableBitSet getReadMap(DataDictionary dd, TableDescriptor baseTable, ResultColumnList updateColumnList)
          Gets the map of all columns which must be read out of the base table.
protected  int getStatementType()
          Return the type of statement, something from StatementType.
static FormatableBitSet getUpdateReadMap(TableDescriptor baseTable, ResultColumnList updateColumnList, java.util.Vector conglomVector, ConstraintDescriptorList relevantConstraints, GenericDescriptorList relevantTriggers, boolean[] needsDeferredProcessing)
          Builds a bitmap of all columns which should be read from the Store in order to satisfy an UPDATE statement.
 void init(java.lang.Object targetTableName, java.lang.Object resultSet)
          Initializer for an UpdateNode.
 ConstantAction makeConstantAction()
          Compile constants that Execution will use
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 boolean referencesSessionSchema()
          Return true if the node references SESSION schema tables (temporary or permanent)
protected  void setDeferredForUpdateOfIndexColumn()
          Updates are deferred if they update a column in the index used to scan the table being updated.
 java.lang.String statementToString()
           
 java.lang.String toString()
          Convert this object to a String.
 
Methods inherited from class org.apache.derby.impl.sql.compile.DMLModStatementNode
adjustDeferredFlag, bindCheckConstraint, bindConstraints, generateCheckConstraints, generateCheckConstraints, generateCodeForTemporaryTable, getAffectedIndexes, getAllRelevantConstraints, getAllRelevantTriggers, getCheckConstraints, getFKInfo, getReadColMap, getResultColumnList, getResultColumnList, getSchemaDescriptor, getTriggerInfo, getXAffectedIndexes, hasCheckConstraints, init, isAtomic, markAffectedIndexes, optimize, parseCheckConstraint, requiresDeferredProcessing, setRefActionInfo, setTarget, verifyTargetTable
 
Methods inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
accept, activationKind, bind, bindExpressions, bindExpressionsWithTables, bindResultSetsWithTables, bindTables, generateParameterHolders, generateParameterValueSet, getResultSetNode, makeResultDescription
 
Methods inherited from class org.apache.derby.impl.sql.compile.StatementNode
generate, lockTableForCompilation
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, isInstanceOf, isSessionSchema, isSessionSchema, makeTableName, needsSavepoint, nodeHeader, parseQueryText, printLabel, setBeginOffset, setContextManager, setEndOffset, setNodeType, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

changedColumnIds

public int[] changedColumnIds

emptyHeapRow

public ExecRow emptyHeapRow

deferred

public boolean deferred

checkConstraints

public ValueNode checkConstraints

fkInfo

public FKInfo fkInfo

targetTable

protected FromTable targetTable

readColsBitSet

protected FormatableBitSet readColsBitSet

positionedUpdate

protected boolean positionedUpdate

COLUMNNAME

public static final java.lang.String COLUMNNAME
See Also:
Constant Field Values
Constructor Detail

UpdateNode

public UpdateNode()
Method Detail

init

public void init(java.lang.Object targetTableName,
                 java.lang.Object resultSet)
Initializer for an UpdateNode.

Overrides:
init in class DMLModStatementNode
Parameters:
targetTableName - The name of the table to update
resultSet - The ResultSet that will generate the rows to update from the given table

toString

public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class StatementNode
Returns:
This object as a String

statementToString

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

printSubNodes

public void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Overrides:
printSubNodes in class DMLStatementNode
Parameters:
depth - The depth of this node in the tree
Returns:
Nothing

bind

public QueryTreeNode bind()
                   throws StandardException
Bind this UpdateNode. 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.

Binding an update will also massage the tree so that the ResultSetNode has a set of columns to contain the old row value, followed by a set of columns to contain the new row value, followed by a column to contain the RowLocation of the row to be updated.

Overrides:
bind in class QueryTreeNode
Returns:
The bound query tree
Throws:
StandardException - Thrown on error

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

setDeferredForUpdateOfIndexColumn

protected void setDeferredForUpdateOfIndexColumn()
Updates are deferred if they update a column in the index used to scan the table being updated.


generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Code generation for update. The generated code will contain: o A static member for the (xxx)ResultSet with the RowLocations and new update values 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 when generating the (xxx)ResultSet.

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method for 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,
                                   ResultColumnList updateColumnList)
                            throws StandardException
Gets the map of all columns which must be read out of the base table. These are the columns needed to

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.

NOTE: this method is not expected to be called when all columns are being updated (i.e. updateColumnList is null).

Parameters:
dd - the data dictionary to look in
baseTable - the base table descriptor
updateColumnList - the rcl for the update. CANNOT BE NULL
Returns:
a FormatableBitSet of columns to be read out of the base table
Throws:
StandardException - Thrown on error

getChangedColumnIds

private int[] getChangedColumnIds(ResultColumnList rcl)
Construct the changedColumnIds array. Note we sort its entries by columnId.


getUpdateReadMap

public static FormatableBitSet getUpdateReadMap(TableDescriptor baseTable,
                                                ResultColumnList updateColumnList,
                                                java.util.Vector conglomVector,
                                                ConstraintDescriptorList relevantConstraints,
                                                GenericDescriptorList relevantTriggers,
                                                boolean[] needsDeferredProcessing)
                                         throws StandardException
Builds a bitmap of all columns which should be read from the Store in order to satisfy an UPDATE statement. Is passed a list of updated columns. Does the following: 1) finds all indices which overlap the updated columns 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 constraints which overlap the updated columns and adds the constrained columns to the bitmap 5) finds all triggers which overlap the updated columns. 6) if there are any triggers, marks all columns in the bitmap 7) adds the triggers to an evolving list of triggers

Parameters:
updateColumnList - a list of updated columns
conglomVector - OUT: vector of affected indices
relevantConstraints - IN/OUT. Empty list is passed in. We hang constraints on it as we go.
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 or constraint requires deferred processing
Returns:
a FormatableBitSet of columns to be read out of the base table
Throws:
StandardException - Thrown on error


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.