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

pack-priv Class StaticMethodCallNode

extends MethodCallNode
Class Inheritance
Imports
java.lang.reflect.Method, .Modifier, java.sql.ParameterMetaData, java.util.List, org.apache.derby.catalog.AliasInfo, .TypeDescriptor, org.apache.derby.catalog.types.RoutineAliasInfo, 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.LocalField, .MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.CompilerContext, .Visitor, org.apache.derby.iapi.sql.conn.Authorizer, .LanguageConnectionContext, org.apache.derby.iapi.sql.dictionary.AliasDescriptor, .SchemaDescriptor, org.apache.derby.iapi.types.DataTypeDescriptor, .JSQLType, .StringDataValue, .TypeId, org.apache.derby.iapi.util.JBitSet

A StaticMethodCallNode represents a static method call from a Class (as opposed to from an Object). For a procedure the call requires that the arguments be ? parameters. The parameter is *logically* passed into the method call a number of different ways.

For a application call like CALL MYPROC(?) the logically Java method call is (in psuedo Java/SQL code) (examples with CHAR(10) parameter)
Fixed length IN parameters - com.acme.MyProcedureMethod(?)
Variable length IN parameters - com.acme.MyProcedureMethod(CAST (? AS CHAR(10))
Fixed length INOUT parameter - String[] holder = new String[] {?}; com.acme.MyProcedureMethod(holder); ? = holder[0]
Variable length INOUT parameter - String[] holder = new String[] {CAST (? AS CHAR(10)}; com.acme.MyProcedureMethod(holder); ? = CAST (holder[0] AS CHAR(10))
Fixed length OUT parameter - String[] holder = new String[1]; com.acme.MyProcedureMethod(holder); ? = holder[0]
Variable length INOUT parameter - String[] holder = new String[1]; com.acme.MyProcedureMethod(holder); ? = CAST (holder[0] AS CHAR(10))

For static method calls there is no pre-definition of an IN or INOUT parameter, so a call to CallableStatement.registerOutParameter() makes the parameter an INOUT parameter, provided: - the parameter is passed directly to the method call (no casts or expressions). - the method's parameter type is a Java array type. Since this is a dynamic decision we compile in code to take both paths, based upon a boolean is INOUT which is derived from the ParameterValueSet. Code is logically (only single parameter String[] shown here). Note, no casts can exist here. boolean isINOUT = getParameterValueSet().getParameterMode(0) == PARAMETER_IN_OUT; if (isINOUT) { String[] holder = new String[] {?}; com.acme.MyProcedureMethod(holder); ? = holder[0] } else { com.acme.MyProcedureMethod(?) }

Field Summary

Modifier and TypeField and Description
pack-priv AliasDescriptor
private boolean
private int[]
private boolean
isInsideBind

This flag is true while bindExpression() is executing.

private boolean
private LocalField[]
private TableName
private AggregateNode
private LocalField
returnsNullOnNullState

Generated boolean field to hold the indicator for if any of the parameters to a RETURNS NULL ON NULL INPUT function are NULL.

private String
routineDefiner

Authorization id of user owning schema in which routine is defined.

Inherited from org.apache.derby.impl.sql.compile.MethodCallNode:
actualMethodReturnTypeinternalCalljavaClassNamemethodmethodNamemethodParameterTypesmethodParmsroutineInfosignature

Constructor Summary

AccessConstructor and Description
pack-priv
StaticMethodCallNode(String
The name of the method to call
methodName
,
String
The name of the java class that the static method belongs to.
javaClassName
,
ContextManager
The context manager
cm
)

Constructor for a NonStaticMethodCallNode

pack-priv
StaticMethodCallNode(TableName
The name of the method to call
methodName
,
String
The name of the java class that the static method belongs to.
javaClassName
,
ContextManager
The context manager
cm
)

Constructor for a StaticMethodCallNode

Method Summary

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

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

Accept the visitor for all visitable children of this node.

pack-priv JavaValueNode

Returns:

this or an AggregateNode
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
)

Implements abstract org.apache.derby.impl.sql.compile.JavaValueNode.bindExpression.

Bind this expression.

private JavaValueNode
bindExpressionMinion(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates)

pack-priv boolean

Returns:

boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode.
categorize
(JBitSet
JBitSet with bit map of referenced FromTables
referencedTabs
,
boolean
Whether or not to consider method calls, field references and conditional nodes when building bit map
simplePredsOnly
)

Overrides org.apache.derby.impl.sql.compile.MethodCallNode.categorize.

Categorize this predicate.

private void
coerceMethodParameter(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, RoutineAliasInfo rai, int parameterCount, DataTypeDescriptor paramdtd, TypeId parameterTypeId, int parameterMode, int p)

Coerce an actual method parameter to the declared type of the corresponding routine argument.

pack-priv void
generateExpression(ExpressionClassBuilder
The ExpressionClassBuilder for the class we're generating
acb
,
MethodBuilder
The method the expression will go into
mb
)

Implements abstract org.apache.derby.impl.sql.compile.JavaValueNode.generateExpression.

Do code generation for this method call

pack-priv void
generateOneParameter(ExpressionClassBuilder
The ExpressionClassBuilder for the class we're generating
acb
,
MethodBuilder
the method the expression will go into
mb
,
int
Identifies which parameter to generate. 0 based.
parameterNumber
)

Overrides org.apache.derby.impl.sql.compile.MethodCallNode.generateOneParameter.

Push extra code to generate the casts within the arrays for the parameters passed as arrays.

private void
generatePushNestedSessionContext(ActivationClassBuilder
activation class builder
acb
,
MethodBuilder
method builder
mb
,
boolean hadDefinersRights, String definer)

Add code to set up the SQL session context for a stored procedure or function which needs a nested SQL session context (only needed for those which can contain SQL).

pack-priv TableName
getFullName()

Overrides org.apache.derby.impl.sql.compile.MethodCallNode.getFullName.

Get the schema-qualified name of the the routine.

pack-priv int
getPrivType()

Set default privilege of EXECUTE for this node.

public AggregateNode
getResolvedAggregate()

Get the aggregate, if any, which this method call resolves to.

public static ValueNode
makeCast(ValueNode parameterNode, DataTypeDescriptor targetType, ContextManager cm)

Wrap a parameter in a CAST node.

private void
optimizeDomainValueConversion()

If this SQL function has parameters which are SQLToJavaValueNode over JavaToSQLValueNode and the java value node underneath is a SQL function defined with CALLED ON NULL INPUT, then we can get rid of the wrapper nodes over the java value node for such parameters.

private boolean
permitsSQL(RoutineAliasInfo rai)

Returns true if the routine permits SQL.

private void
resolveRoutine(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, SchemaDescriptor sd, boolean noSchema)

Resolve a routine.

public void
setAppearsInGroupBy()

Flag that this function invocation appears in a GROUP BY clause

public String

Returns:

This object as a String
toString
()

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

Convert this object to a String.

Inherited from org.apache.derby.impl.sql.compile.MethodCallNode:
addParmsareParametersQueryInvariantbindParametersgenerateParametersgetCorrelationTablesgetDataTypegetFirstVarargIdxgetIsParamgetJavaClassNamegetMethodNamegetMethodParameterClassesgetMethodParmsgetObjectSignaturegetObjectTypeNamegetOrderableVariantTypegetParameterTypeNamegetPrimitiveSignaturegetResolvedMethodgetRoutineArgIdxgetRoutineArgIdxgetRoutineInfohasVarargsisVarargpreprocessprintSubNodesremapColumnReferencesToExpressionsresolveMethodCallsetNullParameterInfosomeParametersAreNullstripOneArrayLevelthrowNoMethodFound

Field Detail

appearsInGroupByback to summary
private boolean appearsInGroupBy
applicationParameterNumbersback to summary
private int[] applicationParameterNumbers
isInsideBindback to summary
private boolean isInsideBind

This flag is true while bindExpression() is executing. It is used to avoid infinite recursion when bindExpression() is reentered.

isSystemCodeback to summary
private boolean isSystemCode
outParamArraysback to summary
private LocalField[] outParamArrays
procedureNameback to summary
private TableName procedureName
resolvedAggregateback to summary
private AggregateNode resolvedAggregate
returnsNullOnNullStateback to summary
private LocalField returnsNullOnNullState

Generated boolean field to hold the indicator for if any of the parameters to a RETURNS NULL ON NULL INPUT function are NULL. Only set if this node is calling such a function. Set at generation time.

routineDefinerback to summary
private String routineDefiner

Authorization id of user owning schema in which routine is defined.

Constructor Detail

StaticMethodCallNodeback to summary
pack-priv StaticMethodCallNode(String methodName, String javaClassName, ContextManager cm)

Constructor for a NonStaticMethodCallNode

Parameters
methodName:String

The name of the method to call

javaClassName:String

The name of the java class that the static method belongs to.

cm:ContextManager

The context manager

StaticMethodCallNodeback to summary
pack-priv StaticMethodCallNode(TableName methodName, String javaClassName, ContextManager cm)

Constructor for a StaticMethodCallNode

Parameters
methodName:TableName

The name of the method to call

javaClassName:String

The name of the java class that the static method belongs to.

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.MethodCallNode.acceptChildren.

Doc from org.apache.derby.impl.sql.compile.MethodCallNode.acceptChildren.

Accept the visitor for all visitable children of this node.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on error
bindExpressionback to summary
pack-priv JavaValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException

Implements abstract org.apache.derby.impl.sql.compile.JavaValueNode.bindExpression.

Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression.

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:JavaValueNode

this or an AggregateNode

Exceptions
StandardException:
Thrown on error
bindExpressionMinionback to summary
private JavaValueNode bindExpressionMinion(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException
categorizeback to summary
pack-priv boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) throws StandardException

Overrides org.apache.derby.impl.sql.compile.MethodCallNode.categorize.

Categorize this predicate. Initially, this means building a bit map of the referenced tables for each predicate. If the source of this ColumnReference (at the next underlying level) is not a ColumnReference or a VirtualColumnNode then this predicate will not be pushed down. For example, in: select * from (select 1 from s) a (x) where x = 1 we will not push down x = 1.

Note

It would be easy to handle the case of a constant, but if the inner SELECT returns an arbitrary expression, then we would have to copy that tree into the pushed predicate, and that tree could contain subqueries and method calls. RESOLVE - revisit this issue once we have views.

Parameters
referencedTabs:JBitSet

JBitSet with bit map of referenced FromTables

simplePredsOnly:boolean

Whether or not to consider method calls, field references and conditional nodes when building bit map

Returns:boolean

boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
coerceMethodParameterback to summary
private void coerceMethodParameter(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, RoutineAliasInfo rai, int parameterCount, DataTypeDescriptor paramdtd, TypeId parameterTypeId, int parameterMode, int p) throws StandardException

Coerce an actual method parameter to the declared type of the corresponding routine argument.

generateExpressionback to summary
pack-priv void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException

Implements abstract org.apache.derby.impl.sql.compile.JavaValueNode.generateExpression.

Do code generation for this method call

Parameters
acb:ExpressionClassBuilder

The ExpressionClassBuilder for the class we're generating

mb:MethodBuilder

The method the expression will go into

Exceptions
StandardException:
Thrown on error
generateOneParameterback to summary
pack-priv void generateOneParameter(ExpressionClassBuilder acb, MethodBuilder mb, int parameterNumber) throws StandardException

Overrides org.apache.derby.impl.sql.compile.MethodCallNode.generateOneParameter.

Push extra code to generate the casts within the arrays for the parameters passed as arrays.

Parameters
acb:ExpressionClassBuilder

Doc from org.apache.derby.impl.sql.compile.MethodCallNode.generateOneParameter.

The ExpressionClassBuilder for the class we're generating

mb:MethodBuilder

Doc from org.apache.derby.impl.sql.compile.MethodCallNode.generateOneParameter.

the method the expression will go into

parameterNumber:int

Doc from org.apache.derby.impl.sql.compile.MethodCallNode.generateOneParameter.

Identifies which parameter to generate. 0 based.

Annotations
@Override
Exceptions
StandardException:

Doc from org.apache.derby.impl.sql.compile.MethodCallNode.generateOneParameter.

Thrown on error

generatePushNestedSessionContextback to summary
private void generatePushNestedSessionContext(ActivationClassBuilder acb, MethodBuilder mb, boolean hadDefinersRights, String definer) throws StandardException

Add code to set up the SQL session context for a stored procedure or function which needs a nested SQL session context (only needed for those which can contain SQL). The generated code calls pushNestedSessionContext.

Parameters
acb:ActivationClassBuilder

activation class builder

mb:MethodBuilder

method builder

See Also
LanguageConnectionContext#pushNestedSessionContext
getFullNameback to summary
pack-priv TableName getFullName()

Overrides org.apache.derby.impl.sql.compile.MethodCallNode.getFullName.

Doc from org.apache.derby.impl.sql.compile.MethodCallNode.getFullName.

Get the schema-qualified name of the the routine. Is non-null only for StaticMethodCallNodes.

Annotations
@Override
getPrivTypeback to summary
pack-priv int getPrivType()

Set default privilege of EXECUTE for this node.

getResolvedAggregateback to summary
public AggregateNode getResolvedAggregate()

Get the aggregate, if any, which this method call resolves to.

makeCastback to summary
public static ValueNode makeCast(ValueNode parameterNode, DataTypeDescriptor targetType, ContextManager cm) throws StandardException

Wrap a parameter in a CAST node.

optimizeDomainValueConversionback to summary
private void optimizeDomainValueConversion() throws StandardException

If this SQL function has parameters which are SQLToJavaValueNode over JavaToSQLValueNode and the java value node underneath is a SQL function defined with CALLED ON NULL INPUT, then we can get rid of the wrapper nodes over the java value node for such parameters. This is because SQL functions defined with CALLED ON NULL INPUT need access to only java domain values. This can't be done for parameters which are wrappers over SQL function defined with RETURN NULL ON NULL INPUT because such functions need access to both sql domain value and java domain value. - Derby479 This optimization is not available if the outer function is RETURN NULL ON NULL INPUT. That is because the SQLToJavaNode is responsible for compiling the byte code which skips the method call if the parameter is null--if we remove the SQLToJavaNode, then we don't compile that check and we get bug DERBY-1030.

permitsSQLback to summary
private boolean permitsSQL(RoutineAliasInfo rai)

Returns true if the routine permits SQL.

resolveRoutineback to summary
private void resolveRoutine(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, SchemaDescriptor sd, boolean noSchema) throws StandardException

Resolve a routine. Obtain a list of routines from the data dictionary of the correct type (functions or procedures) and name. Pick the best routine from the list. Currently only a single routine with a given type and name is allowed, thus if changes are made to support overloaded routines, careful code inspection and testing will be required.

setAppearsInGroupByback to summary
public void setAppearsInGroupBy()

Flag that this function invocation appears in a GROUP BY clause

toStringback to summary
public String toString()

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