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 2008/01/04 17:04:20 UTC

svn commit: r608901 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/types/ impl/sql/compile/

Author: djd
Date: Fri Jan  4 08:04:19 2008
New Revision: 608901

URL: http://svn.apache.org/viewvc?rev=608901&view=rev
Log:
DERBY-2775 (partial) Add a method to obtain an logically immutable DataTypeDescriptor based upon a DataTypeDescriptor but with different collation settings. Add setCollationInfo methods in ValueNode to change its collation settings and hence its (soon to be) immutable data type. Use ValueNode.setCollationInfo for the simple cases where a node's collation is set from another type.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.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/SimpleStringOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java?rev=608901&r1=608900&r2=608901&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java Fri Jan  4 08:04:19 2008
@@ -115,8 +115,7 @@
         
         // By definition, any catalog type (column in a table,
         // procedure etc.) is derivation implicit.
-        dtd.setCollationDerivation(
-                StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+        dtd.collationDerivation = StringDataValue.COLLATION_DERIVATION_IMPLICIT;
         
         return dtd;
 	}
@@ -425,7 +424,7 @@
 												isNullable,
 												typeId.getMaximumMaximumWidth());
 	}
-	public DataTypeDescriptor(DataTypeDescriptor source, boolean isNullable)
+	private DataTypeDescriptor(DataTypeDescriptor source, boolean isNullable)
 	{
 		//There might be other places, but one place this method gets called
 		//from is ResultColumn.init. When the ResultColumn(RC) is for a 
@@ -443,6 +442,27 @@
 												);
         this.collationDerivation = source.getCollationDerivation();
 	}
+    
+    private DataTypeDescriptor(DataTypeDescriptor source,
+            int collationType,
+            int collationDerivation)
+    {
+        //There might be other places, but one place this method gets called
+        //from is ResultColumn.init. When the ResultColumn(RC) is for a 
+        //ColumnDescriptor(CD), the RC's TypeDescriptorImpl(TDI) should get 
+        //all the attributes of CD's TDI. So, if the CD is for a user table's
+        //character type column, then this call by RC.init should have CD's 
+        //collation attributes copied into RC along with other attributes. 
+        this.typeId = source.typeId;
+        typeDescriptor = new TypeDescriptorImpl(source.typeDescriptor,
+                                                source.getPrecision(),
+                                                source.getScale(),
+                                                source.isNullable(),
+                                                source.getMaximumWidth(),
+                                                collationType
+                                                );
+        this.collationDerivation = collationDerivation;
+    }
 
 	/**
 	 * Constructor for internal uses only.  
@@ -1123,6 +1143,24 @@
             return this;
         
         return new DataTypeDescriptor(this, isNullable);
+    }
+    
+    /**
+     * Return a type description identical to this type
+     * with the exception that its collation information is
+     * taken from the passed in information.
+    * @return This if collation would be unchanged otherwise a new type.
+     */   
+    public DataTypeDescriptor getCollatedType(int collationType,
+            int collationDerivation)
+    {
+        if ((getCollationType() == collationType) &&
+            (getCollationDerivation() == collationDerivation))
+            return this;
+                
+        return new DataTypeDescriptor(this,
+                collationType,
+                collationDerivation);
     }
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java?rev=608901&r1=608900&r2=608901&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java Fri Jan  4 08:04:19 2008
@@ -126,10 +126,7 @@
 			leftOperand.setType(new DataTypeDescriptor(leftType, true));
 			if (rightOperand.getTypeId().isStringTypeId()) {
 				//collation of ? operand should be picked from the context
-				leftOperand.getTypeServices().setCollationDerivation(
-						rightOperand.getTypeServices().getCollationDerivation());
-				leftOperand.getTypeServices().setCollationType(
-						rightOperand.getTypeServices().getCollationType());
+                leftOperand.setCollationInfo(rightOperand.getTypeServices());
 			}
 		}
 
@@ -169,10 +166,7 @@
 			rightOperand.setType(new DataTypeDescriptor(rightType, true));
 			if (leftOperand.getTypeId().isStringTypeId()) {
 				//collation of ? operand should be picked from the context
-				rightOperand.getTypeServices().setCollationDerivation(
-						leftOperand.getTypeServices().getCollationDerivation());
-				rightOperand.getTypeServices().setCollationType(
-						leftOperand.getTypeServices().getCollationType());
+                rightOperand.setCollationInfo(leftOperand.getTypeServices());
 			}
 		}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java?rev=608901&r1=608900&r2=608901&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java Fri Jan  4 08:04:19 2008
@@ -193,15 +193,10 @@
             //or escape clauses in that order. If not, then it will take it's
             //collation from the compilation schema.
             if (!leftOperand.requiresTypeFromContext()) {
-            	receiver.getTypeServices().setCollationDerivation(
-            			leftOperand.getTypeServices().getCollationDerivation());
-            	receiver.getTypeServices().setCollationType(
-            			leftOperand.getTypeServices().getCollationType());
+                receiver.setCollationInfo(leftOperand.getTypeServices());
+
             } else if (rightOperand != null && !rightOperand.requiresTypeFromContext()) {
-            	receiver.getTypeServices().setCollationDerivation(
-            			rightOperand.getTypeServices().getCollationDerivation());
-            	receiver.getTypeServices().setCollationType(
-            			rightOperand.getTypeServices().getCollationType());            	
+                receiver.setCollationInfo(rightOperand.getTypeServices());          	
             } else {
     			receiver.setCollationUsingCompilationSchema(
     					StringDataValue.COLLATION_DERIVATION_IMPLICIT);            	
@@ -235,10 +230,7 @@
             //By the time we come here, receiver will have correct collation
             //set on it and hence we can rely on it to get correct collation
             //for the other ? in LIKE clause
-			leftOperand.getTypeServices().setCollationDerivation(
-					receiver.getTypeServices().getCollationDerivation());
-			leftOperand.getTypeServices().setCollationType(
-        			receiver.getTypeServices().getCollationType());            	
+            leftOperand.setCollationInfo(receiver.getTypeServices());          	
         }
 
         /* 
@@ -267,10 +259,7 @@
             //By the time we come here, receiver will have correct collation
             //set on it and hence we can rely on it to get correct collation
             //for the other ? in LIKE clause
-			rightOperand.getTypeServices().setCollationDerivation(
-					receiver.getTypeServices().getCollationDerivation());
-			rightOperand.getTypeServices().setCollationType(
-        			receiver.getTypeServices().getCollationType());            	
+            rightOperand.setCollationInfo(receiver.getTypeServices());    	
         }
 
         bindToBuiltIn();

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?rev=608901&r1=608900&r2=608901&view=diff
==============================================================================
--- 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 Fri Jan  4 08:04:19 2008
@@ -1043,10 +1043,8 @@
 				//depending on the collation type.
 				if (newValue instanceof StringDataValue)
 				{
-					constant.getTypeServices().setCollationDerivation(
-							resultColumnType.getCollationDerivation());
-					constant.getTypeServices().setCollationType(
-							resultColumnType.getCollationType());
+                    constant.setCollationInfo(resultColumnType);
+                    
 					DataValueFactory dvf = getDataValueFactory();
 					newValue = ((StringDataValue)newValue).getValue(dvf.getCharacterCollator(
 							constant.getTypeServices().getCollationType()));

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java?rev=608901&r1=608900&r2=608901&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java Fri Jan  4 08:04:19 2008
@@ -133,10 +133,7 @@
 				);
 		//Result of upper()/lower() will have the same collation as the   
 		//argument to upper()/lower(). 
-		getTypeServices().setCollationDerivation(
-				operand.getTypeServices().getCollationDerivation());
-		getTypeServices().setCollationType(
-				operand.getTypeServices().getCollationType());
+        setCollationInfo(operand.getTypeServices());
 
 		return this;
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java?rev=608901&r1=608900&r2=608901&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java Fri Jan  4 08:04:19 2008
@@ -532,10 +532,7 @@
 			//character to be trimmed is also a parameter), then it will take 
 			//it's collation from the compilation schema.
             if (!leftOperand.requiresTypeFromContext()) {
-            	receiver.getTypeServices().setCollationDerivation(
-            			leftOperand.getTypeServices().getCollationDerivation());
-            	receiver.getTypeServices().setCollationType(
-            			leftOperand.getTypeServices().getCollationType());
+                receiver.setCollationInfo(leftOperand.getTypeServices());
             } else {
     			receiver.setCollationUsingCompilationSchema(
     					StringDataValue.COLLATION_DERIVATION_IMPLICIT);            	
@@ -551,10 +548,7 @@
             //By the time we come here, receiver will have correct collation
             //set on it and hence we can rely on it to get correct collation
             //for the ? for the character that needs to be used for trimming.
-			leftOperand.getTypeServices().setCollationDerivation(
-					receiver.getTypeServices().getCollationDerivation());
-			leftOperand.getTypeServices().setCollationType(
-        			receiver.getTypeServices().getCollationType());            	
+            leftOperand.setCollationInfo(receiver.getTypeServices());           	
 		}
 
 		bindToBuiltIn();
@@ -597,10 +591,7 @@
 		//Result of TRIM should pick up the collation of the character string
 		//that is getting trimmed (which is variable receiver) because it has
 		//correct collation set on it.
-		getTypeServices().setCollationDerivation(
-				receiver.getTypeServices().getCollationDerivation());
-		getTypeServices().setCollationType(
-				receiver.getTypeServices().getCollationType());
+        setCollationInfo(receiver.getTypeServices());
 
 		return this;
 	}
@@ -681,10 +672,7 @@
             //By the time we come here, receiver will have correct collation
             //set on it and hence we can rely on it to get correct collation
             //for this ? 
-			leftOperand.getTypeServices().setCollationDerivation(
-					receiver.getTypeServices().getCollationDerivation());
-			leftOperand.getTypeServices().setCollationType(
-        			receiver.getTypeServices().getCollationType());            	
+            leftOperand.setCollationInfo(receiver.getTypeServices());          	
 		}
 
 		/*
@@ -851,10 +839,7 @@
 		//Result of SUSBSTR should pick up the collation of the 1st argument
 		//to SUBSTR. The 1st argument to SUBSTR is represented by the variable
 		//receiver in this class.
-		getTypeServices().setCollationDerivation(
-				receiver.getTypeServices().getCollationDerivation());
-		getTypeServices().setCollationType(
-				receiver.getTypeServices().getCollationType());
+        setCollationInfo(receiver.getTypeServices());
 		return this;
 	}
 

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?rev=608901&r1=608900&r2=608901&view=diff
==============================================================================
--- 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 Fri Jan  4 08:04:19 2008
@@ -206,6 +206,40 @@
     {
         setType(getTypeServices().getNullabilityType(nullability));
     }
+    
+    /**
+     * Set the collation type and derivation of this node based upon
+     * the collation information in the passed in type. Note that the
+     * base type of this node is not changed (e.g. INTEGER), only its
+     * collation settings. This may result in a different object being
+     * returned from getTypeServices().
+     * 
+     * @param collationInfoType Type to take collation type and derivation from.
+     * @throws StandardException Error setting type.
+     */
+    public void setCollationInfo(DataTypeDescriptor collationInfoType)
+    throws StandardException
+    {
+        setCollationInfo(collationInfoType.getCollationType(),
+                collationInfoType.getCollationDerivation());
+    }
+
+    /**
+     * Set the collation type and derivation of this node based upon
+     * the collation information passed in.
+     * This may result in a different object being
+     * returned from getTypeServices().
+     * 
+     * @param collationType Collation type
+     * @param collationDerivation Collation derivation
+     * @throws StandardException Error setting type
+     */
+    public void setCollationInfo(int collationType, int collationDerivation)
+        throws StandardException
+    {
+        setType(getTypeServices().getCollatedType(
+                collationType, collationDerivation));
+    }
 
 	/**
 	 * Get the TypeId from this ValueNode.
@@ -271,9 +305,9 @@
 	 */
 	protected void setCollationUsingCompilationSchema(int collationDerivation)
 	throws StandardException {
-        getTypeServices().setCollationType(
-	    	     getSchemaDescriptor(null, false).getCollationType());
-        getTypeServices().setCollationDerivation(collationDerivation);
+        setCollationInfo(
+                getSchemaDescriptor(null, false).getCollationType(),
+                collationDerivation);
 	}