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

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.JavaValueNode
          extended by org.apache.derby.impl.sql.compile.MethodCallNode
              extended by org.apache.derby.impl.sql.compile.StaticMethodCallNode
All Implemented Interfaces:
Visitable

public class StaticMethodCallNode
extends MethodCallNode

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 dynmaic decision we compile in code to take both paths, based upon a boolean isINOUT which is dervied 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
(package private)  AliasDescriptor ad
           
private  boolean alreadyBound
           
private  int[] applicationParameterNumbers
           
private  boolean isSystemCode
           
private  LocalField[] outParamArrays
           
private  TableName procedureName
           
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.
 
Fields inherited from class org.apache.derby.impl.sql.compile.MethodCallNode
actualMethodReturnType, internalCall, javaClassName, method, methodName, methodParameterTypes, methodParms, routineInfo, signature
 
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_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
StaticMethodCallNode()
           
 
Method Summary
 JavaValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this expression.
 boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly)
          Categorize this predicate.
 void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
          Do code generation for this method call
 void generateOneParameter(ExpressionClassBuilder acb, MethodBuilder mb, int parameterNumber)
          Push extra code to generate the casts within the arrays for the parameters passed as arrays.
private  void generateSetupNestedSessionContext(ActivationClassBuilder acb, MethodBuilder mb)
          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).
(package private)  int getPrivType()
          Set default privilege of EXECUTE for this node.
 void init(java.lang.Object methodName, java.lang.Object javaClassName)
          Intializer for a NonStaticMethodCallNode
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, java.util.Vector aggregateVector, SchemaDescriptor sd)
          Resolve a routine.
 java.lang.String toString()
          Convert this object to a String.
 
Methods inherited from class org.apache.derby.impl.sql.compile.MethodCallNode
acceptChildren, addParms, areParametersQueryInvariant, bindParameters, generateParameters, getCorrelationTables, getDataType, getIsParam, getJavaClassName, getMethodName, getMethodParameterClasses, getMethodParms, getObjectSignature, getOrderableVariantType, getParameterTypeName, getPrimitiveSignature, getResolvedMethod, getRoutineInfo, init, preprocess, printSubNodes, remapColumnReferencesToExpressions, resolveMethodCall, setNullParameterInfo, someParametersAreNull, throwNoMethodFound
 
Methods inherited from class org.apache.derby.impl.sql.compile.JavaValueNode
castToPrimitive, checkReliability, generate, 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, 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, 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

procedureName

private TableName procedureName

outParamArrays

private LocalField[] outParamArrays

applicationParameterNumbers

private int[] applicationParameterNumbers

isSystemCode

private boolean isSystemCode

alreadyBound

private boolean alreadyBound

returnsNullOnNullState

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.


ad

AliasDescriptor ad
Constructor Detail

StaticMethodCallNode

public StaticMethodCallNode()
Method Detail

init

public void init(java.lang.Object methodName,
                 java.lang.Object javaClassName)
Intializer for a NonStaticMethodCallNode

Overrides:
init in class QueryTreeNode
Parameters:
methodName - The name of the method to call
javaClassName - The name of the java class that the static method belongs to.

bindExpression

public JavaValueNode bindExpression(FromList fromList,
                                    SubqueryList subqueryList,
                                    java.util.Vector aggregateVector)
                             throws StandardException
Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression.

Specified by:
bindExpression in class JavaValueNode
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:
this or an AggregateNode
Throws:
StandardException - Thrown on error
See Also:
ValueNode.bindExpression(org.apache.derby.impl.sql.compile.FromList, org.apache.derby.impl.sql.compile.SubqueryList, java.util.Vector)

permitsSQL

private boolean permitsSQL(RoutineAliasInfo rai)
Returns true if the routine permits SQL.


optimizeDomainValueConversion

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.

Throws:
StandardException

resolveRoutine

private void resolveRoutine(FromList fromList,
                            SubqueryList subqueryList,
                            java.util.Vector aggregateVector,
                            SchemaDescriptor sd)
                     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.

Parameters:
fromList -
subqueryList -
aggregateVector -
sd -
Throws:
StandardException

generateSetupNestedSessionContext

private void generateSetupNestedSessionContext(ActivationClassBuilder acb,
                                               MethodBuilder mb)
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 setupNestedSessionContext.

Parameters:
acb - activation class builder
mb - method builder
See Also:
LanguageConnectionContext.setupNestedSessionContext(org.apache.derby.iapi.sql.Activation)

generateOneParameter

public void generateOneParameter(ExpressionClassBuilder acb,
                                 MethodBuilder mb,
                                 int parameterNumber)
                          throws StandardException
Push extra code to generate the casts within the arrays for the parameters passed as arrays.

Overrides:
generateOneParameter in class MethodCallNode
Parameters:
acb - The ExpressionClassBuilder for the class we're generating
mb - the method the expression will go into
parameterNumber - Identifies which parameter to generate. 0 based.
Throws:
StandardException - Thrown on error

categorize

public boolean categorize(JBitSet referencedTabs,
                          boolean simplePredsOnly)
                   throws StandardException
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.

Overrides:
categorize in class MethodCallNode
Parameters:
referencedTabs - JBitSet with bit map of referenced FromTables
simplePredsOnly - 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:
ValueNode.categorize(org.apache.derby.iapi.util.JBitSet, boolean)

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

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
Do code generation for this method call

Specified by:
generateExpression in class JavaValueNode
Parameters:
acb - The ExpressionClassBuilder for the class we're generating
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

getPrivType

int getPrivType()
Set default privilege of EXECUTE for this node.


Built on Thu 2011-03-10 11:54:14+0000, from revision ???

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