📄 parameternode.java
字号:
/* Derby - Class org.apache.derby.impl.sql.compile.ParameterNode 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.sql.compile.CompilerContext;import org.apache.derby.iapi.types.JSQLType;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.iapi.sql.LanguageFactory;import org.apache.derby.iapi.sql.ParameterValueSet;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.impl.sql.execute.BaseActivation;import org.apache.derby.iapi.services.classfile.VMOpcode;import java.sql.Types;import java.util.Enumeration;import java.util.Vector;/** * This node type represents a ? parameter. * * @author Jeff Lichtman */public class ParameterNode extends ValueNode{ /* ** The parameter number for this parameter. The numbers start at 0. */ int parameterNumber; /* ** We want to know if this node was generated or not. ** It will be skipped if it was in a predicate that ** was optimized out of the query. Skipped parameters ** need to do some minimal generation so that we can ** make users pass in parameter values for us to ignore. */ private boolean generated; /* ** Pointer to the array in the DMLStatementNode that holds the ** DataTypeServices for the parameters. 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. */ DataTypeDescriptor[] typeServices; /* ** The default value for this parameter. Currently, the only ** reason for a parameter having a default value is for a ** stored prepared statement, where they are supplied for ** optimization. */ DataValueDescriptor defaultValue; /** * 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. */ protected JSQLType jsqlType; private int orderableVariantType = Qualifier.QUERY_INVARIANT; /** * 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()). */ private ValueNode returnOutputParameter; /** * Constructor for use by the NodeFactory */ public ParameterNode() { } /** * Initializer for a ParameterNode. * * @param parameterNumber The number of this parameter, * (unique per query starting at 0) * @param defaultValue The default value for this parameter * */ public void init(Object parameterNumber, Object defaultValue) { this.defaultValue = (DataValueDescriptor) defaultValue; this.parameterNumber = ((Integer) parameterNumber).intValue(); } /** * Get the parameter number * * @return The parameter number */ public int getParameterNumber() { return parameterNumber; } /** * Set the descriptor array * * @param The array of DataTypeServices to fill in when the parameters * are bound. * * @return Nothing */ public void setDescriptors(DataTypeDescriptor[] descriptors) { // The following is commented out for #3546, for create publication // or target ddl creations there could be multiple statements trying // to bind their own parameters. So the following assumptions does not // hold true. // if (SanityManager.DEBUG) // SanityManager.ASSERT(typeServices == null, // "Attempt to re-set typeServices"); typeServices = descriptors; } /** * Set the DataTypeServices for this parameter * * @param descriptor The DataTypeServices to set for this parameter * * @return Nothing */ public void setDescriptor(DataTypeDescriptor descriptor) { if (SanityManager.DEBUG) SanityManager.ASSERT(typeServices != null, "typeServices not initialized"); // if type already determined, there's nothing to do. // this can occur if a named parameter ("?paramName") is // set equal to a unnamed parameter ("?") in a COPY PUBLICATION // statement. in this case, the named parameter may be referenced // multiple times. each time it must resolve to the same "?" // parameter. if ( typeServices[parameterNumber] != null ) { return; } /* Make sure the type is nullable. */ if ( ! descriptor.isNullable()) { /* ** Generate a new descriptor with all the same properties as ** the given one, except that it is nullable. */ descriptor = new DataTypeDescriptor(descriptor, true); } typeServices[parameterNumber] = descriptor; setType(descriptor); if ( getJSQLType() == null ) { setJSQLType( new JSQLType( descriptor ) ); } } /** * Mark this as a return output parameter (e.g. * ? = CALL myMethod()) */ public void setReturnOutputParam(ValueNode valueNode) { returnOutputParameter = valueNode; } /** * Is this as a return output parameter (e.g. * ? = CALL myMethod()) * * @return true if it is a return param */ public boolean isReturnOutputParam() { return returnOutputParameter != null; } /** * 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 setDescriptor() * method above. * * @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 The new top of the expression tree. * * @exception StandardException Thrown on error */ public ValueNode bindExpression( FromList fromList, SubqueryList subqueryList, Vector aggregateVector) throws StandardException { checkReliability( "?", CompilerContext.UNNAMED_PARAMETER_ILLEGAL ); return this; } /** * Return whether or not this expression tree represents a constant expression. * * @return Whether or not this expression tree represents a constant expression. */ public boolean isConstantExpression() { return true; } /** @see ValueNode#constantExpression */ public boolean constantExpression(PredicateList whereClause) { return true; } /** * 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) * * @return The variant type for the underlying expression. */ protected int getOrderableVariantType() { // Parameters are invariant for the life of the query return orderableVariantType; } /** * 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. */ void setOrderableVariantType(int type) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -