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

📄 resultcolumn.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.ResultColumn   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.compiler.MethodBuilder;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.StringDataValue;import org.apache.derby.iapi.sql.ResultColumnDescriptor;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.services.io.StoredFormatIds;import org.apache.derby.iapi.types.DataValueFactory;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.RowOrdering;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.impl.sql.compile.ActivationClassBuilder;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.iapi.util.StringUtil;import java.sql.Types;import java.util.Vector;/** * A ResultColumn represents a result column in a SELECT, INSERT, or UPDATE * statement.  In a SELECT statement, the result column just represents an * expression in a row being returned to the client.  For INSERT and UPDATE * statements, the result column represents an column in a stored table. * So, a ResultColumn has to be bound differently depending on the type of * statement it appears in. * * @author Jeff Lichtman */public class ResultColumn extends ValueNode 				implements ResultColumnDescriptor, Comparable{	/* name and exposedName should point to the same string, unless there is a	 * derived column list, in which case name will point to the underlying name	 * and exposedName will point to the name from the derived column list.	 */	String			name;	String			exposedName;	String			tableName;	String			sourceTableName;	//Used by metadata api ResultSetMetaData.getSchemaName to get a column's table's schema.	String			sourceSchemaName;	ValueNode		expression;	ColumnDescriptor	columnDescriptor;	boolean			isGenerated;	boolean			isGeneratedForUnmatchedColumnInInsert;	boolean			isGroupingColumn;	boolean			isReferenced;	boolean			isRedundant;	boolean			isNameGenerated;	boolean			updated;	boolean			updatableByCursor;	private boolean defaultColumn;	// tells us if this ResultColumn is a placeholder for a generated	// autoincrement value for an insert statement.	boolean			autoincrementGenerated;	// tells us if this ResultColumn represents an autoincrement column in a	// base table.	boolean 		autoincrement;	/* ResultSetNumber for the ResultSet (at generate() time) that we belong to */	private int		resultSetNumber = -1;	ColumnReference reference; // used to verify quals at bind time, if given.	/* virtualColumnId is the ResultColumn's position (1-based) within the ResultSet */	private int		virtualColumnId;	/**	 * Different types of initializer parameters indicate different	 * types of initialization.	 *	 * @param arg1	The name of the column, if any.	 * @param arg2	The expression this result column represents	 *	 * - OR -	 *	 * @param arg1	a column reference node	 * @param arg2	The expression this result column represents	 *	 * - OR -	 *	 * @param arg1	The column descriptor.	 * @param arg2	The expression this result column represents	 *	 * - OR -	 *	 * @param dtd			The type of the column	 * @param expression	The expression this result column represents	 *	 * @return	The newly initialized ResultColumn	 */	public void init(Object arg1, Object arg2)	{		// RESOLVE: This is something of a hack - it is not obvious that		// the first argument being null means it should be treated as		// a String.		if ((arg1 instanceof String) || (arg1 == null))		{			this.name = (String) arg1;			this.exposedName = this.name;			this.expression = (ValueNode) arg2;		}		else if (arg1 instanceof ColumnReference)		{			ColumnReference ref = (ColumnReference) arg1;			this.name = ref.getColumnName();			this.exposedName = ref.getColumnName();			/*				when we bind, we'll want to make sure				the reference has the right table name.		 	*/			this.reference = ref; 			this.expression = (ValueNode) arg2;		}		else if (arg1 instanceof ColumnDescriptor)		{			ColumnDescriptor coldes = (ColumnDescriptor) arg1;			DataTypeDescriptor colType = coldes.getType();			this.name = coldes.getColumnName();			this.exposedName = name;			/* Clone the type info here, so we can change nullability if needed */			setType(new DataTypeDescriptor(colType, colType.isNullable()));			this.columnDescriptor = coldes;			this.expression = (ValueNode) arg2;			this.autoincrement = coldes.isAutoincrement();		}		else		{			setType((DataTypeDescriptor) arg1);			this.expression = (ValueNode) arg2;			if (arg2 instanceof ColumnReference)			{				reference = (ColumnReference) arg2;			}		}				/* this result column represents a <default> keyword in an insert or		 * update statement		 */		if (expression != null &&			expression.isInstanceOf(C_NodeTypes.DEFAULT_NODE))			defaultColumn = true;	}	/**	 * Returns TRUE if the ResultColumn is standing in for a DEFAULT keyword in	 * an insert/update statement.	 */	public boolean isDefaultColumn()	{		return defaultColumn;	}	public void setDefaultColumn(boolean value)	{		defaultColumn = value;	}	/**	 * The following methods implement the ResultColumnDescriptor	 * interface.  See the Language Module Interface for details.	 */	public String getName()	{		return exposedName;	}	public String getSchemaName() throws StandardException	{		if ((columnDescriptor!=null) &&			(columnDescriptor.getTableDescriptor() != null))			return columnDescriptor.getTableDescriptor().getSchemaName();		else		{			if (expression != null)			// REMIND: could look in reference, if set.				return expression.getSchemaName();			else				return null;		}	}	public String getTableName()	{		if (tableName != null)		{			return tableName;		}		if ((columnDescriptor!=null) &&			(columnDescriptor.getTableDescriptor() != null))		{			return columnDescriptor.getTableDescriptor().getName();		}		else		{			return expression.getTableName();		}	}	/**	 * @see ResultColumnDescriptor#getSourceTableName	 */	public String getSourceTableName()	{		return sourceTableName;	}	/**	 * @see ResultColumnDescriptor#getSourceSchemaName	 */	public String getSourceSchemaName()	{		return sourceSchemaName;	}	/**	 * Clear the table name for the underlying ColumnReference.	 * See UpdateNode for full explaination.	 */	public void clearTableName()	{		if (expression instanceof ColumnReference)		{			((ColumnReference) expression).setTableNameNode((TableName) null);		}	}	public DataTypeDescriptor getType()	{		return dataTypeServices;	}	public DataTypeDescriptor getExpressionType()	{		return (expression == null) ?			dataTypeServices :			expression.getTypeServices();	}	public int getColumnPosition()	{		if (columnDescriptor!=null)			return columnDescriptor.getPosition();		else			return virtualColumnId;	}	/**	 * Set the expression in this ResultColumn.  This is useful in those	 * cases where you don't know the expression in advance, like for	 * INSERT statements with column lists, where the column list and	 * SELECT or VALUES clause are parsed separately, and then have to	 * be hooked up.	 *	 * @param expression	The expression to be set in this ResultColumn	 *	 * @return	Nothing	 */	public void setExpression(ValueNode expression)	{		this.expression = expression;	}	/**	 * Get the expression in this ResultColumn.  	 *	 * @return ValueNode	this.expression	 */	public ValueNode getExpression()	{		return expression;	}	/**	 * Set the expression to a null node of the	 * correct type.	 *	 * @return Nothing.	 *	 * @exception StandardException		Thrown on error	 */	void setExpressionToNullNode()		throws StandardException	{		expression = getNullNode(getTypeId(), 									getContextManager());	}	/**	 * Set the name in this ResultColumn.  This is useful when you don't	 * know the name at the time you create the ResultColumn, for example,	 * in an insert-select statement, where you want the names of the	 * result columns to match the table being inserted into, not the	 * table they came from.	 *	 * @param name	The name to set in this ResultColumn	 *	 * @return	Nothing	 */	public void setName(String name)	{		if (this.name == null)		{			this.name = name;		}		else {			if (SanityManager.DEBUG)			SanityManager.ASSERT(reference == null || 				name.equals(reference.getColumnName()), 				"don't change name from reference name");		}		this.exposedName = name;	}	/**	 * Is the name for this ResultColumn generated?	 */	public boolean isNameGenerated()	{		return isNameGenerated;	}	/**	 * Set that this result column name is generated.	 */	public void setNameGenerated(boolean value)	{		isNameGenerated = value;	}	/**	 * Set the resultSetNumber for this ResultColumn.  This is the 	 * resultSetNumber for the ResultSet that we belong to.  This	 * is useful for generate() and necessary since we do not have a	 * back pointer to the RSN.	 *	 * @param resultSetNumber	The resultSetNumber.	 *	 * @return Nothing.	 */	public void setResultSetNumber(int resultSetNumber)	{		this.resultSetNumber = resultSetNumber;	}	/**	 * Get the resultSetNumber for this ResultColumn.	 *	 * @return int	The resultSetNumber.	 */	public int getResultSetNumber()	{		return resultSetNumber;	}	/**	 * 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);		/* expression will be null for AllResultColumn */		if (expression != null)		{			expression.setClause(clause);		}		else if (SanityManager.DEBUG)		{			SanityManager.ASSERT(this instanceof AllResultColumn,				"this expected to be instanceof AllResultColumn when expression is null");		}	}	/** 	 * Adjust the virtualColumnId for this ResultColumn	by the specified amount	 * 	 * @param adjust	The adjustment for the virtualColumnId	 *	 * @return Nothing	 */	public void adjustVirtualColumnId(int adjust)	{		virtualColumnId += adjust;	}	/** 	 * Set the virtualColumnId for this ResultColumn	 * 	 * @param id	The virtualColumnId for this ResultColumn	 *	 * @return Nothing	 */

⌨️ 快捷键说明

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