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

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ResultSetNode
          extended byorg.apache.derby.impl.sql.compile.FromTable
              extended byorg.apache.derby.impl.sql.compile.CurrentOfNode
All Implemented Interfaces:
Optimizable, Visitable

public final class CurrentOfNode
extends FromTable

The CurrentOf operator is used by positioned DELETE and UPDATE to get the current row and location for the target cursor. The bind() operations for positioned DELETE and UPDATE add a column to the select list under the statement for the row location accessible from this node. This node is placed in the from clause of the select generated for the delete or update operation. It acts much like a FromBaseTable, using the information about the target table of the cursor to provide information.

Author:
ames

Field Summary
private  TableName baseTableName
           
private  java.lang.String cursorName
           
private  TableName exposedTableName
           
private  ExecPreparedStatement preStmt
           
private  CostEstimate singleScanCostEstimate
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.FromTable
bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, loadFactor, maxCapacity, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategy
 
Fields inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
costEstimate, cursorTargetTable, insertSource, optimizer, referencedTableMap, resultColumns, resultSetNumber, scratchCostEstimate, statementResultSet
 
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
CurrentOfNode()
           
 
Method Summary
 void bindExpressions(FromList fromListParam)
          Bind the expressions in this ResultSetNode.
 ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam)
          Binding this FromTable means finding the prepared statement for the cursor and creating the result columns (the columns updatable on that cursor).
 CostEstimate estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering)
          Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Generation on a CurrentOfNode creates a scan on the cursor, CurrentOfResultSet.
 TableName getBaseCursorTargetTableName()
           
 java.lang.String getCursorName()
           
(package private)  ExecPreparedStatement getCursorStatement()
          Return the CursorNode associated with a positioned update/delete.
 java.lang.String getExposedName()
          Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.
 TableName getExposedTableName()
           
 ResultColumn getMatchingColumn(ColumnReference columnReference)
          Try to find a ResultColumn in the table represented by this CurrentOfNode that matches the name in the given ColumnReference.
 void init(java.lang.Object cursor, java.lang.Object tableProperties)
          Initializer for a table in a FROM list.
 ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicateList, double outerRows)
          Optimize this CurrentOfNode.
 ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList)
          Preprocess a CurrentOfNode.
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 java.lang.String toString()
          Convert this object to a String.
 int updateTargetLockMode()
          Get the lock mode for this table as the target of an update statement (a delete or update).
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
areAllColumnsProjected, assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, decrementLevel, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCostEstimate, getCurrentAccessPath, getFromTableByName, getLevel, getName, getNumColumnsReturned, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasTableNumber, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, modifyAccessPath, needsSpecialRCLBinding, nextAccessPath, optimizeIt, optimizeSubqueries, pullOptPredicates, pushExpressions, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setAllColumnsProjected, setCostEstimate, setHashKeyColumns, setLevel, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, uniqueJoin, verifyProperties
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
accept, addNewPredicate, assignResultSetNumber, bindExpressionsWithTables, bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, bindVTITables, changeAccessPath, closeMethodArgument, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, generateNormalizationResultSet, generateResultSet, genNewRCForInsert, genNormalizeResultSetNode, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getCursorTargetTable, getFinalCostEstimate, getFromList, getNewCostEstimate, getOptimizer, getReferencedTableMap, getResultColumns, getResultSetNumber, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markOrderingDependent, markStatementResultSet, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, projectResultColumns, pushOrderByList, referencesTarget, rejectParameters, rejectXMLValues, renameGeneratedResultNames, replaceDefaults, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes, subqueryReferencesTarget, verifySelectStarSubquery
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, 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, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, referencesSessionSchema, 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
 
Methods inherited from interface org.apache.derby.iapi.sql.compile.Optimizable
getDataDictionary, getReferencedTableMap, getResultSetNumber
 

Field Detail

cursorName

private java.lang.String cursorName

preStmt

private ExecPreparedStatement preStmt

exposedTableName

private TableName exposedTableName

baseTableName

private TableName baseTableName

singleScanCostEstimate

private CostEstimate singleScanCostEstimate
Constructor Detail

CurrentOfNode

public CurrentOfNode()
Method Detail

init

public void init(java.lang.Object cursor,
                 java.lang.Object tableProperties)
Description copied from class: FromTable
Initializer for a table in a FROM list.

Overrides:
init in class FromTable
Parameters:
cursor - The correlation name
tableProperties - Properties list associated with the table

estimateCost

public CostEstimate estimateCost(OptimizablePredicateList predList,
                                 ConglomerateDescriptor cd,
                                 CostEstimate outerCost,
                                 Optimizer optimizer,
                                 RowOrdering rowOrdering)
                          throws StandardException
Description copied from interface: Optimizable
Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate. It is assumed that the predicate list has already been classified. This cost estimate is just for one scan, not for the life of the query.

Specified by:
estimateCost in interface Optimizable
Overrides:
estimateCost in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.estimateCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, org.apache.derby.iapi.sql.compile.CostEstimate, org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.RowOrdering)

bindNonVTITables

public ResultSetNode bindNonVTITables(DataDictionary dataDictionary,
                                      FromList fromListParam)
                               throws StandardException
Binding this FromTable means finding the prepared statement for the cursor and creating the result columns (the columns updatable on that cursor). We expect someone else to verify that the target table of the positioned update or delete is the table under this cursor.

Overrides:
bindNonVTITables in class ResultSetNode
Parameters:
dataDictionary - The DataDictionary to use for binding
fromListParam - FromList to use/append to.
Returns:
ResultSetNode Returns this.
Throws:
StandardException - Thrown on error

bindExpressions

public void bindExpressions(FromList fromListParam)
Bind the expressions in this ResultSetNode. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.

Overrides:
bindExpressions in class ResultSetNode
Parameters:
fromListParam - FromList to use/append to.
Returns:
Nothing

getMatchingColumn

public ResultColumn getMatchingColumn(ColumnReference columnReference)
                               throws StandardException
Try to find a ResultColumn in the table represented by this CurrentOfNode that matches the name in the given ColumnReference.

Overrides:
getMatchingColumn in class ResultSetNode
Parameters:
columnReference - The columnReference whose name we're looking for in the given table.
Returns:
A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
Throws:
StandardException - Thrown on error

preprocess

public ResultSetNode preprocess(int numTables,
                                GroupByList gbl,
                                FromList fromList)
                         throws StandardException
Preprocess a CurrentOfNode. For a CurrentOfNode, this simply means allocating a referenced table map to avoid downstream NullPointerExceptions. NOTE: There are no bits set in the referenced table map.

Overrides:
preprocess in class ResultSetNode
Parameters:
numTables - The number of tables in the DML Statement
gbl - The group by list, if any
fromList - The from list, if any
Returns:
ResultSetNode at top of preprocessed tree.
Throws:
StandardException - Thrown on error

optimize

public ResultSetNode optimize(DataDictionary dataDictionary,
                              PredicateList predicateList,
                              double outerRows)
                       throws StandardException
Optimize this CurrentOfNode. Nothing to do.

Overrides:
optimize in class ResultSetNode
Parameters:
dataDictionary - The DataDictionary to use for optimization
predicateList - The PredicateList to optimize. This should be a single-table predicate with the table the same as the table in this FromTable.
outerRows - The number of outer joining rows
Returns:
ResultSetNode The top of the optimized subtree.
Throws:
StandardException - Thrown on error

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Generation on a CurrentOfNode creates a scan on the cursor, CurrentOfResultSet.

This routine will generate and return a call of the form:


                ResultSetFactory.getCurrentOfResultSet(cursorName)
           

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The execute() method to be built
Returns:
A compiled Expression that returns a ResultSet that scans the table.
Throws:
StandardException - Thrown on error

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

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 FromTable
Returns:
This object as a String

getExposedName

public java.lang.String getExposedName()
Description copied from class: FromTable
Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.

Overrides:
getExposedName in class FromTable
Returns:
The exposed name of this table.

getExposedTableName

public TableName getExposedTableName()

getBaseCursorTargetTableName

public TableName getBaseCursorTargetTableName()

getCursorName

public java.lang.String getCursorName()

getCursorStatement

ExecPreparedStatement getCursorStatement()
Return the CursorNode associated with a positioned update/delete.

Returns:
CursorNode The associated CursorNode.

updateTargetLockMode

public int updateTargetLockMode()
Get the lock mode for this table as the target of an update statement (a delete or update). This is implemented only for base tables and CurrentOfNodes.

Overrides:
updateTargetLockMode in class ResultSetNode
Returns:
The lock mode
See Also:
TransactionController

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

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