⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valuenode.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.ValueNode   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.types.DataTypeDescriptor;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.compile.TypeCompiler;import org.apache.derby.iapi.types.DataValueFactory;import org.apache.derby.iapi.types.SQLChar;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.Optimizable;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.compile.NodeFactory;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.impl.sql.compile.ActivationClassBuilder;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.iapi.services.i18n.MessageService;import java.lang.reflect.Modifier;import java.sql.Date;import java.sql.Time;import java.sql.Timestamp;import java.util.Vector;/** * A ValueNode is an abstract class for all nodes that can represent data * values, that is, constants, columns, and expressions. * * @author Jeff Lichtman */public abstract class ValueNode extends QueryTreeNode{	public static final int IN_UNKNOWN_CLAUSE = 0;	public static final int IN_SELECT_LIST = 1;	public static final int IN_WHERE_CLAUSE = 2;	public static final int IN_HAVING_CLAUSE = 3;	protected DataTypeDescriptor	dataTypeServices;	private TypeId typeId;	   	private TypeCompiler typeCompiler;	protected int				clause = IN_UNKNOWN_CLAUSE;	// Whether or not additional predicates have been created from this one.	boolean	transformed;	/*	** Constructor for untyped ValueNodes, for example, untyped NULLs	** and parameter nodes.	**	** Binding will replace all untyped ValueNodes with typed ValueNodes	** when it figures out what their types should be.	*/	public ValueNode()	{	}	/**	 * Initializer for numeric types.	 * 	 *	 * @param typeId	The TypeID of this new node	 * @param precision	The precision of this new node	 * @param scale		The scale of this new node	 * @param isNullable	The nullability of this new node	 * @param maximumWidth	The maximum width of this new node	 *	 * @return	Nothing	 *	 * @exception StandardException	 */	public void init(			Object typeId,			Object precision,			Object scale,			Object isNullable,			Object maximumWidth)		throws StandardException	{		setType(			new DataTypeDescriptor(						(TypeId) typeId,						((Integer) precision).intValue(),						((Integer) scale).intValue(),						((Boolean) isNullable).booleanValue(),						((Integer) maximumWidth).intValue()					)				);	}	/**	 * Initializer for non-numeric types.	 * 	 *	 * @param tcf		The factory to get the	 *					DataTypeServicesFactory from	 * @param typeId	The TypeID of this new node	 * @param isNullable	The nullability of this new node	 * @param maximumWidth	The maximum width of this new node	 *	 * @exception StandardException	 */	ValueNode(			Object tcf,			Object typeId,			Object isNullable,			Object maximumWidth)		throws StandardException	{		setType(new DataTypeDescriptor(						(TypeId) typeId,						((Boolean) isNullable).booleanValue(),						((Integer) maximumWidth).intValue()						)				);	}				/**	 * 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 "dataTypeServices: " +				( ( dataTypeServices != null) ?						dataTypeServices.toString() : "null" ) + "\n" +				"clause: " + clause + "\n" +				super.toString();		}		else		{			return "";		}	}	/**	 * Get the DataTypeServices from this ValueNode.	 *	 * @return	The DataTypeServices from this ValueNode.  This	 *		may be null if the node isn't bound yet.	 */	public DataTypeDescriptor getTypeServices()	{		return dataTypeServices;	}	/**	 * Get the TypeId from this ValueNode.	 *	 * @return	The TypeId from this ValueNode.  This	 *		may be null if the node isn't bound yet.	 */	public TypeId getTypeId()	{		return typeId;	}	/**		Return the DataValueFactory	*/	protected final DataValueFactory getDataValueFactory() {		return getLanguageConnectionContext().getDataValueFactory();	}	/**	 * Get the TypeCompiler from this ValueNode, based on its TypeId.	 *	 * @return	This ValueNode's TypeCompiler	 *	 */	public TypeCompiler getTypeCompiler()	{		if (typeCompiler == null)		{			/*			** getTypeId() is overriddend by parameter node so			** don't get smart and remove the extra method call.			*/			typeCompiler = getTypeCompiler(getTypeId());		}		return typeCompiler;	}	/**	 * Set the DataTypeServices in this ValueNode.	 *	 * @param dataTypeServices	The DataTypeServices to set in this	 *				ValueNode	 *	 * @return	Nothing	 */	public void setType(DataTypeDescriptor dataTypeServices)	{		this.dataTypeServices = dataTypeServices;		/* Get this now so we only have to cast it once */		if (dataTypeServices == null)			typeId = null;		else			typeId = dataTypeServices.getTypeId();		// Clear the typeCompiler, just in case type has changed		typeCompiler = null;	}	/**	 * Set the DataTypeServices for this ValueNode.  This method is	 * overridden in ParameterNode.	 *	 * @param descriptor	The DataTypeServices to set for this ValueNode	 *	 * @return	Nothing	 *	 */	public void setDescriptor(DataTypeDescriptor descriptor)	{		setType(descriptor);	}	/**	 * Get the source for this ValueNode.	 *	 * @return	The source of this ValueNode.	 */	public ResultColumn getSourceResultColumn()	{		if (SanityManager.DEBUG)		SanityManager.ASSERT(false,			"getSourceResultColumn() not expected to be called for this node - " +			getClass().toString());		return null;	}	/**	 * Get the clause that this node appears in.	 *	 * @return int	The clause that this node appears in.	 */	public int getClause()	{		return clause;	}	/**	 * Set the clause that this node appears in.	 *	 * @param clause	The clause that this node appears in.	 *	 * @return Nothing.	 */	public void setClause(int clause)	{		this.clause = clause;	}	/**	 * Mark this predicate has having been transformed (other predicates	 * were generated from it).  This will help us with ensure that the	 * predicate does not get calculated into the selectivity multiple	 * times.	 *	 * @return Nothing.	 */	void setTransformed()	{		transformed = true;	}	/** 	 * Return whether or not this predicate has been transformed.	 *	 * @return Whether or not this predicate has been transformed.	 */	boolean getTransformed()	{		return transformed;	}		public ValueNode bindExpression(									FromList fromList, SubqueryList subqueryList,									Vector	aggregateVector)		throws StandardException	{		return bindExpression(fromList, subqueryList, aggregateVector,false);	}		/**	 * Bind this expression.  This is a place-holder method - it should never	 * be called.	 *	 * @param fromList			The FROM list to use for binding	 * @param subqueryList		The SubqueryList we are building as we hit	 *							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, boolean forQueryRewrite) 				throws StandardException	{		/* There are a bizillion classes which extend ValueNode.  Here is info		 * on some of the classes that bindExpression() should not be called on		 * and why:		 *	o  BaseColumnNodes should only appear under the ResultColumnList		 *     in the FromBaseTable.  They are created/bound when binding the		 *     FromBaseTable.		 */		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(false, 						"bindExpression() not expected to be called on a " + 						this.getClass().toString());		}		return this;	}	/**	 * Generate a SQL->Java->SQL conversion tree above the current node	 * and bind the new nodes individually.	 * This is useful when doing comparisons, built-in functions, etc. on	 * java types which have a direct mapping to system built-in types.	 *	 * @return ValueNode	The new tree.	 *	 * @exception StandardException	Thrown on error	 */	public ValueNode genSQLJavaSQLTree()		throws StandardException	{		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(typeId != null,				"genSQLJavaSQLTree() only expected to be called on a bound node");			SanityManager.ASSERT(typeId.userType(),				"genSQLJavaSQLTree() only expected to be called on user types");		}		JavaValueNode stjvn = (JavaValueNode) getNodeFactory().getNode(									C_NodeTypes.SQL_TO_JAVA_VALUE_NODE,									this,									getContextManager());		ValueNode jtsvn = (ValueNode) getNodeFactory().getNode(									C_NodeTypes.JAVA_TO_SQL_VALUE_NODE,									stjvn,									getContextManager());		jtsvn.setType(DataTypeDescriptor.getSQLDataTypeDescriptor(stjvn.getJavaTypeName()));		return jtsvn;	}	/**	 * 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		The modified expression	 *	 * @exception StandardException		Thrown on error	 */	public ValueNode preprocess(int numTables,								FromList outerFromList,								SubqueryList outerSubqueryList,								PredicateList outerPredicateList) 					throws StandardException	{		return this;	}	/**	 * Eliminate NotNodes in the current query block.  We traverse the tree, 	 * inverting ANDs and ORs and eliminating NOTs as we go.  We stop at 	 * ComparisonOperators and boolean expressions.  We invert 	 * ComparisonOperators and replace boolean expressions with 	 * boolean expression = false.	 * NOTE: Since we do not recurse under ComparisonOperators, there	 * still could be NotNodes left in the tree.	 *	 * @param	underNotNode		Whether or not we are under a NotNode.	 *								 *	 * @return		The modified expression	 *	 * @exception StandardException		Thrown on error	 */	ValueNode eliminateNots(boolean underNotNode) 					throws StandardException

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -