📄 methodcallnode.java
字号:
/* Derby - Class org.apache.derby.impl.sql.compile.MethodCallNode Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.sql.compile;import org.apache.derby.iapi.services.loader.ClassInspector;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.types.JSQLType;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.compile.Visitable;import org.apache.derby.iapi.sql.compile.Visitor;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.sql.compile.TypeCompiler;import org.apache.derby.catalog.TypeDescriptor;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.JDBC30Translation;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.catalog.types.RoutineAliasInfo;import java.lang.reflect.Modifier;import java.lang.reflect.Member;import java.util.StringTokenizer;import java.util.Vector;/** * A MethodCallNode represents a Java method call. Method calls can be done * through DML (as expressions) or through the CALL statement. * * @author Jeff Lichtman */public abstract class MethodCallNode extends JavaValueNode{ /* ** Name of the method. */ protected String methodName; /** The name of the class containing the method. May not be known until bindExpression() has been called. * @see #bindExpression * @see #getJavaClassName() */ protected String javaClassName; /** For a procedure or function call */ RoutineAliasInfo routineInfo; /** True if this is an internal call, just used to set up a generated method call. */ boolean internalCall; /** For resolution of procedure INOUT/OUT parameters to the primitive form, such as int[]. May be null. */ private String[] procedurePrimitiveArrayType; // bound signature of arguments, stated in universal types (JSQLType) protected JSQLType[] signature; /* ** Parameters to the method, if any. No elements if no parameters. */ protected JavaValueNode[] methodParms; /* The method call */ protected Member method; protected String actualMethodReturnType; /** * Gets the signature of JSQLTypes needed to propagate a work unit from * target to source. * * @return the JSQLType signature */ public JSQLType[] getSignature() { return signature; } /** The parameter types for the resolved method. */ String[] methodParameterTypes; /** * Initializer for a MethodCallNode * * @param methodName The name of the method to call */ public void init(Object methodName) { this.methodName = (String) methodName; } public String getMethodName() { return methodName; } /** * @return the name of the class that contains the method, null if not known. It may not be known * until this node has been bound. */ public String getJavaClassName() { return javaClassName; } /** * Set the clause that this node appears in. * * @param clause The clause that this node appears in. * * @return Nothing. */ public void setClause(int clause) { super.setClause(clause); if (methodParms != null) { for (int parm = 0; parm < methodParms.length; parm++) { if (methodParms[parm] != null) { methodParms[parm].setClause(clause); } } } } /** * Add the parameter list. * (This flavor is useful when transforming a non-static method call node * to a static method call node.) * * @param methodParms JavaValueNode[] * * @return Nothing */ public void addParms(JavaValueNode[] methodParms) { this.methodParms = methodParms; } /** * Add the parameter list * * @param parameterList A Vector of the parameters * * @return Nothing * * @exception StandardException Thrown on error */ public void addParms(Vector parameterList) throws StandardException { methodParms = new JavaValueNode[parameterList.size()]; int plSize = parameterList.size(); for (int index = 0; index < plSize; index++) { QueryTreeNode qt; qt = (QueryTreeNode) parameterList.elementAt(index); /* ** If the parameter is a SQL ValueNode, there are two ** possibilities. Either it is a JavaValueNode with ** a JavaToSQLValueNode on top of it, or it is a plain ** SQL ValueNode. In the former case, just get rid of ** the JavaToSQLValueNode. In the latter case, put a ** SQLToJavaValueNode on top of it. In general, we ** want to avoid converting the same value back and forth ** between the SQL and Java domains. */ if ( ! (qt instanceof JavaValueNode)) { if (qt instanceof JavaToSQLValueNode) { qt = ((JavaToSQLValueNode) qt).getJavaValueNode(); } else { qt = (SQLToJavaValueNode) getNodeFactory(). getNode( C_NodeTypes.SQL_TO_JAVA_VALUE_NODE, qt, getContextManager()); } } methodParms[index] = (JavaValueNode) qt; } } /** * Prints the sub-nodes of this object. See QueryTreeNode.java for * how tree printing is supposed to work. * * @param depth The depth of this node in the tree * * @return Nothing */ public void printSubNodes(int depth) { if (SanityManager.DEBUG) { int parm; super.printSubNodes(depth); if (methodParms != null) { for (parm = 0; parm < methodParms.length; parm++) { if (methodParms[parm] != null) { printLabel(depth, "methodParms[" + parm + "] :"); methodParms[parm].treePrint(depth + 1); } } } } } /** * Convert this object to a String. See comments in QueryTreeNode.java * for how this should be done for tree printing. * * @return This object as a String */ public String toString() { if (SanityManager.DEBUG) { return "methodName: " + (methodName != null ? methodName : "null") + "\n" + super.toString(); } else { return ""; } } /** * Bind this expression. This means binding the sub-expressions, * as well as figuring out what the return type is for this expression. * * @param fromList The FROM list for the query this * expression is in, for binding columns. * @param subqueryList The subquery list being built as we find SubqueryNodes * @param aggregateVector The aggregate vector being built as we find AggregateNodes * * @return this * * @exception StandardException Thrown on error */ final void bindParameters( FromList fromList, SubqueryList subqueryList, Vector aggregateVector) throws StandardException { /* Bind the parameters */ if (methodParms != null) { int count = methodParms.length; // with a procedure call the signature // is preformed in StaticMethodCall from // the procedures signature. if (signature == null) signature = new JSQLType[ count ]; for (int parm = 0; parm < count; parm++) { if (methodParms[parm] != null) { methodParms[parm] = methodParms[parm].bindExpression( fromList, subqueryList, aggregateVector); if (routineInfo == null) signature[ parm ] = methodParms[ parm ].getJSQLType(); // prohibit LOB columns/types if (signature[parm] != null) { String type = signature[parm].getSQLType().getTypeId().getSQLTypeName(); if (type.equals("BLOB") || type.equals("CLOB") || type.equals("NCLOB")) { throw StandardException.newException(SQLState.LOB_AS_METHOD_ARGUMENT_OR_RECEIVER); } } } } } } /** * 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 * * @return Whether or not all of the parameters to this node are QUERY_INVARIANT or CONSTANT * @exception StandardException thrown on error */ protected boolean areParametersQueryInvariant() throws StandardException { return (getVariantTypeOfParams() == Qualifier.QUERY_INVARIANT); } /** * Build parameters for error message and throw the exception when there * is no matching signature found. * * @param receiverTypeName Type name for receiver * @param parmTypeNames Type names for parameters as object types * @param primParmTypeNames Type names for parameters as primitive types * * @return Nothing. * * @exception StandardException Thrown on error */ void throwNoMethodFound(String receiverTypeName, String[] parmTypeNames, String[] primParmTypeNames) throws StandardException { /* Put the parameter type names into a single string */ StringBuffer parmTypes = new StringBuffer(); for (int i = 0; i < parmTypeNames.length; i++) { if (i != 0) parmTypes.append(", "); /* RESOLVE - shouldn't be using hard coded strings for output */ parmTypes.append( (parmTypeNames[i].length() != 0 ? parmTypeNames[i] : "UNTYPED")); if ((primParmTypeNames != null) && ! primParmTypeNames[i].equals(parmTypeNames[i])) // has primitive parmTypes.append("(" + primParmTypeNames[i] + ")"); } throw StandardException.newException(SQLState.LANG_NO_METHOD_FOUND, receiverTypeName, methodName, parmTypes); } /** * 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. * * @param numTables Number of tables in the DML Statement * @param outerFromList FromList from outer query block * @param outerSubqueryList SubqueryList from outer query block * @param outerPredicateList PredicateList from outer query block * * @return Nothing. * * @exception StandardException Thrown on error */ public void preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException { int parm; /* Preprocess the parameters */ if (methodParms != null) { for (parm = 0; parm < methodParms.length; parm++) { if (methodParms[parm] != null) { methodParms[parm].preprocess(numTables, outerFromList,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -