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

public Class ParameterNode

extends ValueNode
Class Inheritance
Imports
java.sql.Types, java.util.List, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, .SQLState, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.sql.compile.CompilerContext, org.apache.derby.iapi.store.access.Qualifier, org.apache.derby.iapi.types.DataTypeDescriptor, .DataValueDescriptor, .JSQLType, .TypeId

This node type represents a ? parameter.

Field Summary

Modifier and TypeField and Description
private DataValueDescriptor
private JSQLType
jsqlType

This ParameterNode may turn up as an argument to a replicated Work Unit.

private int
private int
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.

Inherited from org.apache.derby.impl.sql.compile.ValueNode:
transformed

Constructor Summary

AccessConstructor and Description
pack-priv
ParameterNode(int
The number of this parameter, (unique per query starting at 0)
parameterNumber
,
DataValueDescriptor
The default value for this parameter
defaultValue
,
ContextManager
The context manager
cm
)

Constructor for a ParameterNode.

Method Summary

Modifier and TypeMethod and Description
pack-priv ValueNode

Returns:

The new top of the expression tree.
bindExpression
(FromList
The FROM list for the query this expression is in, for binding columns.
fromList
,
SubqueryList
The subquery list being built as we find SubqueryNodes
subqueryList
,
List<AggregateNode>
The aggregate list being built as we find AggregateNodes
aggregates
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.bindExpression.

Bind this expression.

pack-priv boolean
constantExpression(PredicateList whereClause)

Overrides org.apache.derby.impl.sql.compile.ValueNode.constantExpression.

Return whether or not this expression tree represents a constant value.

pack-priv void
generateExpression(ExpressionClassBuilder
The ExpressionClassBuilder for the class being built
acb
,
MethodBuilder
The method the expression will go into
mb
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.generateExpression.

For a ParameterNode, we generate for the return value: (<java type name>) ( (BaseActivation) this.getParameter(parameterNumber) )

pack-priv static void
generateParameterValueSet(ExpressionClassBuilder
The ExpressionClassBuilder for the class we're building
acb
,
int
number of parameters for this statement
numberOfParameters
,
List<ParameterNode>
The parameter list for the statement.
parameterList
)

Generate the code to create the ParameterValueSet, if necessary, when constructing the activation.

pack-priv DataValueDescriptor

Returns:

the value, may be null
getDefaultValue
()

Get the default value for the parameter.

public JSQLType

Returns:

the JSQLType that the remote system assigned
getJSQLType
()

Get the JSQLType associated with this parameter.

protected int

Returns:

The variant type for the underlying expression.
getOrderableVariantType
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getOrderableVariantType.

Return the variant type for the underlying expression.

pack-priv int

Returns:

The parameter number
getParameterNumber
()

Get the parameter number

pack-priv TypeId
getTypeId()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getTypeId.

Get the TypeId from this ValueNode.

pack-priv boolean

Returns:

Whether or not this expression tree represents a constant expression.
isConstantExpression
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isConstantExpression.

Return whether or not this expression tree represents a constant expression.

pack-priv boolean
isEquivalent(ValueNode
the node to compare this ValueNode against.
o
)

Implements abstract org.apache.derby.impl.sql.compile.ValueNode.isEquivalent.

Tests if this node is equivalent to the specified ValueNode.

pack-priv boolean
isParameterNode()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isParameterNode.

Returns TRUE if this is a parameter node.

pack-priv boolean

Returns:

true if it is a return param
isReturnOutputParam
()

Is this as a return output parameter (e.g. ?

pack-priv boolean
requiresTypeFromContext()

Overrides org.apache.derby.impl.sql.compile.ValueNode.requiresTypeFromContext.

Returns TRUE if the type of this node will be determined from the context in which it is getting used.

pack-priv void
setDescriptors(DataTypeDescriptor[]
The array of DataTypeServices to fill in when the parameters are bound.
descriptors
)

Set the descriptor array

public void
setJSQLType(JSQLType
the JSQLType associated with this parameter
type
)

Set the JSQLType of this parameter.

pack-priv void
setOrderableVariantType(int type)

In a special circumstance, we want to consider parameters as constants.

pack-priv void
setReturnOutputParam(ValueNode valueNode)

Mark this as a return output parameter (e.g. ?

pack-priv void
setType(DataTypeDescriptor
The DataTypeServices to set for this parameter
descriptor
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.setType.

Set the DataTypeServices for this parameter

protected void
setValueToGenerate(ValueNode
The ValueNode to generate in place of this ParameterNode.
vn
)

Save the received ValueNode locally so that we can generate it (in place of "this") at generation time.

Inherited from org.apache.derby.impl.sql.compile.ValueNode:
bindExpressioncategorizechangeToCNFcheckIsBooleancheckTopPredicatesForEqualsConditionscopyFieldseliminateNotsevaluateConstantExpressionsgenEqualsFalseTreegenerategenIsNullTreegenSQLJavaSQLTreegetClonegetColumnNamegetConstantValueAsObjectgetDataValueFactorygetSchemaNamegetSourceResultColumngetTableNamegetTablesReferencedgetTransformedgetTypeCompilergetTypeServicesisBinaryEqualsOperatorNodeisBooleanFalseisBooleanTrueisCloneableisInListProbeNodeisRelationalOperatorisSameNodeKindoptimizableEqualityNodepreprocessputAndsOnTopremapColumnReferencesToExpressionsselectivitysetCollationInfosetCollationInfosetCollationUsingCompilationSchemasetCollationUsingCompilationSchemasetNullabilitysetTransformedsetTypesetTypetoStringupdatableByCursorverifyChangeToCNFverifyEliminateNotsverifyPutAndsOnTop

Field Detail

defaultValueback to summary
private DataValueDescriptor defaultValue
jsqlTypeback to summary
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.

orderableVariantTypeback to summary
private int orderableVariantType
parameterNumberback to summary
private int parameterNumber
returnOutputParameterback to summary
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()).

userParameterTypesback to summary
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.

valToGenerateback to summary
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

ParameterNodeback to summary
pack-priv ParameterNode(int parameterNumber, DataValueDescriptor defaultValue, ContextManager cm)

Constructor for a ParameterNode.

Parameters
parameterNumber:int

The number of this parameter, (unique per query starting at 0)

defaultValue:DataValueDescriptor

The default value for this parameter

cm:ContextManager

The context manager

Method Detail

bindExpressionback to summary
pack-priv ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.bindExpression.

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.

Parameters
fromList:FromList

The FROM list for the query this expression is in, for binding columns.

subqueryList:SubqueryList

The subquery list being built as we find SubqueryNodes

aggregates:List<AggregateNode>

The aggregate list being built as we find AggregateNodes

Returns:ValueNode

The new top of the expression tree.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
constantExpressionback to summary
pack-priv boolean constantExpression(PredicateList whereClause)

Overrides org.apache.derby.impl.sql.compile.ValueNode.constantExpression.

Doc from org.apache.derby.impl.sql.compile.ValueNode.constantExpression.

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.

Returns:boolean

True means this expression tree represents a constant value.

Annotations
@Override
See Also
ValueNode#constantExpression
generateExpressionback to summary
pack-priv void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.generateExpression.

For a ParameterNode, we generate for the return value: () ( (BaseActivation) this.getParameter(parameterNumber) )

Parameters
acb:ExpressionClassBuilder

The ExpressionClassBuilder for the class being built

mb:MethodBuilder

The method the expression will go into

Annotations
@Override
Exceptions
StandardException:
Thrown on error
generateParameterValueSetback to summary
pack-priv static void generateParameterValueSet(ExpressionClassBuilder acb, int numberOfParameters, List<ParameterNode> 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:ExpressionClassBuilder

The ExpressionClassBuilder for the class we're building

numberOfParameters:int

number of parameters for this statement

parameterList:List<ParameterNode>

The parameter list for the statement.

Exceptions
StandardException:
on error
getDefaultValueback to summary
pack-priv DataValueDescriptor getDefaultValue()

Get the default value for the parameter. Parameters may get default values for optimization purposes.

Returns:DataValueDescriptor

the value, may be null

getJSQLTypeback to summary
public JSQLType getJSQLType()

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

Returns:JSQLType

the JSQLType that the remote system assigned

getOrderableVariantTypeback to summary
protected int getOrderableVariantType()

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

Returns:int

The variant type for the underlying expression.

Annotations
@Override
getParameterNumberback to summary
pack-priv int getParameterNumber()

Get the parameter number

Returns:int

The parameter number

getTypeIdback to summary
pack-priv TypeId getTypeId() throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.getTypeId.

Doc from org.apache.derby.impl.sql.compile.ValueNode.getTypeId.

Get the TypeId from this ValueNode.

Returns:TypeId

The TypeId from this ValueNode. This may be null if the node isn't bound yet.

Annotations
@Override
isConstantExpressionback to summary
pack-priv boolean isConstantExpression()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isConstantExpression.

Return whether or not this expression tree represents a constant expression.

Returns:boolean

Whether or not this expression tree represents a constant expression.

Annotations
@Override
isEquivalentback to summary
pack-priv boolean isEquivalent(ValueNode o)

Implements abstract org.apache.derby.impl.sql.compile.ValueNode.isEquivalent.

Doc from org.apache.derby.impl.sql.compile.ValueNode.isEquivalent.

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:

  • The two ValueNodes must be of the same node type to be considered equivalent. e.g.: CastNode vs. CastNode - equivalent (if their args also match), ColumnReference vs CastNode - not equivalent.
  • If node P contains other ValueNode(s) and so on, those node(s) must also be of the same node type to be considered equivalent.
  • If node P takes a parameter list, then the number of arguments and its arguments for the two nodes must also match to be considered equivalent. e.g.: CAST(c1 as INTEGER) vs CAST(c1 as SMALLINT), they are not equivalent.
  • When comparing SQL NULLs in this context, they are considered to be equivalent.
  • If this does not apply or it is determined that the two nodes are not equivalent then the derived class of this method should return false; otherwise, return true.
Parameters
o:ValueNode

the node to compare this ValueNode against.

Returns:boolean

true if the two nodes are equivalent, false otherwise.

isParameterNodeback to summary
pack-priv boolean isParameterNode()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isParameterNode.

Doc from org.apache.derby.impl.sql.compile.ValueNode.isParameterNode.

Returns TRUE if this is a parameter node. We do lots of special things with Parameter Nodes.

Annotations
@Override
See Also
ValueNode#isParameterNode
isReturnOutputParamback to summary
pack-priv boolean isReturnOutputParam()

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

Returns:boolean

true if it is a return param

requiresTypeFromContextback to summary
pack-priv boolean requiresTypeFromContext()

Overrides org.apache.derby.impl.sql.compile.ValueNode.requiresTypeFromContext.

Doc from org.apache.derby.impl.sql.compile.ValueNode.requiresTypeFromContext.

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().

Returns:boolean

Whether this node's type will be determined from the context

Annotations
@Override
See Also
ValueNode#requiresTypeFromContext
setDescriptorsback to summary
pack-priv void setDescriptors(DataTypeDescriptor[] descriptors)

Set the descriptor array

Parameters
descriptors:DataTypeDescriptor[]

The array of DataTypeServices to fill in when the parameters are bound.

setJSQLTypeback to summary
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:JSQLType

the JSQLType associated with this parameter

setOrderableVariantTypeback to summary
pack-priv 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.

setReturnOutputParamback to summary
pack-priv void setReturnOutputParam(ValueNode valueNode)

Mark this as a return output parameter (e.g. ? = CALL myMethod())

setTypeback to summary
pack-priv void setType(DataTypeDescriptor descriptor) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.setType.

Set the DataTypeServices for this parameter

Parameters
descriptor:DataTypeDescriptor

The DataTypeServices to set for this parameter

Annotations
@Override
setValueToGenerateback to summary
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:ValueNode

The ValueNode to generate in place of this ParameterNode.