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

📄 columndefinitionnode.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.ColumnDefinitionNode   Copyright 1997, 2005 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.sanity.SanityManager;import org.apache.derby.iapi.services.io.StoredFormatIds;import org.apache.derby.iapi.reference.Limits;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;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.sql.depend.DependencyManager;import org.apache.derby.iapi.sql.depend.ProviderList;import org.apache.derby.iapi.sql.depend.ProviderInfo;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.impl.sql.execute.ColumnInfo;import org.apache.derby.catalog.AliasInfo;import org.apache.derby.catalog.DefaultInfo;import org.apache.derby.catalog.UUID;import org.apache.derby.catalog.types.DefaultInfoImpl;import java.util.Vector;import java.sql.Types;/** * A ColumnDefinitionNode represents a column definition in a DDL statement. * There will be a ColumnDefinitionNode for each column in a CREATE TABLE * statement, and for the column in an ALTER TABLE ADD COLUMN statement. * * @author Jeff Lichtman */public class ColumnDefinitionNode extends TableElementNode{	boolean						isAutoincrement;	DataTypeDescriptor			dataTypeServices;	DataValueDescriptor			defaultValue;	DefaultInfoImpl				defaultInfo;	DefaultNode					defaultNode;	long						autoincrementIncrement;	long						autoincrementStart;	boolean						autoincrementVerify;	/**	 * Initializer for a ColumnDefinitionNode	 *	 * @param name			The name of the column	 * @param defaultNode	The default value of the column	 * @param dataTypeServices	A DataTypeServices telling the type	 *				of the column	 * @param autoIncrementInfo	Info for autoincrement columns	 *	 */	public void init(					Object name,					Object defaultNode,					Object dataTypeServices,					Object autoIncrementInfo)		throws StandardException	{		super.init(name);		this.dataTypeServices = (DataTypeDescriptor) dataTypeServices;		if (defaultNode instanceof UntypedNullConstantNode)		{			/* No DTS yet for MODIFY DEFAULT */			if (dataTypeServices != null)			{				defaultValue = 					((UntypedNullConstantNode) defaultNode).									convertDefaultNode(this.dataTypeServices);			}		}		else		{			if (SanityManager.DEBUG)			{				if (defaultNode != null &&					! (defaultNode instanceof DefaultNode))				{					SanityManager.THROWASSERT(						"defaultNode expected to be instanceof DefaultNode, not " +						defaultNode.getClass().getName());				}			}			this.defaultNode = (DefaultNode) defaultNode;			if (autoIncrementInfo != null)			{				long[] aii = (long[]) autoIncrementInfo;				autoincrementStart = aii[QueryTreeNode.AUTOINCREMENT_START_INDEX];				autoincrementIncrement = aii[QueryTreeNode.AUTOINCREMENT_INC_INDEX];				/*				 * If using DB2 syntax to set increment value, will need to check if column				 * is already created for autoincrement.				 */				autoincrementVerify = (aii[QueryTreeNode.AUTOINCREMENT_IS_AUTOINCREMENT_INDEX] > 0) ? false : true;				isAutoincrement = true;				// an autoincrement column cannot be null-- setting				// non-nullability for this column is needed because 				// you could create a column with ai default, add data, drop 				// the default, and try to add it back again you'll get an				// error because the column is marked nullable.				if (dataTypeServices != null)					(this.dataTypeServices).setNullability(false);			}		}	}	/**	 * 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.toString() + "\n" +				"defaultValue: " + defaultValue + "\n" +				super.toString();		}		else		{			return "";		}	}	/**	 * Returns the unqualified name of the column being defined.	 *	 * @return	the name of the column	 */	public String getColumnName()	{		return this.name;	}	/**	 * Returns the data type services of the column being defined.	 *	 * @return	the data type services of the column	 */	public DataTypeDescriptor getDataTypeServices()	{		return this.dataTypeServices;	}	/**	 * Return the DataValueDescriptor containing the default value for this	 * column	 *	 * @return	The default value of the column	 */	public DataValueDescriptor getDefaultValue()	{		return this.defaultValue;	}	/**	 * Return the DefaultInfo containing the default information for this	 * column	 *	 * @return	The default info for the column	 */	public DefaultInfo getDefaultInfo()	{		return defaultInfo;	}	/**	 * Return the DefaultNode, if any, associated with this node.	 *	 * @return The DefaultNode, if any, associated with this node.	 */	public DefaultNode getDefaultNode()	{		return defaultNode;	}	/**	 * Is this an autoincrement column?	 *	 * @return Whether or not this is an autoincrement column.	 */	public boolean isAutoincrementColumn()	{		if (SanityManager.DEBUG)		{			if (isAutoincrement && autoincrementIncrement == 0)			{				SanityManager.THROWASSERT(					"autoincrementIncrement expected to be non-zero");			}			if ((! isAutoincrement) && 				(autoincrementStart != 0 || autoincrementIncrement != 0))			{				SanityManager.THROWASSERT(					"both autoincrementStart and autoincrementIncrement expected to be 0");			}		}		return isAutoincrement;	}	/**	 * Get the autoincrement start value	 *	 * @return Autoincrement start value.	 */	long getAutoincrementStart()	{		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(isAutoincrement,				"isAutoincrement expected to be true");		}		return autoincrementStart;	}	/**	 * Get the autoincrement increment value	 *	 * @return Autoincrement increment value.	 */	long getAutoincrementIncrement()	{		if (SanityManager.DEBUG)		{			SanityManager.ASSERT(isAutoincrement,				"isAutoincrement expected to be true");		}		return autoincrementIncrement;	}	/**	 * Check the validity of a user type.  Checks whether this column	 * definition describes a user type that either doesn't exist or is	 * inaccessible, or that doesn't implement Serializable.	 *	 * @return	Nothing	 *	 * @exception StandardException		Thrown on error	 */	public void checkUserType(TableDescriptor td) 		throws StandardException	{		String			columnTypeName;		/* Built-in types need no checking */		if (dataTypeServices.getTypeId().builtIn())			return;		ClassInspector classInspector = getClassFactory().getClassInspector();		columnTypeName =			dataTypeServices.getTypeId().getCorrespondingJavaTypeName();		/* User type - We first check for the columnTypeName as a java class.		 * If that fails, then we treat it as a class alias.		 */		boolean foundMatch = false;		Throwable reason = null;		try {			foundMatch = classInspector.accessible(columnTypeName);		} catch (ClassNotFoundException cnfe) {			reason = cnfe;		}		if (!foundMatch)		{			throw StandardException.newException(SQLState.LANG_TYPE_DOESNT_EXIST, reason, columnTypeName,																name);		}		if (! classInspector.assignableTo(columnTypeName,											"java.io.Serializable")  &&            // Before Java2, SQLData is not defined, assignableTo call returns false            ! classInspector.assignableTo(columnTypeName,"java.sql.SQLData"))        {			getCompilerContext().addWarning(				StandardException.newWarning(SQLState.LANG_TYPE_NOT_SERIALIZABLE, columnTypeName,																 name));		}	}	/**	 * Get the UUID of the old column default.	 *	 * @return The UUID of the old column default.	 */	UUID getOldDefaultUUID()	{		return null;	}	/**	 * Get the action associated with this node.	 *	 * @return The action associated with this node.	 */	int getAction()	{		return ColumnInfo.CREATE;	}	/**	 * Check the validity of the default, if any, for this node.	 *	 * @param dd		The DataDictionary.	 * @param td		The TableDescriptor.	 *	 * @return Nothing.	 *	 * @exception StandardException		Thrown on error	 */	void bindAndValidateDefault(DataDictionary dd, TableDescriptor td)		throws StandardException	{		/* DB2 requires non-nullable columns to have a default in ALTER TABLE */		if (td != null && !dataTypeServices.isNullable() && defaultNode == null)		{			if (!isAutoincrement)				throw StandardException.newException(SQLState.LANG_DB2_NOT_NULL_COLUMN_INVALID_DEFAULT, getColumnName());		}					// No work to do if no user specified default		if (defaultNode == null)		{			return;		}		// No work to do if user specified NULL		if (defaultValue != null)		{			return;

⌨️ 快捷键说明

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