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

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
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
CallStatementNode, CursorNode, DMLModStatementNode

abstract class DMLStatementNode
extends StatementNode

A DMLStatementNode represents any type of DML statement: a cursor declaration, an INSERT statement, and UPDATE statement, or a DELETE statement. All DML statements have result sets, but they do different things with them. A SELECT statement sends its result set to the client, an INSERT statement inserts its result set into a table, a DELETE statement deletes from a table the rows corresponding to the rows in its result set, and an UPDATE statement updates the rows in a base table corresponding to the rows in its result set.


Field Summary
(package private)  ResultSetNode resultSet
          The result set is the rows that result from running the statement.
 
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
DMLStatementNode()
           
 
Method Summary
(package private)  void acceptChildren(Visitor v)
          Accept the visitor for all visitable children of this node.
(package private)  int activationKind()
          Returns the type of activation this class generates.
(package private)  QueryTreeNode bind(DataDictionary dataDictionary)
          Bind this DMLStatementNode.
protected  void bindExpressions()
          Bind the expressions in this DML statement.
protected  void bindExpressionsWithTables()
          Bind the expressions in the underlying ResultSets with tables.
 QueryTreeNode bindResultSetsWithTables(DataDictionary dataDictionary)
          Bind only the underlying ResultSets with tables.
protected  void bindTables(DataDictionary dataDictionary)
          Bind the tables in this DML statement.
(package private)  void generateParameterValueSet(ActivationClassBuilder acb)
          Generate the code to create the ParameterValueSet, if necessary, when constructing the activation.
(package private)  int getPrivType()
          Return default privilege needed for this node.
 ResultSetNode getResultSetNode()
          Get the ResultSetNode from this DML Statement.
 void init(java.lang.Object resultSet)
          Initializer for a DMLStatementNode
 boolean isAtomic()
          A read statement is atomic (DMLMod overrides us) if there are no work units, and no SELECT nodes, or if its SELECT nodes are all arguments to a function.
 ResultDescription makeResultDescription()
          Make a ResultDescription for use in a PreparedStatement.
 void optimizeStatement()
          Optimize a DML statement (which is the only type of statement that should need optimizing, I think).
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 
Methods inherited from class org.apache.derby.impl.sql.compile.StatementNode
bindStatement, executeSchemaName, executeStatementName, generate, getSPSName, lockTableForCompilation, needsSavepoint, statementToString, 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, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resultSet

ResultSetNode resultSet
The result set is the rows that result from running the statement. What this means for SELECT statements is fairly obvious. For a DELETE, there is one result column representing the key of the row to be deleted (most likely, the location of the row in the underlying heap). For an UPDATE, the row consists of the key of the row to be updated plus the updated columns. For an INSERT, the row consists of the new column values to be inserted, with no key (the system generates a key). The parser doesn't know anything about keys, so the columns representing the keys will be added after parsing (perhaps in the binding phase?).

Constructor Detail

DMLStatementNode

DMLStatementNode()
Method Detail

init

public void init(java.lang.Object resultSet)
Initializer for a DMLStatementNode

Overrides:
init in class QueryTreeNode
Parameters:
resultSet - A ResultSetNode for the result set of the DML statement

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 QueryTreeNode
Parameters:
depth - The depth of this node in the tree

getResultSetNode

public ResultSetNode getResultSetNode()
Get the ResultSetNode from this DML Statement. (Useful for view resolution after parsing the view definition.)

Returns:
ResultSetNode The ResultSetNode from this DMLStatementNode.

bind

QueryTreeNode bind(DataDictionary dataDictionary)
             throws StandardException
Bind this DMLStatementNode. 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.

Parameters:
dataDictionary - The DataDictionary to use to look up columns, tables, etc.
Returns:
The bound query tree
Throws:
StandardException - Thrown on error

bindResultSetsWithTables

public QueryTreeNode bindResultSetsWithTables(DataDictionary dataDictionary)
                                       throws StandardException
Bind only the underlying ResultSets with tables. This is necessary for INSERT, where the binding order depends on the underlying ResultSets. 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.

Parameters:
dataDictionary - The DataDictionary to use to look up columns, tables, etc.
Returns:
The bound query tree
Throws:
StandardException - Thrown on error

bindTables

protected void bindTables(DataDictionary dataDictionary)
                   throws StandardException
Bind the tables in this DML statement.

Parameters:
dataDictionary - The data dictionary to use to look up the tables
Throws:
StandardException - Thrown on error

bindExpressions

protected void bindExpressions()
                        throws StandardException
Bind the expressions in this DML statement.

Throws:
StandardException - Thrown on error

bindExpressionsWithTables

protected void bindExpressionsWithTables()
                                  throws StandardException
Bind the expressions in the underlying ResultSets with tables.

Throws:
StandardException - Thrown on error

activationKind

int activationKind()
Returns the type of activation this class generates.

Specified by:
activationKind in class StatementNode
Returns:
either (NEED_ROW_ACTIVATION | NEED_PARAM_ACTIVATION) or (NEED_ROW_ACTIVATION) depending on params

optimizeStatement

public void optimizeStatement()
                       throws StandardException
Optimize a DML statement (which is the only type of statement that should need optimizing, I think). This method over-rides the one in QueryTreeNode. This method takes a bound tree, and returns an optimized tree. It annotates the bound tree rather than creating an entirely new tree. Throws an exception if the tree is not bound, or if the binding is out of date.

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

makeResultDescription

public ResultDescription makeResultDescription()
Make a ResultDescription for use in a PreparedStatement. ResultDescriptions are visible to JDBC only for cursor statements. For other types of statements, they are only used internally to get descriptions of the base tables being affected. For example, for an INSERT statement, the ResultDescription describes the rows in the table being inserted into, which is useful when the values being inserted are of a different type or length than the columns in the base table.

Overrides:
makeResultDescription in class StatementNode
Returns:
A ResultDescription for this DML statement

generateParameterValueSet

void generateParameterValueSet(ActivationClassBuilder acb)
                         throws StandardException
Generate the code to create the ParameterValueSet, if necessary, when constructing the activation. Also generate the code to call a method that will throw an exception if we try to execute without all the parameters being set.

Parameters:
acb - The ActivationClassBuilder for the class we're building
Throws:
StandardException

isAtomic

public boolean isAtomic()
                 throws StandardException
A read statement is atomic (DMLMod overrides us) if there are no work units, and no SELECT nodes, or if its SELECT nodes are all arguments to a function. This is admittedly a bit simplistic, what if someone has:
        VALUES myfunc(SELECT max(c.commitFunc()) FROM T) 
 
but we aren't going too far out of our way to catch every possible wierd case. We basically want to be permissive w/o allowing someone to partially commit a write.

Overrides:
isAtomic in class StatementNode
Returns:
true if the statement is atomic
Throws:
StandardException - on error

acceptChildren

void acceptChildren(Visitor v)
              throws StandardException
Accept the visitor for all visitable children of this node.

Overrides:
acceptChildren in class QueryTreeNode
Parameters:
v - the visitor
Throws:
StandardException - on error

getPrivType

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

Returns:
true if the statement is atomic

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

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