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

public Class CursorNode

extends DMLStatementNode
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .List, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.Visitor, org.apache.derby.iapi.sql.conn.Authorizer, org.apache.derby.iapi.sql.dictionary.DataDictionary, .TableDescriptor, org.apache.derby.impl.sql.CursorInfo, .CursorTableReference

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.

Field Summary

Modifier and TypeField and Description
private boolean
private ValueNode
private boolean
private boolean
private int
private String
private boolean
private ValueNode
private OrderByList
public static final int
private String
private ArrayList<TableDescriptor>
statsToUpdate

List of TableDescriptors for base tables whose associated indexes should be checked for stale statistics.

pack-priv static final int
private List<String>
updatableColumns

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

pack-priv static final int
private int
private FromTable
Inherited from org.apache.derby.impl.sql.compile.DMLStatementNode:
resultSet

Constructor Summary

AccessConstructor and Description
pack-priv
CursorNode(String
Type of statement (SELECT, UPDATE, INSERT)
statementType
,
ResultSetNode
A ResultSetNode specifying the result set for the cursor
resultSet
,
String
The name of the cursor, null if no name
name
,
OrderByList
The order by list for the cursor, null if no order by list
orderByList
,
ValueNode
The value of a if present
offset
,
ValueNode
The value of a if present
fetchFirst
,
boolean
True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntax
hasJDBClimitClause
,
int
The user-specified update mode for the cursor, for example, CursorNode.READ_ONLY
updateMode
,
String[]
The array 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.
updatableColumns
,
boolean
True if this cursor is the driving left-join of a MERGE statement
forMergeStatement
,
ContextManager
The context manager
cm
)

Constructor for a CursorNode

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

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

Accept the visitor for all visitable children of this node.

pack-priv int

Returns:

either (NEED_CURSOR_ACTIVATION
activationKind
()

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

Returns the type of activation this class generates.

public void
private void
bindUpdateColumns(FromTable
The underlying target table
targetTable
)

Bind the update columns by their names to the target table of the cursor specification.

private void
collectTablesWithPossiblyStaleStats()

Collects table descriptors for base tables whose index statistics we want to check for staleness (or to create).

private int

Returns:

the known update mode for the cursor.
determineUpdateMode
(DataDictionary dataDictionary)

Take a cursor and determine if it is UPDATE or READ_ONLY based on the shape of the cursor specification.

pack-priv void
generate(ActivationClassBuilder
The ActivationClassBuilder for the class being built
acb
,
MethodBuilder
The method the generated code is to go into
mb
)

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

Do code generation for this CursorNode

public Object

Returns:

the cursor info
getCursorInfo
()

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

Get information about this cursor.

protected ArrayList<String>
pack-priv String
pack-priv String
pack-priv int
pack-priv String
pack-priv String
public boolean

Returns:

boolean Whether or not this Statement requires a set/clear savepoint
needsSavepoint
()

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

Returns whether or not this Statement requires a set/clear savepoint around its execution.

public void
optimizeStatement()

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

Optimize a DML statement (which is the only type of statement that should need optimizing, I think).

pack-priv void
printSubNodes(int
The depth of this node in the tree
depth
)

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

Prints the sub-nodes of this object.

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
public String

Returns:

This object as a String
toString
()

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

Convert this object to a String.

public TableDescriptor[]

Returns:

A list of table descriptors (potentially empty).
updateIndexStatisticsFor
()

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

Returns a list of base tables for which the index statistics of the associated indexes should be updated.

private static String

Returns:

A String representing the update mode.
updateModeString
(int
An updateMode identifier
updateMode
)

Support routine for translating an updateMode identifier to a String

Inherited from org.apache.derby.impl.sql.compile.DMLStatementNode:
bindbindExpressionsbindExpressionsWithTablesbindResultSetsWithTablesbindTablesgenerateParameterValueSetgetPrivTypegetResultSetNodeisAtomicmakeResultDescription

Field Detail

checkIndexStatsback to summary
private boolean checkIndexStats
fetchFirstback to summary
private ValueNode fetchFirst
forMergeStatementback to summary
private boolean forMergeStatement
hasJDBClimitClauseback to summary
private boolean hasJDBClimitClause
indexOfSessionTableNamesInSavedObjectsback to summary
private int indexOfSessionTableNamesInSavedObjects
nameback to summary
private String name
needTargetback to summary
private boolean needTarget
offsetback to summary
private ValueNode offset
orderByListback to summary
private OrderByList orderByList
READ_ONLYback to summary
public static final int READ_ONLY
statementTypeback to summary
private String statementType
statsToUpdateback to summary
private ArrayList<TableDescriptor> statsToUpdate

List of TableDescriptors for base tables whose associated indexes should be checked for stale statistics.

UNSPECIFIEDback to summary
pack-priv static final int UNSPECIFIED
updatableColumnsback to summary
private List<String> updatableColumns

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

UPDATEback to summary
pack-priv static final int UPDATE
updateModeback to summary
private int updateMode
updateTableback to summary
private FromTable updateTable

Constructor Detail

CursorNodeback to summary
pack-priv CursorNode(String statementType, ResultSetNode resultSet, String name, OrderByList orderByList, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, int updateMode, String[] updatableColumns, boolean forMergeStatement, ContextManager cm)

Constructor for a CursorNode

Parameters
statementType:String

Type of statement (SELECT, UPDATE, INSERT)

resultSet:ResultSetNode

A ResultSetNode specifying the result set for the cursor

name:String

The name of the cursor, null if no name

orderByList:OrderByList

The order by list for the cursor, null if no order by list

offset:ValueNode

The value of a if present

fetchFirst:ValueNode

The value of a if present

hasJDBClimitClause:boolean

True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntax

updateMode:int

The user-specified update mode for the cursor, for example, CursorNode.READ_ONLY

updatableColumns:String[]

The array 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.

forMergeStatement:boolean

True if this cursor is the driving left-join of a MERGE statement

cm:ContextManager

The context manager

Method Detail

acceptChildrenback to summary
pack-priv void acceptChildren(Visitor v) throws StandardException

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

Accept the visitor for all visitable children of this node.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on error
activationKindback to summary
pack-priv int activationKind()

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

Returns the type of activation this class generates.

Returns:int

either (NEED_CURSOR_ACTIVATION

Annotations
@Override
Exceptions
StandardException:
Thrown on error
bindStatementback to summary
public void bindStatement() throws StandardException

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

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.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
bindUpdateColumnsback to summary
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:FromTable

The underlying target table

Exceptions
StandardException:
Thrown on error
collectTablesWithPossiblyStaleStatsback to summary
private void collectTablesWithPossiblyStaleStats() throws StandardException

Collects table descriptors for base tables whose index statistics we want to check for staleness (or to create).

determineUpdateModeback to summary
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:

  • if it says FOR READ ONLY
  • if it says ORDER BY
  • if its query specification is not read only. At present this is explicitly tested here, with these conditions. At some future point in time, this checking ought to be moved into the ResultSet nodes themselves. The conditions for a query spec. not to be read only include:
    • if it has a set operation such as UNION or INTERSECT, i.e. does not have a single outermost SELECT
    • if it does not have exactly 1 table in its FROM list; 0 tables would occur if we ever support a SELECT without a FROM e.g., for generating a row without an underlying table (like what we do for an INSERT of a VALUES list); >1 tables occurs when joins are in the tree.
    • if the table in its FROM list is not a base table (REMIND when views/from subqueries are added, this should be relaxed to be that the table is not updatable)
    • if it has a GROUP BY or HAVING (NOTE I am assuming that if and aggregate is detected in a SELECT w/o a GROUP BY, one has been added to show that the whole table is a group)
    • NOTE that cursors are updatable even if none of the columns in the select are updatable -- what they care about is the updatability of the columns of the target table.
Returns:int

the known update mode for the cursor.

Exceptions
StandardException:
Thrown on error
generateback to summary
pack-priv void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException

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

Do code generation for this CursorNode

Parameters
acb:ActivationClassBuilder

The ActivationClassBuilder for the class being built

mb:MethodBuilder

The method the generated code is to go into

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getCursorInfoback to summary
public Object getCursorInfo() throws StandardException

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

Get information about this cursor. For sps, this is info saved off of the original query tree (the one for the underlying query).

Returns:Object

the cursor info

Annotations
@Override
Exceptions
StandardException:
thrown if generation fails
getSessionSchemaTableNamesForCursorback to summary
protected ArrayList<String> getSessionSchemaTableNamesForCursor() throws StandardException
getUpdateBaseTableNameback to summary
pack-priv String getUpdateBaseTableName()
getUpdateExposedTableNameback to summary
pack-priv String getUpdateExposedTableName() throws StandardException
getUpdateModeback to summary
pack-priv int getUpdateMode()
getUpdateSchemaNameback to summary
pack-priv String getUpdateSchemaName() throws StandardException
getXMLback to summary
pack-priv String getXML()
needsSavepointback to summary
public boolean needsSavepoint()

Overrides org.apache.derby.impl.sql.compile.StatementNode.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

Returns:boolean

boolean Whether or not this Statement requires a set/clear savepoint

Annotations
@Override
optimizeStatementback to summary
public void optimizeStatement() throws StandardException

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

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.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
printSubNodesback to summary
pack-priv void printSubNodes(int depth)

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

Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Parameters
depth:int

The depth of this node in the tree

Annotations
@Override
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()

Implements abstract org.apache.derby.impl.sql.compile.StatementNode.statementToString.

toStringback to summary
public String toString()

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

Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Returns:String

This object as a String

Annotations
@Override
updateIndexStatisticsForback to summary
public TableDescriptor[] updateIndexStatisticsFor() throws StandardException

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

Returns a list of base tables for which the index statistics of the associated indexes should be updated.

Returns:TableDescriptor[]

A list of table descriptors (potentially empty).

Annotations
@Override
Exceptions
StandardException:
if accessing the index descriptors of a base table fails
updateModeStringback to summary
private static String updateModeString(int updateMode)

Support routine for translating an updateMode identifier to a String

Parameters
updateMode:int

An updateMode identifier

Returns:String

A String representing the update mode.