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/08 19:51:59 UTC

svn commit: r554399 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/

Author: djd
Date: Sun Jul  8 10:51:58 2007
New Revision: 554399

URL: http://svn.apache.org/viewvc?view=rev&rev=554399
Log:
DERBY-2775 Cleanup ValueNode.getTypeServices to not throw an exception and cleanup some implementations
of getTypeServices to be clear on what they are returning. Change the language compile code to
use the new immutable method to get a nullable DataTypeDecriptor.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.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/ColumnReference.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VirtualColumnNode.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java Sun Jul  8 10:51:58 2007
@@ -139,20 +139,15 @@
 
 	public String toString()
 	{
-		if (SanityManager.DEBUG)
-		{
-			try {
-                return "castTarget: " + getTypeServices() + "\n" +
-                	super.toString();
-            } catch (StandardException e) {
-                // TEMP - getTypeServices() should not be throwing an exception
-                return "";
-            }
-		}
-		else
-		{
-			return "";
-		}
+	    if (SanityManager.DEBUG)
+	    {
+	        return "castTarget: " + getTypeServices() + "\n" +
+	        super.toString();
+	    }
+	    else
+	    {
+	        return "";
+	    }
 	}
 
 	/**

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=554399&r1=554398&r2=554399
==============================================================================
--- 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 Sun Jul  8 10:51:58 2007
@@ -164,8 +164,8 @@
 				// 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);
+                if (dataTypeServices != null)
+                    this.dataTypeServices = getDataTypeServices().getNullabilityType(false);
 			}
 		}
 	}
@@ -572,7 +572,7 @@
 							(SubqueryList) null,
 							(Vector) null);
 
-			TypeId columnTypeId = (TypeId) dataTypeServices.getTypeId();
+			TypeId columnTypeId = dataTypeServices.getTypeId();
 			TypeId defaultTypeId = defaultTree.getTypeId();
 
 			// Check for 'invalid default' errors (42894)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java Sun Jul  8 10:51:58 2007
@@ -391,17 +391,6 @@
 	}
 
 	/**
-	 * Set the name of this column
-	 *
-	 * @param columnName	The name of this column
-	 */
-
-	public void setColumnName(String columnName)
-	{
-		this.columnName = columnName;
-	}
-
-	/**
 	 * Get the table number for this ColumnReference.
 	 *
 	 * @return	int The table number for this ColumnReference
@@ -1009,22 +998,17 @@
 	}
 
 	/**
-	 * Get the DataTypeServices from this Node.
-	 *
-	 * @return	The DataTypeServices from this Node.  This
-	 *		may be null if the node isn't bound yet.
-	 */
-	public DataTypeDescriptor getTypeServices() throws StandardException
-	{
-        DataTypeDescriptor dtd = super.getTypeServices();
-        if( dtd == null && source != null)
-        {
-            dtd = source.getTypeServices();
-            if( dtd != null)
-                setType( dtd);
-        }
-        return dtd;
-    } // end of getTypeServices
+	 * The type of a ColumnReference is the type of its
+     * source unless the source is null then it is
+     * the type that has been set on this node.
+	 */
+	public DataTypeDescriptor getTypeServices()
+	{        
+        if (source == null)
+            return super.getTypeServices();
+       
+        return source.getTypeServices();
+    }
 
 	/**
 	 * Find the source result set for this ColumnReference and

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java Sun Jul  8 10:51:58 2007
@@ -613,7 +613,6 @@
 					 */
 					matchingRC = resultColumn;
 					columnReference.setSource(resultColumn);
-					columnReference.setType(resultColumn.getTypeServices());
 					/* Set the nesting level at which the CR appears and the nesting level
 					 * of its source RC.
 					 */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java Sun Jul  8 10:51:58 2007
@@ -625,7 +625,6 @@
 					null,
 					getContextManager());
 			newColumnRef.setSource(newRC);
-			newColumnRef.setType(newRC.getExpression().getTypeServices());
 			newColumnRef.setNestingLevel(this.getLevel());
 			newColumnRef.setSourceLevel(this.getLevel());
 			tmpRC = (ResultColumn) getNodeFactory().getNode(
@@ -1087,7 +1086,6 @@
 											null,
 											getContextManager());
 		tmpColumnRef.setSource(targetRC);
-		tmpColumnRef.setType(targetRC.getExpression().getTypeServices());
 		tmpColumnRef.setNestingLevel(this.getLevel());
 		tmpColumnRef.setSourceLevel(this.getLevel());
 		newRC = (ResultColumn) getNodeFactory().getNode(

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java Sun Jul  8 10:51:58 2007
@@ -1178,7 +1178,7 @@
 				 */
 				if (restriction.getTypeServices().isNullable())
 				{
-					nextAnd.getTypeServices().setNullability(true);
+					nextAnd.setNullability(true);
 				}
 			}
 			restriction = nextAnd;
@@ -1263,7 +1263,7 @@
 				 */
 				if (restriction.getTypeServices().isNullable())
 				{
-					nextAnd.getTypeServices().setNullability(true);
+					nextAnd.setNullability(true);
 				}
 			}
 			restriction = nextAnd;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java Sun Jul  8 10:51:58 2007
@@ -21,49 +21,28 @@
 
 package	org.apache.derby.impl.sql.compile;
 
-import org.apache.derby.iapi.services.compiler.MethodBuilder;
+import java.util.Vector;
 
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.ClassName;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.services.compiler.MethodBuilder;
+import org.apache.derby.iapi.services.io.StoredFormatIds;
 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.C_NodeTypes;
 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.sql.dictionary.ColumnDescriptor;
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
 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.types.DataTypeDescriptor;
+import org.apache.derby.iapi.types.DataValueDescriptor;
+import org.apache.derby.iapi.types.DataValueFactory;
+import org.apache.derby.iapi.types.StringDataValue;
+import org.apache.derby.iapi.types.TypeId;
 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
@@ -181,12 +160,10 @@
 		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()));
+			setType(coldes.getType());
 			this.columnDescriptor = coldes;
 			this.expression = (ValueNode) arg2;
 			this.autoincrement = coldes.isAutoincrement();
@@ -295,7 +272,7 @@
 
 	public DataTypeDescriptor getType()
 	{
-		return dataTypeServices;
+		return getTypeServices();
 	}
 
 	public int getColumnPosition()
@@ -496,7 +473,7 @@
 				"tableName: " + tableName + "\n" +
 				"isNameGenerated: " + isNameGenerated + "\n" +
 				"sourceTableName: " + sourceTableName + "\n" +
-				"type: " + dataTypeServices + "\n" +
+				"type: " + getTypeServices() + "\n" +
 				"columnDescriptor: " + columnDescriptor + "\n" +
 				"isGenerated: " + isGenerated + "\n" +
 				"isGeneratedForUnmatchedColumnInInsert: " + isGeneratedForUnmatchedColumnInInsert + "\n" +
@@ -833,19 +810,21 @@
 	public void checkStorableExpression(ResultColumn toStore)
 					throws StandardException
 	{
-		TypeId columnTypeId, toStoreTypeId;
-
-		toStoreTypeId = toStore.getTypeId();
-        if( toStoreTypeId == null)
-            return;
-        
-		columnTypeId = getTypeId();
-
-		if (! getTypeCompiler().storable(toStoreTypeId, getClassFactory()))
-			throw StandardException.newException(SQLState.LANG_NOT_STORABLE, 
-				columnTypeId.getSQLTypeName(),
-				toStoreTypeId.getSQLTypeName() );
+        checkStorableExpression((ValueNode) toStore);
 	}
+    
+    private void checkStorableExpression(ValueNode source)
+        throws StandardException
+    {
+        TypeId toStoreTypeId = source.getTypeId();
+        
+        if (!getTypeCompiler().storable(toStoreTypeId, getClassFactory()))
+        {
+           throw StandardException.newException(SQLState.LANG_NOT_STORABLE, 
+                    getTypeId().getSQLTypeName(),
+                    toStoreTypeId.getSQLTypeName() );
+        }   
+    }
 
 	/**
 		This verifies that the expression is storable into the result column.
@@ -861,12 +840,7 @@
 	public void checkStorableExpression()
 					throws StandardException
 	{
-		TypeId toStoreTypeId = getExpression().getTypeId();
-
-		if (! getTypeCompiler().storable(toStoreTypeId, getClassFactory()))
-			throw StandardException.newException(SQLState.LANG_NOT_STORABLE, 
-                getTypeId().getSQLTypeName(),
-				toStoreTypeId.getSQLTypeName() );
+        checkStorableExpression(getExpression());
 	}
 
 	/**
@@ -955,68 +929,37 @@
 	boolean columnTypeAndLengthMatch()
 		throws StandardException
 	{
-		DataTypeDescriptor	resultColumnType;
-		DataTypeDescriptor	expressionType = expression.getTypeServices();
 
 		/*
 		** We can never make any assumptions about
 		** parameters.  So don't even bother in this
 		** case.
 		*/
-		if (expression.requiresTypeFromContext())
+		if (getExpression().requiresTypeFromContext())
 		{
 			return false;
 		}
 
-		resultColumnType = getType();
-
-		if (SanityManager.DEBUG)
-		{
-			if (! (resultColumnType != null))
-			{
-				SanityManager.THROWASSERT("Type is null for column " + 
-										  this);
-			}
-		}
-
 		// Are we inserting/updating an XML column?  If so, we always
 		// return false so that normalization will occur.  We have to
 		// do this because there are different "kinds" of XML values
 		// and we need to make sure they match--but we don't know
 		// the "kind" until execution time.  See the "normalize"
 		// method in org.apache.derby.iapi.types.XML for more.
-		if (resultColumnType.getTypeId().isXMLTypeId())
+		if (getTypeId().isXMLTypeId())
 			return false;
-
-		/* Are they the same type? */
-		if ( ! resultColumnType.getTypeId().getSQLTypeName().equals(
-			expressionType.getTypeId().getSQLTypeName()
-				)
-			)
-		{
-			return false;
-		}
-
-		/* Are they the same precision? */
-		if (resultColumnType.getPrecision() != expressionType.getPrecision())
-		{
-			return false;
-		}
-
-		/* Are they the same scale? */
-		if (resultColumnType.getScale() != expressionType.getScale())
-		{
-			return false;
-		}
-
-		/* Are they the same width? */
-		if (resultColumnType.getMaximumWidth() != expressionType.getMaximumWidth())
-		{
-			return false;
-		}
+        
+        
+        DataTypeDescriptor  expressionType = getExpression().getTypeServices();
+        
+        if (expressionType == null)
+            System.out.println(getExpression().getClass());
+        
+        if (!getTypeServices().isExactTypeAndLengthMatch(expressionType))
+            return false;
 
 		/* Is the source nullable and the target non-nullable? */
-		if ((! resultColumnType.isNullable()) && expressionType.isNullable())
+		if ((! getTypeServices().isNullable()) && expressionType.isNullable())
 		{
 			return false;
 		}
@@ -1027,12 +970,10 @@
 	boolean columnTypeAndLengthMatch(ResultColumn otherColumn)
 		throws StandardException
 	{
-		DataTypeDescriptor	resultColumnType;
-		DataTypeDescriptor	otherResultColumnType;
 		ValueNode otherExpression = otherColumn.getExpression();
 
-		resultColumnType = getType();
-		otherResultColumnType = otherColumn.getType();
+        DataTypeDescriptor resultColumnType = getTypeServices();
+        DataTypeDescriptor otherResultColumnType = otherColumn.getTypeServices();
 
 		if (SanityManager.DEBUG)
 		{
@@ -1464,9 +1405,21 @@
 	 */
 	public int getMaximumColumnSize()
 	{
-		return dataTypeServices.getTypeId()
-			.getApproximateLengthInBytes(dataTypeServices);
+		return getTypeServices().getTypeId()
+			.getApproximateLengthInBytes(getTypeServices());
 	}
+    
+    public DataTypeDescriptor getTypeServices()
+    {
+        DataTypeDescriptor type = super.getTypeServices();
+        if (type != null)
+            return type;
+        
+        if (getExpression() != null)
+            return getExpression().getTypeServices();
+        
+        return null;
+    }
 
 	/**
 	 * Return the variant type for the underlying expression.
@@ -1537,14 +1490,6 @@
 	}
 
 	/**
-	 * Set the nullability of this ResultColumn.
-	 */
-	public void setNullability(boolean nullability)
-	{
-		dataTypeServices.setNullability(nullability);
-	}
-
-	/**
 	 * Is this column in this array of strings?
 	 *
 	 * @param list the array of column names to compare
@@ -1727,24 +1672,6 @@
 
 		}
 	}
-
-	/**
-	 * Get the DataTypeServices from this Node.
-	 *
-	 * @return	The DataTypeServices from this Node.  This
-	 *		may be null if the node isn't bound yet.
-	 */
-	public DataTypeDescriptor getTypeServices() throws StandardException
-	{
-        DataTypeDescriptor dtd = super.getTypeServices();
-        if( dtd == null && expression != null)
-        {
-            dtd = expression.getTypeServices();
-            if( dtd != null)
-                setType( dtd);
-        }
-        return dtd;
-    } // end of getTypeServices
 
     public TableName getTableNameObject() {
         return null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java Sun Jul  8 10:51:58 2007
@@ -3477,8 +3477,9 @@
 		return mapArray;
 	}
 
-	/** Set the nullability of every ResultColumn in this list */
-	public void setNullability(boolean nullability)
+	/** Set the nullability of every ResultColumn in this list 
+	 * @throws StandardException */
+	public void setNullability(boolean nullability) throws StandardException
 	{
 		int size = size();
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java Sun Jul  8 10:51:58 2007
@@ -50,9 +50,7 @@
     /**
      * The data type for this node.
      */
-	protected DataTypeDescriptor	dataTypeServices;
-   
-	private TypeCompiler typeCompiler;
+	private DataTypeDescriptor	dataTypeServices;
 
 	// Whether or not additional predicates have been created from this one.
 	boolean	transformed;
@@ -195,10 +193,19 @@
 	 * @return	The DataTypeServices from this ValueNode.  This
 	 *		may be null if the node isn't bound yet.
 	 */
-	public DataTypeDescriptor getTypeServices() throws StandardException
+	public DataTypeDescriptor getTypeServices()
 	{
 		return dataTypeServices;
 	}
+    
+    /**
+     * Set the nullability of this value.
+     * @throws StandardException 
+     */
+    public void setNullability(boolean nullability) throws StandardException
+    {
+        setType(getTypeServices().getNullabilityType(nullability));
+    }
 
 	/**
 	 * Get the TypeId from this ValueNode.
@@ -245,9 +252,6 @@
 	public void setType(DataTypeDescriptor dataTypeServices) throws StandardException
 	{
 		this.dataTypeServices = dataTypeServices;
-
-		// Clear the typeCompiler, just in case type has changed
-		typeCompiler = null;
 	}
 	
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VirtualColumnNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VirtualColumnNode.java?view=diff&rev=554399&r1=554398&r2=554399
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VirtualColumnNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/VirtualColumnNode.java Sun Jul  8 10:51:58 2007
@@ -273,7 +273,7 @@
 	 * @return	The DataTypeServices from this Node.  This
 	 *		may be null if the node isn't bound yet.
 	 */
-	public DataTypeDescriptor getTypeServices() throws StandardException
+	public DataTypeDescriptor getTypeServices()
 	{
         return sourceColumn.getTypeServices();
     }