Class MethodCallNode
java.lang.Object
org.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.JavaValueNode
org.apache.derby.impl.sql.compile.MethodCallNode
- All Implemented Interfaces:
Visitable
- Direct Known Subclasses:
NewInvocationNode
,NonStaticMethodCallNode
,StaticMethodCallNode
A MethodCallNode represents a Java method call. Method calls can be done
through DML (as expressions) or through the CALL statement.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
(package private) boolean
True if this is an internal call, just used to set up a generated method call.(package private) String
The name of the class containing the method.protected Member
(package private) String
(package private) String[]
The parameter types for the resolved method.protected JavaValueNode[]
private String[]
For resolution of procedure INOUT/OUT parameters to the primitive form, such as int[].(package private) RoutineAliasInfo
For a procedure or function callprotected JSQLType[]
Fields inherited from class org.apache.derby.impl.sql.compile.JavaValueNode
forCallStatement, jsqlType
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
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
Accept the visitor for all visitable children of this node.(package private) void
Add the parameter listprotected boolean
Return whether or not all of the parameters to this node are QUERY_INVARIANT or CONSTANT.(package private) final void
bindParameters
(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) Bind this expression.(package private) boolean
categorize
(JBitSet referencedTabs, boolean simplePredsOnly) Categorize this predicate.private void
generateAndCastOneParameter
(ExpressionClassBuilder acb, MethodBuilder mb, int param, String parameterType) Generate and cast one parameter, pushing the result onto the stack.(package private) void
generateOneParameter
(ExpressionClassBuilder acb, MethodBuilder mb, int parameterNumber) Generate one parameter to the given method call.int
Generate the parameters to the given method callprivate void
Generate the trailing routine arguments into a varargs array and push that array onto the stack.(package private) void
getCorrelationTables
(JBitSet correlationMap) Build a JBitSet of all of the tables that we are correlated with.(package private) DataTypeDescriptor
Override method in ancestor.int
Get the index of the first vararg if this is a varargs method(package private) TableName
Get the schema-qualified name of the the routine.protected boolean[]
Build an array of booleans denoting whether or not a given method parameter is a ?.(package private) String
(package private) Class<?>[]
Get the resolved Classes of our parameters(package private) JavaValueNode[]
Get the method parameters.protected String[]
Build an array of names of the argument types.(package private) static String
getObjectTypeName
(JSQLType jsqlType, TypeCompilerFactory tcf) (package private) int
Return the variant type for the underlying expression.static String
(package private) String[]
getPrimitiveSignature
(boolean castToPrimitiveAsNecessary) protected int
getRoutineArgIdx
(int invocationArgIdx) Get the offset into the routine arguments corresponding to the index of the invocation parameter.protected int
getRoutineArgIdx
(RoutineAliasInfo rai, int invocationArgIdx) Get the details on the invoked routines.private String
getVarargTypeName
(String arrayTypeName) Turn an array type name into the corresponding vararg type nameprivate int
boolean
Return true if the routine has varargsboolean
isVararg
(int parameterNumber) Return true if the parameter is a varargprivate String[]
parseValidateSignature
(String externalName, int offset, boolean hasDynamicResultSets) Parse the user supplied signature for a method and validate it, need to match the number of parameters passed in and match the valid types for the parameter.(package private) void
preprocess
(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) Preprocess an expression tree.(package private) void
printSubNodes
(int depth) Prints the sub-nodes of this object.(package private) JavaValueNode
Remap all ColumnReferences in this tree to be clones of the underlying expression.protected void
resolveMethodCall
(String javaClassName, boolean staticMethod) (package private) void
setNullParameterInfo
(String[] parmTypeNames) Set the appropriate type information for a null passed as a parameter.protected boolean
Return true if some parameters are null, false otherwise.protected String
stripOneArrayLevel
(String typeName) Strip the trailing [] from a type name(package private) void
throwNoMethodFound
(String receiverTypeName, String[] parmTypeNames, String[] primParmTypeNames) Build parameters for error message and throw the exception when there is no matching signature found.toString()
Convert this object to a String.Methods inherited from class org.apache.derby.impl.sql.compile.JavaValueNode
bindExpression, castToPrimitive, checkReliability, generate, generateExpression, generateReceiver, generateReceiver, getCollationType, getConstantValueAsObject, getJavaTypeName, getJSQLType, getPrimitiveTypeName, getReceiverExpression, isPrimitiveType, mapToTypeID, markForCallStatement, markReturnValueDiscarded, mustCastToPrimitive, returnValueDiscarded, returnValueToSQLDomain, setCollationType, setJavaTypeName, valueReturnedToSQLDomain
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, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
Field Details
-
methodName
String methodName -
javaClassName
String javaClassNameThe name of the class containing the method. May not be known until bindExpression() has been called.- See Also:
-
routineInfo
RoutineAliasInfo routineInfoFor a procedure or function call -
internalCall
boolean internalCallTrue if this is an internal call, just used to set up a generated method call. -
procedurePrimitiveArrayType
For resolution of procedure INOUT/OUT parameters to the primitive form, such as int[]. May be null. -
signature
-
methodParms
-
method
-
actualMethodReturnType
-
methodParameterTypes
String[] methodParameterTypesThe parameter types for the resolved method.
-
-
Constructor Details
-
MethodCallNode
MethodCallNode(String methodName, ContextManager cm)
-
-
Method Details
-
getMethodName
String getMethodName() -
getFullName
TableName getFullName()Get the schema-qualified name of the the routine. Is non-null only for StaticMethodCallNodes.
-
getJavaClassName
- Returns:
- the name of the class that contains the method, null if not known. It may not be known until this node has been bound.
-
getResolvedMethod
- Returns:
- get the Java method or constructor determined during the bind() phase.
-
getRoutineInfo
Get the details on the invoked routines. -
addParms
Add the parameter list- Parameters:
parameterList
- A list of the parameters- Throws:
StandardException
- Thrown on error
-
getMethodParameterClasses
Class<?>[] getMethodParameterClasses()Get the resolved Classes of our parameters- Returns:
- the Classes of our parameters
-
getCorrelationTables
Build a JBitSet of all of the tables that we are correlated with.- Parameters:
correlationMap
- The JBitSet of the tables that we are correlated with.- Throws:
StandardException
-
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 classQueryTreeNode
- Parameters:
depth
- The depth of this node in the tree
-
toString
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.- Overrides:
toString
in classQueryTreeNode
- Returns:
- This object as a String
-
bindParameters
final void bindParameters(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression.- Parameters:
fromList
- The FROM list for the query this expression is in, for binding columns.subqueryList
- The subquery list being built as we find SubqueryNodesaggregates
- The aggregate list being built as we find AggregateNodes- Throws:
StandardException
- Thrown on error
-
areParametersQueryInvariant
Return whether or not all of the parameters to this node are QUERY_INVARIANT or CONSTANT. This is useful for VTIs - a VTI is a candidate for materialization if all of its parameters are QUERY_INVARIANT or CONSTANT- Returns:
- Whether or not all of the parameters to this node are QUERY_INVARIANT or CONSTANT
- Throws:
StandardException
- thrown on error
-
throwNoMethodFound
void throwNoMethodFound(String receiverTypeName, String[] parmTypeNames, String[] primParmTypeNames) throws StandardException Build parameters for error message and throw the exception when there is no matching signature found.- Parameters:
receiverTypeName
- Type name for receiverparmTypeNames
- Type names for parameters as object typesprimParmTypeNames
- Type names for parameters as primitive types- Throws:
StandardException
- Thrown on error
-
getVarargTypeName
Turn an array type name into the corresponding vararg type name -
preprocess
void preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException Preprocess an expression tree. We do a number of transformations here (including subqueries, IN lists, LIKE and BETWEEN) plus subquery flattening. NOTE: This is done before the outer ResultSetNode is preprocessed.- Specified by:
preprocess
in classJavaValueNode
- Parameters:
numTables
- Number of tables in the DML StatementouterFromList
- FromList from outer query blockouterSubqueryList
- SubqueryList from outer query blockouterPredicateList
- PredicateList from outer query block- Throws:
StandardException
- Thrown on error- See Also:
-
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.- Specified by:
categorize
in classJavaValueNode
- Parameters:
referencedTabs
- JBitSet with bit map of referenced FromTablessimplePredsOnly
- Whether or not to consider method calls, field references and conditional nodes when building bit map- Returns:
- boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode.
- Throws:
StandardException
- Thrown on error- See Also:
-
remapColumnReferencesToExpressions
Remap all ColumnReferences in this tree to be clones of the underlying expression.- Specified by:
remapColumnReferencesToExpressions
in classJavaValueNode
- Returns:
- JavaValueNode The remapped expression tree.
- Throws:
StandardException
- Thrown on error- See Also:
-
hasVarargs
public boolean hasVarargs()Return true if the routine has varargs -
getFirstVarargIdx
public int getFirstVarargIdx()Get the index of the first vararg if this is a varargs method -
isVararg
public boolean isVararg(int parameterNumber) Return true if the parameter is a vararg -
generateParameters
public int generateParameters(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException Generate the parameters to the given method call- Parameters:
acb
- The ExpressionClassBuilder for the class we're generatingmb
- the method the expression will go into- Returns:
- Count of arguments to the method.
- Throws:
StandardException
- Thrown on error
-
generateAndCastOneParameter
private void generateAndCastOneParameter(ExpressionClassBuilder acb, MethodBuilder mb, int param, String parameterType) throws StandardException Generate and cast one parameter, pushing the result onto the stack.
- Throws:
StandardException
-
generateVarargs
Generate the trailing routine arguments into a varargs array and push that array onto the stack.
- Throws:
StandardException
-
getRoutineArgIdx
protected int getRoutineArgIdx(int invocationArgIdx) Get the offset into the routine arguments corresponding to the index of the invocation parameter. The two indexes may be different in the case of varargs methods. There may be more invocation args than declared routine args. For a varargs routine, all of the trailing invocation parameters correspond to the last argument declared by the CREATE FUNCTION/PROCEDURE statement.
-
getRoutineArgIdx
-
getParameterTypeName
- Throws:
StandardException
-
generateOneParameter
void generateOneParameter(ExpressionClassBuilder acb, MethodBuilder mb, int parameterNumber) throws StandardException Generate one parameter to the given method call. This method is overriden by RepStaticMethodCallNode.- Parameters:
acb
- The ExpressionClassBuilder for the class we're generatingmb
- the method the expression will go intoparameterNumber
- Identifies which parameter to generate. 0 based.- Throws:
StandardException
- Thrown on error
-
setNullParameterInfo
Set the appropriate type information for a null passed as a parameter. This method is called after method resolution, when a signature was successfully matched.- Parameters:
parmTypeNames
- String[] with the java type names for the parameters as declared by the method- Throws:
StandardException
- Thrown on error
-
resolveMethodCall
protected void resolveMethodCall(String javaClassName, boolean staticMethod) throws StandardException - Throws:
StandardException
-
stripOneArrayLevel
Strip the trailing [] from a type name -
parseValidateSignature
private String[] parseValidateSignature(String externalName, int offset, boolean hasDynamicResultSets) throws StandardException Parse the user supplied signature for a method and validate it, need to match the number of parameters passed in and match the valid types for the parameter.- Parameters:
offset
- Character offset of first parenhasDynamicResultSets
- Can ResultSet[] parameters be specified.- Returns:
- The valid array of types for resolution.
- Throws:
StandardException
-
someParametersAreNull
protected boolean someParametersAreNull()Return true if some parameters are null, false otherwise. -
getObjectSignature
Build an array of names of the argument types. These types are biased toward Java objects. That is, if an argument is of SQLType, then we map it to the corresponding Java synonym class (e.g., SQLINT is mapped to 'java.lang.Integer').- Returns:
- array of type names
- Throws:
StandardException
- Thrown on error
-
getIsParam
protected boolean[] getIsParam()Build an array of booleans denoting whether or not a given method parameter is a ?.- Returns:
- array of booleans denoting wheter or not a given method parameter is a ?.
-
getObjectTypeName
static String getObjectTypeName(JSQLType jsqlType, TypeCompilerFactory tcf) throws StandardException - Throws:
StandardException
-
getPrimitiveSignature
- Throws:
StandardException
-
getOrderableVariantType
Return the variant type for the underlying expression. The variant type can be: VARIANT - variant within a scan (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 classJavaValueNode
- Returns:
- The variant type for the underlying expression.
- Throws:
StandardException
-
getVariantTypeOfParams
- Throws:
StandardException
-
getDataType
Override method in ancestor.- Overrides:
getDataType
in classJavaValueNode
- Throws:
StandardException
-
getMethodParms
JavaValueNode[] getMethodParms()Get the method parameters.- Returns:
- The method parameters
-
acceptChildren
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classQueryTreeNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-