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

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.ReadCursorNode
                  extended byorg.apache.derby.impl.sql.compile.CursorNode
All Implemented Interfaces:
Visitable

public class CursorNode
extends ReadCursorNode

A CursorNode represents a result set that can be returned to a client. A cursor can be a named cursor created by the DECLARE CURSOR statement, or it can be an unnamed cursor associated with a SELECT statement (more precisely, a table expression that returns rows to the client). In the latter case, the cursor does not have a name.

Author:
Jeff Lichtman

Field Summary
protected  int indexOfSessionTableNamesInSavedObjects
           
private  java.lang.String name
           
private  boolean needTarget
           
private  OrderByList orderByList
           
static int READ_ONLY
           
private  java.lang.String statementType
           
private  ResultColumnDescriptor[] targetColumnDescriptors
           
private  ResultColumnList targetColumns
           
static int UNSPECIFIED
           
private  java.util.Vector updatableColumns
          There can only be a list of updatable columns when FOR UPDATE is specified as part of the cursor specification.
static int UPDATE
           
private  int updateMode
           
private  FromTable updateTable
           
 
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
CursorNode()
           
 
Method Summary
(package private)  int activationKind()
          Returns the type of activation this class generates.
 QueryTreeNode bind()
          Bind this CursorNode.
 QueryTreeNode bind(DataDictionary dataDictionary)
          Bind this ReadCursorNode.
private  void bindUpdateColumns(FromTable targetTable)
          Bind the update columns by their names to the target table of the cursor specification.
private  int determineUpdateMode(DataDictionary dataDictionary)
          Take a cursor and determine if it is UPDATE or READ_ONLY based on the shape of the cursor specification.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Do code generation for this CursorNode
 ResultColumnDescriptor[] genTargetResultColList()
          Positioned update needs to know what the target result set looks like.
 java.lang.Object getCursorInfo()
          Get information about this cursor.
protected  java.util.ArrayList getSessionSchemaTableNamesForCursor()
           
private  java.lang.String[] getUpdatableColumns()
          Return String[] of names from the FOR UPDATE OF List
 java.lang.String getUpdateBaseTableName()
           
private  java.lang.String[] getUpdateColumnNames()
          Get an array of strings for each updatable column in this list.
 java.lang.String getUpdateExposedTableName()
           
 int getUpdateMode()
           
 java.lang.String getUpdateSchemaName()
           
 void init(java.lang.Object statementType, java.lang.Object resultSet, java.lang.Object name, java.lang.Object orderByList, java.lang.Object updateMode, java.lang.Object updatableColumns)
          Initializer for a CursorNode
 boolean needsSavepoint()
          Returns whether or not this Statement requires a set/clear savepoint around its execution.
 QueryTreeNode optimize()
          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.
 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 static java.lang.String updateModeString(int updateMode)
          Support routine for translating an updateMode identifier to a String
 
Methods inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
accept, bindExpressions, bindExpressionsWithTables, bindResultSetsWithTables, bindTables, generateParameterHolders, generateParameterValueSet, getResultSetNode, init, isAtomic, 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, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, nodeHeader, parseQueryText, printLabel, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNSPECIFIED

public static final int UNSPECIFIED
See Also:
Constant Field Values

READ_ONLY

public static final int READ_ONLY
See Also:
Constant Field Values

UPDATE

public static final int UPDATE
See Also:
Constant Field Values

name

private java.lang.String name

orderByList

private OrderByList orderByList

statementType

private java.lang.String statementType

updateMode

private int updateMode

needTarget

private boolean needTarget

updatableColumns

private java.util.Vector updatableColumns
There can only be a list of updatable columns when FOR UPDATE is specified as part of the cursor specification.


updateTable

private FromTable updateTable

targetColumns

private ResultColumnList targetColumns

targetColumnDescriptors

private ResultColumnDescriptor[] targetColumnDescriptors

indexOfSessionTableNamesInSavedObjects

protected int indexOfSessionTableNamesInSavedObjects
Constructor Detail

CursorNode

public CursorNode()
Method Detail

init

public void init(java.lang.Object statementType,
                 java.lang.Object resultSet,
                 java.lang.Object name,
                 java.lang.Object orderByList,
                 java.lang.Object updateMode,
                 java.lang.Object updatableColumns)
Initializer for a CursorNode

Overrides:
init in class QueryTreeNode
Parameters:
statementType - Type of statement (SELECT, UPDATE, INSERT)
resultSet - A ResultSetNode specifying the result set for the cursor
name - The name of the cursor, null if no name
orderByList - The order by list for the cursor, null if no order by list
updateMode - The user-specified update mode for the cursor, for example, CursorNode.READ_ONLY
updatableColumns - The list of updatable columns specified by the user in the FOR UPDATE clause, null if no updatable columns specified. May only be provided if the updateMode parameter is CursorNode.UPDATE.

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 ReadCursorNode

updateModeString

private static java.lang.String updateModeString(int updateMode)
Support routine for translating an updateMode identifier to a String

Parameters:
updateMode - An updateMode identifier
Returns:
A String representing the update mode.

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 CursorNode. 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. It also includes determining whether an UNSPECIFIED cursor is updatable or not, and verifying that an UPDATE cursor actually is.

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

getSessionSchemaTableNamesForCursor

protected java.util.ArrayList getSessionSchemaTableNamesForCursor()
                                                           throws StandardException
Throws:
StandardException

determineUpdateMode

private int determineUpdateMode(DataDictionary dataDictionary)
                         throws StandardException
Take a cursor and determine if it is UPDATE or READ_ONLY based on the shape of the cursor specification.

The following conditions make a cursor read only:

Returns:
the known update mode for the cursor.
Throws:
StandardException - Thrown on error

optimize

public QueryTreeNode optimize()
                       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:
optimize in class DMLStatementNode
Returns:
An optimized QueryTree
Throws:
StandardException - Thrown on error

activationKind

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

Overrides:
activationKind in class DMLStatementNode
Returns:
either (NEED_CURSOR_ACTIVATION
Throws:
StandardException - Thrown on error

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Do code generation for this CursorNode

Overrides:
generate in class ReadCursorNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method the generated code is to go into
Throws:
StandardException - Thrown on error

getUpdateBaseTableName

public java.lang.String getUpdateBaseTableName()

getUpdateExposedTableName

public java.lang.String getUpdateExposedTableName()
                                           throws StandardException
Throws:
StandardException

getUpdateSchemaName

public java.lang.String getUpdateSchemaName()
                                     throws StandardException
Throws:
StandardException

getUpdateMode

public int getUpdateMode()

getUpdatableColumns

private java.lang.String[] getUpdatableColumns()
Return String[] of names from the FOR UPDATE OF List

Returns:
String[] of names from the FOR UPDATE OF list.

genTargetResultColList

public ResultColumnDescriptor[] genTargetResultColList()
                                                throws StandardException
Positioned update needs to know what the target result set looks like. This is generated from the UpdateColumnList available for the cursor, to describe the rows coming from the target result set under the cursor. This result set contains a superset of the updatable columns; the caller must verify that only those listed in the FOR UPDATE clause are used.

Returns:
a result column list containing a description of the target table (this may contain non-updatable columns).
Throws:
StandardException - Thrown on error

needsSavepoint

public boolean needsSavepoint()
Returns whether or not this Statement requires a set/clear savepoint around its execution. The following statement "types" do not require them: Cursor - unnecessary and won't work in a read only environment Xact - savepoint will get blown away underneath us during commit/rollback

Overrides:
needsSavepoint in class QueryTreeNode
Returns:
boolean Whether or not this Statement requires a set/clear savepoint

getCursorInfo

public java.lang.Object getCursorInfo()
                               throws StandardException
Get information about this cursor. For sps, this is info saved off of the original query tree (the one for the underlying query).

Overrides:
getCursorInfo in class QueryTreeNode
Returns:
the cursor info
Throws:
StandardException - thrown if generation fails

bindUpdateColumns

private void bindUpdateColumns(FromTable targetTable)
                        throws StandardException
Bind the update columns by their names to the target table of the cursor specification. Doesn't check for duplicates in the list, although it could... REVISIT: If the list is empty, should it expand it out? at present, it leaves it empty.

Parameters:
targetTable - The underlying target table
Throws:
StandardException - Thrown on error

getUpdateColumnNames

private java.lang.String[] getUpdateColumnNames()
Get an array of strings for each updatable column in this list.

Returns:
an array of strings

bind

public QueryTreeNode bind(DataDictionary dataDictionary)
                   throws StandardException
Bind this ReadCursorNode. This means looking up tables and columns and getting their types, and figuring out the result types of all expressions.

Overrides:
bind in class DMLStatementNode
Parameters:
dataDictionary - Namespace to bind against.
Returns:
The bound query tree
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.