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

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.InsertNode
All Implemented Interfaces:
Visitable

public final class InsertNode
extends DMLModStatementNode

An InsertNode is the top node in a query tree for an insert statement.

After parsing, the node contains targetTableName: the target table for the insert collist: a list of column names, if specified queryexpr: the expression being inserted, either a values clause or a select form; both of these are represented via the SelectNode, potentially with a TableOperatorNode such as UnionNode above it.

After binding, the node has had the target table's descriptor located and inserted, and the queryexpr and collist have been massaged so that they are identical to the table layout. This involves adding any default values for missing columns, and reordering the columns to match the table's ordering of them.

After optimizing, ...


Field Summary
protected  RowLocation[] autoincRowLocation
           
protected  boolean bulkInsert
           
private  boolean bulkInsertReplace
           
 ValueNode checkConstraints
           
 boolean deferred
           
 FKInfo fkInfo
           
 ResultColumnList targetColumnList
           
 java.util.Properties targetProperties
           
 
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
InsertNode()
           
 
Method Summary
 QueryTreeNode bind()
          Bind this InsertNode.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Code generation for insert creates an expression for: ResultSetFactory.getInsertResultSet(resultSet.generate(ps), this )
private  void getAffectedIndexes(TableDescriptor td)
          Get the list of indexes on the table being inserted into.
 boolean[] getIndexedCols()
          Create a boolean[] to track the (0-based) columns which are indexed.
protected  int getStatementType()
          Return the type of statement, something from StatementType.
(package private) static int getStatementType(java.util.Properties targetProperties)
          Return the statement type, where it is dependent on the targetProperties.
 void init(java.lang.Object targetName, java.lang.Object insertColumns, java.lang.Object queryExpression, java.lang.Object targetProperties)
          Initializer for an InsertNode.
 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)
 java.lang.String statementToString()
           
 java.lang.String toString()
          Convert this object to a String.
private  boolean verifyBulkInsert(DataDictionary dd, java.lang.String mode)
          Do the bind time checks to see if bulkInsert is allowed on this table.
private  void verifyTargetProperties(DataDictionary dd)
          Verify that the target properties that we are interested in all hold valid values.
 
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, 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, isInstanceOf, isSessionSchema, isSessionSchema, makeTableName, needsSavepoint, nodeHeader, parseQueryText, printLabel, resolveTableToSynonym, 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

targetColumnList

public ResultColumnList targetColumnList

deferred

public boolean deferred

checkConstraints

public ValueNode checkConstraints

targetProperties

public java.util.Properties targetProperties

fkInfo

public FKInfo fkInfo

bulkInsert

protected boolean bulkInsert

bulkInsertReplace

private boolean bulkInsertReplace

autoincRowLocation

protected RowLocation[] autoincRowLocation
Constructor Detail

InsertNode

public InsertNode()
Method Detail

init

public void init(java.lang.Object targetName,
                 java.lang.Object insertColumns,
                 java.lang.Object queryExpression,
                 java.lang.Object targetProperties)
Initializer for an InsertNode.

Overrides:
init in class QueryTreeNode
Parameters:
targetName - The name of the table/VTI to insert into
insertColumns - A ResultColumnList with the names of the columns to insert into. May be null if the user did not specify the columns - in this case, the binding phase will have to figure it out.
targetProperties - The properties specified on the target 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 InsertNode. 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 insert will also massage the tree so that the collist and select column order/number are the same as the layout of the table in the store.

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

verifyTargetProperties

private void verifyTargetProperties(DataDictionary dd)
                             throws StandardException
Verify that the target properties that we are interested in all hold valid values. NOTE: Any target property which is valid but cannot be supported due to a target database, etc. will be turned off quietly.

Parameters:
dd - The DataDictionary
Returns:
Nothing.
Throws:
StandardException - Thrown on error

verifyBulkInsert

private boolean verifyBulkInsert(DataDictionary dd,
                                 java.lang.String mode)
                          throws StandardException
Do the bind time checks to see if bulkInsert is allowed on this table. bulkInsert is disallowed at bind time for: o target databases o (tables with triggers?) (It is disallowed at execution time if the table has at least 1 row in it or if it is a deferred mode insert.)

Parameters:
dd - The DataDictionary
mode - The insert mode
Returns:
Whether or not bulkInsert is allowed.
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

getIndexedCols

public boolean[] getIndexedCols()
                         throws StandardException
Create a boolean[] to track the (0-based) columns which are indexed.

Returns:
A boolean[] to track the (0-based) columns which are indexed.
Throws:
StandardException - Thrown on failure

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Code generation for insert creates an expression for: ResultSetFactory.getInsertResultSet(resultSet.generate(ps), this )

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - the method for the execute() method to be built
Returns:
A compiled Expression returning an InsertResultSet
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

getStatementType

static final int getStatementType(java.util.Properties targetProperties)
Return the statement type, where it is dependent on the targetProperties. (insertMode = replace causes statement type to be BULK_INSERT_REPLACE.

Returns:
the type of statement

getAffectedIndexes

private void getAffectedIndexes(TableDescriptor td)
                         throws StandardException
Get the list of indexes on the table being inserted into. This is used by INSERT. This is an optimized version of what UPDATE and DELETE use.

Parameters:
td - TableDescriptor for the table being inserted into or deleted from
Returns:
Nothing
Throws:
StandardException - Thrown on error

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

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