Class CursorNode
java.lang.Object
org.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.StatementNode
org.apache.derby.impl.sql.compile.DMLStatementNode
org.apache.derby.impl.sql.compile.CursorNode
- All Implemented Interfaces:
Visitable
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
FieldsModifier and TypeFieldDescriptionprivate boolean
private ValueNode
private boolean
private boolean
private int
private String
private boolean
private ValueNode
private OrderByList
static final int
private String
private ArrayList
<TableDescriptor> List ofTableDescriptor
s for base tables whose associated indexes should be checked for stale statistics.(package private) static final int
There can only be a list of updatable columns when FOR UPDATE is specified as part of the cursor specification.(package private) static final int
private int
private FromTable
Fields inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
resultSet
Fields inherited from class org.apache.derby.impl.sql.compile.StatementNode
EMPTY_TD_LIST, 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_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
Constructor Summary
ConstructorsConstructorDescriptionCursorNode
(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 -
Method Summary
Modifier and TypeMethodDescription(package private) void
Accept the visitor for all visitable children of this node.(package private) int
Returns the type of activation this class generates.void
Bind this CursorNode.private void
bindUpdateColumns
(FromTable targetTable) Bind the update columns by their names to the target table of the cursor specification.private void
Collects table descriptors for base tables whose index statistics we want to check for staleness (or to create).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.(package private) void
generate
(ActivationClassBuilder acb, MethodBuilder mb) Do code generation for this CursorNodeGet information about this cursor.(package private) String
(package private) String
(package private) int
(package private) String
(package private) String
getXML()
boolean
Returns whether or not this Statement requires a set/clear savepoint around its execution.void
Optimize a DML statement (which is the only type of statement that should need optimizing, I think).(package private) void
printSubNodes
(int depth) Prints the sub-nodes of this object.boolean
Return true if the node references SESSION schema tables (temporary or permanent)(package private) String
toString()
Convert this object to a String.Returns a list of base tables for which the index statistics of the associated indexes should be updated.private static String
updateModeString
(int updateMode) Support routine for translating an updateMode identifier to a StringMethods inherited from class org.apache.derby.impl.sql.compile.DMLStatementNode
bind, bindExpressions, bindExpressionsWithTables, bindResultSetsWithTables, bindTables, generateParameterValueSet, getPrivType, getResultSetNode, isAtomic, makeResultDescription
Methods inherited from class org.apache.derby.impl.sql.compile.StatementNode
executeSchemaName, executeStatementName, generate, getSPSName, lockTableForCompilation
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
Field Details
-
UNSPECIFIED
static final int UNSPECIFIED- See Also:
-
READ_ONLY
public static final int READ_ONLY- See Also:
-
UPDATE
static final int UPDATE- See Also:
-
name
-
orderByList
-
offset
-
fetchFirst
-
hasJDBClimitClause
private boolean hasJDBClimitClause -
statementType
-
updateMode
private int updateMode -
needTarget
private boolean needTarget -
updatableColumns
There can only be a list of updatable columns when FOR UPDATE is specified as part of the cursor specification. -
updateTable
-
statsToUpdate
List ofTableDescriptor
s for base tables whose associated indexes should be checked for stale statistics. -
checkIndexStats
private boolean checkIndexStats -
indexOfSessionTableNamesInSavedObjects
private int indexOfSessionTableNamesInSavedObjects -
forMergeStatement
private boolean forMergeStatement
-
-
Constructor Details
-
CursorNode
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
- Type of statement (SELECT, UPDATE, INSERT)resultSet
- A ResultSetNode specifying the result set for the cursorname
- The name of the cursor, null if no nameorderByList
- The order by list for the cursor, null if no order by listoffset
- The value of aif present fetchFirst
- The value of aif present hasJDBClimitClause
- True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntaxupdateMode
- The user-specified update mode for the cursor, for example, CursorNode.READ_ONLYupdatableColumns
- 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
- True if this cursor is the driving left-join of a MERGE statementcm
- The context manager
-
-
Method Details
-
toString
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.- Overrides:
toString
in classStatementNode
- Returns:
- This object as a String
-
statementToString
String statementToString()- Specified by:
statementToString
in classStatementNode
-
updateModeString
Support routine for translating an updateMode identifier to a String- Parameters:
updateMode
- An updateMode identifier- Returns:
- A String representing the update mode.
-
printSubNodes
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 classDMLStatementNode
- Parameters:
depth
- The depth of this node in the tree
-
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.- Overrides:
bindStatement
in classStatementNode
- Throws:
StandardException
- Thrown on error
-
collectTablesWithPossiblyStaleStats
Collects table descriptors for base tables whose index statistics we want to check for staleness (or to create).- Throws:
StandardException
-
referencesSessionSchema
Return true if the node references SESSION schema tables (temporary or permanent)- Overrides:
referencesSessionSchema
in classQueryTreeNode
- Returns:
- true if references SESSION schema tables, else false
- Throws:
StandardException
- Thrown on error
-
getSessionSchemaTableNamesForCursor
- Throws:
StandardException
-
determineUpdateMode
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:
- the known update mode for the cursor.
- Throws:
StandardException
- Thrown on error
-
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.- Overrides:
optimizeStatement
in classDMLStatementNode
- Throws:
StandardException
- Thrown on error
-
activationKind
int activationKind()Returns the type of activation this class generates.- Overrides:
activationKind
in classDMLStatementNode
- Returns:
- either (NEED_CURSOR_ACTIVATION
- Throws:
StandardException
- Thrown on error
-
generate
Do code generation for this CursorNode- Overrides:
generate
in classQueryTreeNode
- Parameters:
acb
- The ActivationClassBuilder for the class being builtmb
- The method the generated code is to go into- Throws:
StandardException
- Thrown on error
-
getUpdateBaseTableName
String getUpdateBaseTableName() -
getUpdateExposedTableName
- Throws:
StandardException
-
getUpdateSchemaName
- Throws:
StandardException
-
getUpdateMode
int getUpdateMode() -
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 classStatementNode
- Returns:
- boolean Whether or not this Statement requires a set/clear savepoint
-
getCursorInfo
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 classStatementNode
- Returns:
- the cursor info
- Throws:
StandardException
- thrown if generation fails
-
bindUpdateColumns
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
-
getXML
String getXML() -
updateIndexStatisticsFor
Returns a list of base tables for which the index statistics of the associated indexes should be updated.- Overrides:
updateIndexStatisticsFor
in classStatementNode
- Returns:
- A list of table descriptors (potentially empty).
- Throws:
StandardException
- if accessing the index descriptors of a base table fails
-
acceptChildren
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classDMLStatementNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-