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

📄 resultsetnode.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.ResultSetNode   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.context.ContextManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.CostEstimate;import org.apache.derby.iapi.sql.compile.OptimizerFactory;import org.apache.derby.iapi.sql.compile.Optimizer;import org.apache.derby.iapi.sql.compile.OptimizableList;import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;import org.apache.derby.iapi.sql.compile.Parser;import org.apache.derby.iapi.sql.compile.Visitable;import org.apache.derby.iapi.sql.compile.Visitor;import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;import org.apache.derby.iapi.sql.compile.RowOrdering;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.DefaultDescriptor;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.sql.ResultColumnDescriptor;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.services.loader.GeneratedMethod;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.impl.sql.compile.ActivationClassBuilder;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.iapi.services.classfile.VMOpcode;import org.apache.derby.catalog.types.DefaultInfoImpl;import java.util.Properties;import java.util.Vector;import java.util.Set;/** * A ResultSetNode represents a result set, that is, a set of rows.  It is * analogous to a ResultSet in the LanguageModuleExternalInterface.  In fact, * code generation for a a ResultSetNode will create a "new" call to a * constructor for a ResultSet. * * @author Jeff Lichtman */public abstract class ResultSetNode extends QueryTreeNode{	int					resultSetNumber;	/* Bit map of referenced tables under this ResultSetNode */	JBitSet				referencedTableMap;	ResultColumnList	resultColumns;	boolean				statementResultSet;	boolean				cursorTargetTable;	boolean				insertSource;	CostEstimate 		costEstimate;	CostEstimate		scratchCostEstimate;	Optimizer			optimizer;	// Final cost estimate for this result set node, which is the estimate	// for this node with respect to the best join order for the top-level	// query. Subclasses will set this value where appropriate.	CostEstimate		finalCostEstimate;	/**	 * 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 	"resultSetNumber: " + resultSetNumber + "\n" +				"referencedTableMap: " +				(referencedTableMap != null 						? referencedTableMap.toString() 						: "null") + "\n" +				"statementResultSet: " + statementResultSet + "\n" +				super.toString();		}		else		{			return "";		}	}	/**	 * 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)		{			super.printSubNodes(depth);			if (resultColumns != null)			{				printLabel(depth, "resultColumns: ");				resultColumns.treePrint(depth);			}		}	}	/**	 * Get the resultSetNumber in this ResultSetNode. Expected to be set during	 * generate().	 *	 * @return int 	The resultSetNumber.	 */	public int getResultSetNumber()	{		return resultSetNumber;	}	/**	 * Get the CostEstimate for this ResultSetNode.	 *	 * @return	The CostEstimate for this ResultSetNode.	 */	public CostEstimate getCostEstimate()	{		if (SanityManager.DEBUG)		{			if (costEstimate == null)			{				SanityManager.THROWASSERT(					"costEstimate is not expected to be null for " +					getClass().getName());			}		}		return costEstimate;	}	/**	 * Get the final CostEstimate for this ResultSetNode.	 *	 * @return	The final CostEstimate for this ResultSetNode.	 */	public CostEstimate getFinalCostEstimate()		throws StandardException	{		if (SanityManager.DEBUG)		{			if (finalCostEstimate == null)			{				SanityManager.THROWASSERT(					"finalCostEstimate is not expected to be null for " +					getClass().getName());			}		}		return finalCostEstimate;	}	/**	 * Assign the next resultSetNumber to the resultSetNumber in this ResultSetNode. 	 * Expected to be done during generate().	 *	 * @return Nothing.	 *	 * @exception StandardException		Thrown on error	 */	public void assignResultSetNumber() throws StandardException	{		resultSetNumber = getCompilerContext().getNextResultSetNumber();		resultColumns.setResultSetNumber(resultSetNumber);	}	/**	 * Bind the non VTI tables in this ResultSetNode.  This includes getting their	 * descriptors from the data dictionary and numbering them.	 *	 * @param dataDictionary	The DataDictionary to use for binding	 * @param fromListParam		FromList to use/append to.	 *	 * @return	ResultSetNode	 *	 * @exception StandardException		Thrown on error	 */	public ResultSetNode bindNonVTITables(DataDictionary dataDictionary, 							FromList fromListParam) 							throws StandardException {		return this;	}	/**	 * Bind the VTI tables in this ResultSetNode.  This includes getting their	 * descriptors from the data dictionary and numbering them.	 *	 * @param fromListParam		FromList to use/append to.	 *	 * @return	ResultSetNode	 *	 * @exception StandardException		Thrown on error	 */	public ResultSetNode bindVTITables(FromList fromListParam) 		throws StandardException {		return this;	}	/**	 * Bind the expressions in this ResultSetNode.  This means binding the	 * sub-expressions, as well as figuring out what the return type is for	 * each expression.	 *	 * @param fromListParam		FromList to use/append to.	 *	 * @return	Nothing	 *	 * @exception StandardException		Thrown on error	 */	public void bindExpressions(FromList fromListParam)					throws StandardException	{		if (SanityManager.DEBUG)		SanityManager.ASSERT(false, 					"bindExpressions() is not expected to be called for " + 					this.getClass().toString());	}	/**	 * Bind the expressions in this ResultSetNode if it has tables.  This means binding the	 * sub-expressions, as well as figuring out what the return type is for	 * each expression.	 *	 * @param fromListParam		FromList to use/append to.	 *	 * @return	Nothing	 *	 * @exception StandardException		Thrown on error	 */	public void bindExpressionsWithTables(FromList fromListParam)					throws StandardException	{		if (SanityManager.DEBUG)		SanityManager.ASSERT(false, 					"bindExpressionsWithTables() is not expected to be called for " + 					this.getClass().toString());	}	/**	 * Bind the expressions in the target list.  This means binding the	 * sub-expressions, as well as figuring out what the return type is	 * for each expression.  This is useful for EXISTS subqueries, where we	 * need to validate the target list before blowing it away and replacing	 * it with a SELECT true.	 *	 * @return	Nothing	 *	 * @exception StandardException		Thrown on error	 */	public void bindTargetExpressions(FromList fromListParam)					throws StandardException	{		if (SanityManager.DEBUG)		SanityManager.ASSERT(false, 					"bindTargetExpressions() is not expected to be called for " + 					this.getClass().toString());	}	/**	 * Set the type of each parameter in the result column list for this table constructor.	 *	 * @param typeColumns	The ResultColumnList containing the desired result	 *						types.	 *	 * @exception StandardException		Thrown on error	 */	void setTableConstructorTypes(ResultColumnList typeColumns)			throws StandardException	{		if (SanityManager.DEBUG)			SanityManager.ASSERT(resultColumns.size() <= typeColumns.size(),				"More columns in ResultColumnList than in base table");		/* Look for ? parameters in the result column list */		int rclSize = resultColumns.size();		for (int index = 0; index < rclSize; index++)		{			ResultColumn	rc = (ResultColumn) resultColumns.elementAt(index);			ValueNode re = rc.getExpression();			if (re.isParameterNode())			{				ResultColumn	typeCol =					(ResultColumn) typeColumns.elementAt(index);				/*				** We found a ? - set its type to the type of the				** corresponding column of the target table.				*/				((ParameterNode) re).setDescriptor(										typeCol.getTypeServices());			}			else if (re instanceof CharConstantNode)			{				// Character constants are of type CHAR (fixed length string).				// This causes a problem (beetle 5160) when multiple row values are provided				// as constants for insertion into a variable length string column.				//				// This issue is the query expression				// VALUES 'abc', 'defghi'				// has type of CHAR(6), ie. the length of largest row value for that column.				// This is from the UNION defined behaviour.				// This causes strings with less than the maximum length to be blank padded				// to that length (CHAR semantics). Thus if this VALUES clause is used to				// insert into a variable length string column, then these blank padded values				// are inserted, which is not what is required ...				// 				// BECAUSE, when the VALUES is used as a table constructor SQL standard says the				// types of the table constructor's columns are set by the table's column types.				// Thus, in this case, each of those string constants should be of type VARCHAR				// (or the matching string type for the table).				//				//				// This is only an issue for fixed length character (CHAR, BIT) string or				// binary consraints being inserted into variable length types.				// This is because any other type's fundemental literal value is not affected				// by its data type. E.g. Numeric types such as INT, REAL, BIGINT, DECIMAL etc.				// do not have their value modifed by the union since even if the type is promoted				// to a higher type, its fundemental value remains unchanged. 				// values (1.2, 34.4567, 234.47) will be promoted to				// values (1.2000, 34.4567, 234.4700)				// but their numeric value remains the same.				//				//				//				// The fix is to change the base type of the table constructor's value to				// match the column type. Its length can be left as-is, because there is				// still a normailzation step when the value is inserted into the table.				// That will set the correct length and perform truncation checks etc.				ResultColumn	typeCol =					(ResultColumn) typeColumns.elementAt(index);				TypeId colTypeId = typeCol.getTypeId();				if (colTypeId.isStringTypeId()) {					if (colTypeId.getJDBCTypeId() != java.sql.Types.CHAR) {						int maxWidth = re.getTypeServices().getMaximumWidth();

⌨️ 快捷键说明

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