You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2007/07/10 06:39:24 UTC

svn commit: r554824 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: AlterTableNode.java ColumnDefinitionNode.java ModifyColumnNode.java TableElementList.java

Author: djd
Date: Mon Jul  9 21:39:20 2007
New Revision: 554824

URL: http://svn.apache.org/viewvc?view=rev&rev=554824
Log:
DERBY-2775 Change ColumnDefinition to have a getType() method and a setNullability() method to move
towards having an immutable DataTypeDescriptor.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java?view=diff&rev=554824&r1=554823&r2=554824
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java Mon Jul  9 21:39:20 2007
@@ -240,13 +240,13 @@
 					if (tableElementList.elementAt(i) instanceof ColumnDefinitionNode) {
 						ColumnDefinitionNode cdn = (ColumnDefinitionNode) tableElementList.elementAt(i);
 						//check if we are dealing with add character column
-						if (cdn.getDataTypeServices().getTypeId().isStringTypeId()) {
+						if (cdn.getType().getTypeId().isStringTypeId()) {
 							//we found what we are looking for. Set the 
 							//collation type of this column to be the same as
 							//schema descriptor's collation. Set the collation
 							//derivation as implicit
-							cdn.getDataTypeServices().setCollationType(schemaDescriptor.getCollationType());
-							cdn.getDataTypeServices().setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+							cdn.getType().setCollationType(schemaDescriptor.getCollationType());
+							cdn.getType().setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
 			        	}						
 					}
 				}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java?view=diff&rev=554824&r1=554823&r2=554824
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java Mon Jul  9 21:39:20 2007
@@ -70,7 +70,7 @@
     /**
      * The data type of this column.
      */
-    DataTypeDescriptor			dataTypeServices;
+    DataTypeDescriptor type;
     
 	DataValueDescriptor			defaultValue;
 	DefaultInfoImpl				defaultInfo;
@@ -117,7 +117,7 @@
 		throws StandardException
 	{
 		super.init(name);
-		this.dataTypeServices = (DataTypeDescriptor) dataTypeServices;
+		this.type = (DataTypeDescriptor) dataTypeServices;
 		if (defaultNode instanceof UntypedNullConstantNode)
 		{
 			/* No DTS yet for MODIFY DEFAULT */
@@ -125,7 +125,7 @@
 			{
 				defaultValue = 
 					((UntypedNullConstantNode) defaultNode).
-									convertDefaultNode(this.dataTypeServices);
+									convertDefaultNode(this.type);
 			}
 		}
 		else
@@ -165,7 +165,7 @@
 				// 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 = getDataTypeServices().getNullabilityType(false);
+                    setNullability(false);
 			}
 		}
 	}
@@ -181,7 +181,7 @@
 	{
 		if (SanityManager.DEBUG)
 		{
-			return "dataTypeServices: " + dataTypeServices.toString() + "\n" +
+			return "type: " + getType().toString() + "\n" +
 				"defaultValue: " + defaultValue + "\n" +
 				super.toString();
 		}
@@ -202,14 +202,22 @@
 	}
 
 	/**
-	 * Returns the data type services of the column being defined.
+	 * Returns the data type of the column being defined.
 	 *
-	 * @return	the data type services of the column
+	 * @return	the data type of the column
 	 */
-	public final DataTypeDescriptor getDataTypeServices()
+	public final DataTypeDescriptor getType()
 	{
-		return this.dataTypeServices;
+		return type;
 	}
+    
+    /**
+     * Set the nullability of the column definition node.
+      */
+    void setNullability(boolean nullable)
+    {
+        type = getType().getNullabilityType(nullable);
+    }
 
 	/**
 	 * Return the DataValueDescriptor containing the default value for this
@@ -338,13 +346,13 @@
 		String			columnTypeName;
 
 		/* Built-in types need no checking */
-		if (!dataTypeServices.getTypeId().userType())
+		if (!getType().getTypeId().userType())
 			return;
 
 		ClassInspector classInspector = getClassFactory().getClassInspector();
 
 		columnTypeName =
-			dataTypeServices.getTypeId().getCorrespondingJavaTypeName();
+			getType().getTypeId().getCorrespondingJavaTypeName();
 
 
 
@@ -410,7 +418,7 @@
 		throws StandardException
 	{
 		/* DB2 requires non-nullable columns to have a default in ALTER TABLE */
-		if (td != null && !dataTypeServices.isNullable() && defaultNode == null)
+		if (td != null && !getType().isNullable() && defaultNode == null)
 		{
 			if (!isAutoincrement)
 				throw StandardException.newException(SQLState.LANG_DB2_NOT_NULL_COLUMN_INVALID_DEFAULT, getColumnName());
@@ -464,7 +472,7 @@
 				(autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.CREATE_AUTOINCREMENT ||
 						autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_INC_VALUE))
 			throw StandardException.newException(SQLState.LANG_AI_INVALID_INCREMENT, getColumnName());
-		int jdbctype = dataTypeServices.getTypeId().getJDBCTypeId();
+		int jdbctype = getType().getTypeId().getJDBCTypeId();
 		switch (jdbctype)
 		{
 		case Types.TINYINT:
@@ -572,12 +580,12 @@
 							(SubqueryList) null,
 							(Vector) null);
 
-			TypeId columnTypeId = dataTypeServices.getTypeId();
+			TypeId columnTypeId = getType().getTypeId();
 			TypeId defaultTypeId = defaultTree.getTypeId();
 
 			// Check for 'invalid default' errors (42894)
 			// before checking for 'not storable' errors (42821).
-			if (!defaultTypeIsValid(columnTypeId, dataTypeServices,
+			if (!defaultTypeIsValid(columnTypeId, getType(),
 					defaultTypeId, defaultTree, defaultNode.getDefaultText()))
 			{
 					throw StandardException.newException(

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java?view=diff&rev=554824&r1=554823&r2=554824
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java Mon Jul  9 21:39:20 2007
@@ -103,18 +103,17 @@
 		}
 		
 		DataTypeDescriptor oldType = cd.getType();
-        dataTypeServices = 
-            getDataTypeServices().getNullabilityType(oldType.isNullable());
+        setNullability(oldType.isNullable());
 
 		// can't change types yet.
-		if (!(oldType.getTypeId().equals(getDataTypeServices().getTypeId())))
+		if (!(oldType.getTypeId().equals(getType().getTypeId())))
 		{
 			throw StandardException.newException(
 					 SQLState.LANG_MODIFY_COLUMN_CHANGE_TYPE, name);
 		}			
 		
 		// can only alter the length of varchar, nvarchar, bitvarying columns
-		String typeName = getDataTypeServices().getTypeName();
+		String typeName = getType().getTypeName();
 		if (!(typeName.equals(TypeId.NATIONAL_VARCHAR_NAME)) &&
 			!(typeName.equals(TypeId.VARCHAR_NAME)) &&
 			!(typeName.equals(TypeId.VARBIT_NAME)))
@@ -124,7 +123,7 @@
 		}
 		
 		// cannot decrease the length of a column
-		if (getDataTypeServices().getMaximumWidth() < oldType.getMaximumWidth())
+		if (getType().getMaximumWidth() < oldType.getMaximumWidth())
 		{
 			throw StandardException.newException(
 						 SQLState.LANG_MODIFY_COLUMN_INVALID_LENGTH, name);
@@ -302,7 +301,7 @@
 			autoincrementStart = cd.getAutoincStart();
 
 		/* Fill in the DataTypeServices from the DataDictionary */
-		dataTypeServices = cd.getType();
+		type = cd.getType();
 
 		// Now validate the default
 		validateDefault(dd, td);
@@ -355,7 +354,7 @@
 			return;
 		
 		super.validateAutoincrement(dd, td, tableType);
-		if (getDataTypeServices().isNullable())
+		if (getType().isNullable())
 			throw StandardException.newException(SQLState.LANG_AI_CANNOT_ADD_AI_TO_NULLABLE,
 												getColumnName());
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?view=diff&rev=554824&r1=554823&r2=554824
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java Mon Jul  9 21:39:20 2007
@@ -165,8 +165,8 @@
 			{
 				ColumnDefinitionNode cdn = (ColumnDefinitionNode) elementAt(index);
 				if (tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE &&
-					(cdn.getDataTypeServices().getTypeId().isLongConcatableTypeId() ||
-					cdn.getDataTypeServices().getTypeId().isUserDefinedTypeId()))
+					(cdn.getType().getTypeId().isLongConcatableTypeId() ||
+					cdn.getType().getTypeId().isUserDefinedTypeId()))
 				{
 					throw StandardException.newException(SQLState.LANG_LONG_DATA_TYPE_NOT_ALLOWED, cdn.getColumnName());
 				}
@@ -399,7 +399,7 @@
 
 			colInfos[index - numConstraints] = 
 				new ColumnInfo(coldef.getColumnName(),
-							   coldef.getDataTypeServices(),
+							   coldef.getType(),
 							   coldef.getDefaultValue(),
 							   coldef.getDefaultInfo(),
 							   (UUID) null,
@@ -449,12 +449,12 @@
 											C_NodeTypes.BASE_COLUMN_NODE,
 											cdn.getColumnName(),
 									  		exposedName,
-											cdn.getDataTypeServices(),
+											cdn.getType(),
 											getContextManager());
 
 				resultColumn = (ResultColumn) getNodeFactory().getNode(
 												C_NodeTypes.RESULT_COLUMN,
-												cdn.getDataTypeServices(), 
+												cdn.getType(), 
 												valueNode,
 												getContextManager());
 				resultColumn.setName(cdn.getColumnName());
@@ -938,7 +938,7 @@
                 ColumnDefinitionNode cdn = (ColumnDefinitionNode) tableElement;
                 if (colName.equals(cdn.getColumnName()))
                 {
-                    return cdn.getDataTypeServices();
+                    return cdn.getType();
                 }
             }
         }