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

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.ValueNode
          extended by org.apache.derby.impl.sql.compile.ParameterNode
All Implemented Interfaces:
Visitable

public class ParameterNode
extends ValueNode

This node type represents a ? parameter.


Field Summary
private  DataValueDescriptor defaultValue
           
private  JSQLType jsqlType
          This ParameterNode may turn up as an argument to a replicated Work Unit.
private  int orderableVariantType
           
private  int parameterNumber
           
private  ValueNode returnOutputParameter
          By default, we assume we are just a normal, harmless little ole parameter.
private  DataTypeDescriptor[] userParameterTypes
          Pointer to the array in the CompilerContext that holds array of types for all the user-visible paramerers..
private  ValueNode valToGenerate
          If this parameter node was created as part of a "probe predicate" for an InListOperatorNode then it does not actually correspond to a specific value--we just created it as a start-key place-holder for IN-list values at execution time.
 
Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode
transformed
 
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
ParameterNode()
          Constructor for use by the NodeFactory
 
Method Summary
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this expression.
 boolean constantExpression(PredicateList whereClause)
          Return whether or not this expression tree represents a constant value.
 void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
          For a ParameterNode, we generate for the return value: () ( (BaseActivation) this.getParameter(parameterNumber) )
static void generateParameterValueSet(ExpressionClassBuilder acb, int numberOfParameters, java.util.Vector parameterList)
          Generate the code to create the ParameterValueSet, if necessary, when constructing the activation.
(package private)  DataValueDescriptor getDefaultValue()
          Get the default value for the parameter.
 JSQLType getJSQLType()
          Get the JSQLType associated with this parameter.
protected  int getOrderableVariantType()
          Return the variant type for the underlying expression.
(package private)  int getParameterNumber()
          Get the parameter number
 TypeId getTypeId()
          Get the TypeId from this ValueNode.
 void init(java.lang.Object parameterNumber, java.lang.Object defaultValue)
          Initializer for a ParameterNode.
 boolean isConstantExpression()
          Return whether or not this expression tree represents a constant expression.
protected  boolean isEquivalent(ValueNode o)
          Tests if this node is equivalent to the specified ValueNode.
 boolean isParameterNode()
          Returns TRUE if this is a parameter node.
 boolean isReturnOutputParam()
          Is this as a return output parameter (e.g. ?
 boolean requiresTypeFromContext()
          Returns TRUE if the type of this node will be determined from the context in which it is getting used.
(package private)  void setDescriptors(DataTypeDescriptor[] descriptors)
          Set the descriptor array
 void setJSQLType(JSQLType type)
          Set the JSQLType of this parameter.
(package private)  void setOrderableVariantType(int type)
          In a special circumstance, we want to consider parameters as constants.
 void setReturnOutputParam(ValueNode valueNode)
          Mark this as a return output parameter (e.g. ?
 void setType(DataTypeDescriptor descriptor)
          Set the DataTypeServices for this parameter
protected  void setValueToGenerate(ValueNode vn)
          Save the received ValueNode locally so that we can generate it (in place of "this") at generation time.
 
Methods inherited from class org.apache.derby.impl.sql.compile.ValueNode
bindExpression, categorize, changeToCNF, checkIsBoolean, checkTopPredicatesForEqualsConditions, copyFields, eliminateNots, evaluateConstantExpressions, genEqualsFalseTree, generate, generateFilter, genIsNullTree, genSQLJavaSQLTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeServices, init, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isCloneable, isInListProbeNode, isRelationalOperator, isSameNodeType, optimizableEqualityNode, preprocess, putAndsOnTop, remapColumnReferencesToExpressions, selectivity, setCollationInfo, setCollationInfo, setCollationUsingCompilationSchema, setCollationUsingCompilationSchema, setNullability, setTransformed, setType, setType, toString, updatableByCursor, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, acceptChildren, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, foundString, 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, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, printSubNodes, 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

parameterNumber

private int parameterNumber

userParameterTypes

private DataTypeDescriptor[] userParameterTypes
Pointer to the array in the CompilerContext that holds array of types for all the user-visible paramerers.. When each parameter is bound, it fills in its type descriptor in this array. Note that the array is allocated in the parser, but the individual elements are not filled in until their corresponding parameters are bound. This array is not read in this class, but is read from the CompilerContext on completion of compiling the statement. In some case a parameter node may exist but is not a visble user parameter, in this case typeServices will be null so that setting its type will not modify the user's set.


defaultValue

private DataValueDescriptor defaultValue

jsqlType

private JSQLType jsqlType
This ParameterNode may turn up as an argument to a replicated Work Unit. If so, the remote system will have figured out the type of this node. That's what this variable is for.


orderableVariantType

private int orderableVariantType

returnOutputParameter

private ValueNode returnOutputParameter
By default, we assume we are just a normal, harmless little ole parameter. But sometimes we may be a return parameter (e.g. ? = CALL myMethod()).


valToGenerate

private ValueNode valToGenerate
If this parameter node was created as part of a "probe predicate" for an InListOperatorNode then it does not actually correspond to a specific value--we just created it as a start-key place-holder for IN-list values at execution time. In order to serve that purpose we need to generate some value that can be used as the place-holder. Since this parameter node is "fake" and does not correspond to an actual parameter, we can't really generate it; so the following field holds some legitimate ValueNode--either a constant node or a "real" parameter node--that we can generate to serve as the place-holder.

Constructor Detail

ParameterNode

public ParameterNode()
Constructor for use by the NodeFactory

Method Detail

init

public void init(java.lang.Object parameterNumber,
                 java.lang.Object defaultValue)
Initializer for a ParameterNode.

Overrides:
init in class QueryTreeNode
Parameters:
parameterNumber - The number of this parameter, (unique per query starting at 0)
defaultValue - The default value for this parameter

getParameterNumber

int getParameterNumber()
Get the parameter number

Returns:
The parameter number

setDescriptors

void setDescriptors(DataTypeDescriptor[] descriptors)
Set the descriptor array

Parameters:
descriptors - The array of DataTypeServices to fill in when the parameters are bound.

setType

public void setType(DataTypeDescriptor descriptor)
             throws StandardException
Set the DataTypeServices for this parameter

Overrides:
setType in class ValueNode
Parameters:
descriptor - The DataTypeServices to set for this parameter
Throws:
StandardException

setReturnOutputParam

public void setReturnOutputParam(ValueNode valueNode)
Mark this as a return output parameter (e.g. ? = CALL myMethod())


isReturnOutputParam

public boolean isReturnOutputParam()
Is this as a return output parameter (e.g. ? = CALL myMethod())

Returns:
true if it is a return param

bindExpression

public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                java.util.Vector aggregateVector)
                         throws StandardException
Bind this expression. A parameter can't figure out what its type is without knowing where it appears, so this method does nothing. It is up to the node that points to this parameter node to figure out the type of the parameter and set it, using the setType() method above.

Overrides:
bindExpression in class ValueNode
Parameters:
fromList - The FROM list for the query this expression is in, for binding columns.
subqueryList - The subquery list being built as we find SubqueryNodes
aggregateVector - The aggregate vector being built as we find AggregateNodes
Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

isConstantExpression

public boolean isConstantExpression()
Return whether or not this expression tree represents a constant expression.

Overrides:
isConstantExpression in class ValueNode
Returns:
Whether or not this expression tree represents a constant expression.

constantExpression

public boolean constantExpression(PredicateList whereClause)
Description copied from class: ValueNode
Return whether or not this expression tree represents a constant value. In this case, "constant" means that it will always evaluate to the same thing, even if it includes columns. A column is constant if it is compared to a constant expression.

Overrides:
constantExpression in class ValueNode
Returns:
True means this expression tree represents a constant value.
See Also:
ValueNode.constantExpression(org.apache.derby.impl.sql.compile.PredicateList)

getOrderableVariantType

protected int getOrderableVariantType()
Return the variant type for the underlying expression. The variant type can be: VARIANT - variant within a scan (method calls and non-static field access) SCAN_INVARIANT - invariant within a scan (column references from outer tables) QUERY_INVARIANT - invariant within the life of a query (constant expressions)

Overrides:
getOrderableVariantType in class ValueNode
Returns:
The variant type for the underlying expression.

setOrderableVariantType

void setOrderableVariantType(int type)
In a special circumstance, we want to consider parameters as constants. For that situation, we allow a caller to temporarily set us to CONSTANT and then restore us.


setJSQLType

public void setJSQLType(JSQLType type)
Set the JSQLType of this parameter. This supports the unnamed parameters that we use for replicated work units.

Parameters:
type - the JSQLType associated with this parameter

getJSQLType

public JSQLType getJSQLType()
Get the JSQLType associated with this parameter. Again, part of method resolution for replicated work units.

Returns:
the JSQLType that the remote system assigned

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
For a ParameterNode, we generate for the return value: () ( (BaseActivation) this.getParameter(parameterNumber) )

Overrides:
generateExpression in class ValueNode
Parameters:
acb - The ExpressionClassBuilder for the class being built
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

getTypeId

public TypeId getTypeId()
                 throws StandardException
Description copied from class: ValueNode
Get the TypeId from this ValueNode.

Overrides:
getTypeId in class ValueNode
Returns:
The TypeId from this ValueNode. This may be null if the node isn't bound yet.
Throws:
StandardException

generateParameterValueSet

public static void generateParameterValueSet(ExpressionClassBuilder acb,
                                             int numberOfParameters,
                                             java.util.Vector parameterList)
                                      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. This generated code goes into the Activation's constructor early on.

Parameters:
acb - The ExpressionClassBuilder for the class we're building
numberOfParameters - number of parameters for this statement
parameterList - The parameter list for the statement.
Throws:
StandardException - on error

getDefaultValue

DataValueDescriptor getDefaultValue()
Get the default value for the parameter. Parameters may get default values for optimization purposes.

Returns:
the value, may be null

requiresTypeFromContext

public boolean requiresTypeFromContext()
Description copied from class: ValueNode
Returns TRUE if the type of this node will be determined from the context in which it is getting used. If true is returned then after bindExpression() is called on the node, its type must be set (from the relevant context) using setType().

Overrides:
requiresTypeFromContext in class ValueNode
Returns:
Whether this node's type will be determined from the context
See Also:
ValueNode.requiresTypeFromContext()

isParameterNode

public boolean isParameterNode()
Description copied from class: ValueNode
Returns TRUE if this is a parameter node. We do lots of special things with Parameter Nodes.

Overrides:
isParameterNode in class ValueNode
See Also:
ValueNode.isParameterNode()

isEquivalent

protected boolean isEquivalent(ValueNode o)
Description copied from class: ValueNode
Tests if this node is equivalent to the specified ValueNode. Two ValueNodes are considered equivalent if they will evaluate to the same value during query execution.

This method provides basic expression matching facility for the derived class of ValueNode and it is used by the language layer to compare the node structural form of the two expressions for equivalence at bind phase.

Note that it is not comparing the actual row values at runtime to produce a result; hence, when comparing SQL NULLs, they are considered to be equivalent and not unknown.

One usage case of this method in this context is to compare the select column expression against the group by expression to check if they are equivalent. e.g.:

SELECT c1+c2 FROM t1 GROUP BY c1+c2

In general, node equivalence is determined by the derived class of ValueNode. But they generally abide to the rules below:

Specified by:
isEquivalent in class ValueNode
Parameters:
o - the node to compare this ValueNode against.
Returns:
true if the two nodes are equivalent, false otherwise.

setValueToGenerate

protected void setValueToGenerate(ValueNode vn)
Save the received ValueNode locally so that we can generate it (in place of "this") at generation time. See the preprocess() method of InListOperatorNode for more on how this is used.

Parameters:
vn - The ValueNode to generate in place of this ParameterNode.

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

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