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 ma...@apache.org on 2007/04/05 08:41:54 UTC

svn commit: r525729 - in /db/derby/code/trunk/java/engine/org/apache/derby: catalog/TypeDescriptor.java catalog/types/TypeDescriptorImpl.java iapi/types/DataTypeDescriptor.java iapi/types/StringDataValue.java

Author: mamta
Date: Wed Apr  4 23:41:54 2007
New Revision: 525729

URL: http://svn.apache.org/viewvc?view=rev&rev=525729
Log:
Submitting a patch (DERBY2524_Collation_Info_In_DTD_v2_diff.txt) attached to DERBY-2524. This is a followup to the earlier commited patch (DERBY2524_Collation_Info_In_DTD_v1_diff.txt svn revision 525568) 

svn stat -q
M      java\engine\org\apache\derby\iapi\types\DataTypeDescriptor.java
M      java\engine\org\apache\derby\iapi\types\StringDataValue.java
M      java\engine\org\apache\derby\catalog\TypeDescriptor.java
M      java\engine\org\apache\derby\catalog\types\TypeDescriptorImpl.java

The patch does following to address feedback received on the earlier patch in thread http://www.nabble.com/-jira--Created%3A-%28DERBY-2524%29-DataTypeDescriptor%28DTD%29-needs-to-have-collation-type-and-collation-derivation.-These-new-fields-will-apply-only-for-character-string-types.-Other-types-should-ignore-them.-p9842379.html 
1)Moved the constant definitions from TypeDescriptor to StringDataValue.
2)Added javadoc comments for all the constants. One big javadoc comment for one of the constants in the related constants and other 
constants in that group will just have a javadoc of @see. 
3)I had used string costants for collation derivation since they are more verbose. But that is more expensive than simply using
int. As a middle ground, I have defined collation derivation constants as int but the names of the constants are verbose :)
I also changed the api for collation derivation to work with int rather than String. Finally, changed collationDerivation from
String to int in TypeDescriptorImpl.
4)Rather than using "error" to indicate incorrect collation derivation, we will just initialize collation derivation to "none".
For all character string types, the collation derivation should get changed to "implicit" unless we are working with aggregate
result type of character string type and the operands to the aggregate have different collation types.
5)Currently, I only save collation type of a persistent character string type column into SYSCOLUMNS's COLUMNDATATYPE column. Collation
derivation for such character string type is assumed as "implicit" because that is the only possible option in Derby 10.3 for persistent
columns. But in some future release of Derby, when we will start supporting SQL COLLATE clause, we will want to differentiate between 
"explicit" and "implicit" collation derivation for such persistent columns. So, may be it will be good for us to start saving collation 
derivation too. For now, I have added this task as a line item under wiki page http://wiki.apache.org/db-derby/BuiltInLanguageBasedOrderingDERBY-1478 under "Performance/Desirable items" section.
6)I caused several javadoc errors for using @see Classname.methodname rather than @see Classname#methodname. Sorry about that. Fixed 
those errors in this patch.

I think with this patch, I have taken care of all the feedback received on the earlier patch DERBY2524_Collation_Info_In_DTD_v1_diff.txt.

Again, if anyone has any comment on this committed patch or earlier commit svn revision 525568, please send your feedback on
Derby mailing list.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java?view=diff&rev=525729&r1=525728&r2=525729
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/TypeDescriptor.java Wed Apr  4 23:41:54 2007
@@ -46,31 +46,6 @@
 
 	public	static	int MAXIMUM_WIDTH_UNKNOWN = -1;
 
-	/**
-	  For a character string type, the collation derivation should always be 
-	  "explicit"(not possible in Derby 10.3), "implicit" or "none". We will 
-	  start by setting it to "error" here. But at runtime, no TypeDescriptor 
-	  which belongs to a character string type should ever have a collation 
-	  derivation of "error". The initialization to "error" is for catching an 
-	  edge(bug) case where the collation derivation may not have gotten set 
-	  correctly for a character string type.
-	  For all the other types (which are not character string types, the 
-	  collation derivation will be set to "error".
-	 */
-	public	static	String COLLATION_DERIVATION_INCORRECT = "error";
-	public	static	String COLLATION_DERIVATION_IMPLICIT = "implicit";
-	public	static	String COLLATION_DERIVATION_NONE = "none";
-	/**
-	 * In Derby 10.3, all the character columns could have a collation type of
-	 * UCS_BASIC. This is same as what we do in Derby 10.3 release. The other
-	 * option in Derby 10.3 is that all the character string types belonging to
-	 * system tables will collate using UCS_BASIC but all the character string
-	 * types belonging to user tables will collate using TERRITORY_BASED
-	 * collation.
-	 */
-	public	static	int COLLATION_VALUE_UCS_BASIC = 0;
-	public	static	int COLLATION_VALUE_TERRITORY_BASED = 1;
-
 
 	///////////////////////////////////////////////////////////////////////
 	//
@@ -180,8 +155,8 @@
 	public int getCollationType();
 
 	/**
-	 * Set the collation type of this DTD
-	 * @param collationDerivationValue This will be UCS_BASIC/TERRITORY_BASED
+	 * Set the collation type of this TypeDescriptor
+	 * @param collationTypeValue This will be 0(UCS_BASIC)/1(TERRITORY_BASED)
 	 */
 	public void setCollationType(int collationTypeValue);
 
@@ -213,22 +188,19 @@
 	 * with character strings with different collations (Section 9.3 Data types 
 	 * of results of aggregations Syntax Rule 3aii).
 	 *  
-	 * Collation derivation will be initialized to "error" but by the 
-	 * time the runtime code kicks in, it should get set to "implicit"
-	 * or "none". Otherwise, we have run into a bug.
+	 * Collation derivation will be initialized to 0("none").
 	 *  
-	 * @return Should be "implicit" or "none". A value of "error" indicates 
-	 * that the collation derivation of character type has not been set
-	 * correctly.
+	 * @return Should be 0("none") or 1("implicit"). 
 	 */
-	public String getCollationDerivation();
+	public int getCollationDerivation();
 
 	/**
 	 * Set the collation derivation of this DTD
-	 * @param collationDerivationValue This will be implicit/none/explicit
-	 * In Derby 10.3, we do not expect to get value explicit.
+	 * @param collationDerivationValue This will be 
+	 * (0)none/(1)implicit/(2)explicit
+	 * In Derby 10.3, we do not expect to get value 2(explicit).
 	 */
-	public void setCollationDerivation(String collationDerivationValue);
+	public void setCollationDerivation(int collationDerivationValue);
 
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java?view=diff&rev=525729&r1=525728&r2=525729
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java Wed Apr  4 23:41:54 2007
@@ -26,6 +26,8 @@
 
 import org.apache.derby.catalog.TypeDescriptor;
 
+import org.apache.derby.iapi.types.StringDataValue;
+
 import java.io.ObjectOutput;
 import java.io.ObjectInput;
 import java.io.IOException;
@@ -52,10 +54,10 @@
 	private int						scale;
 	private boolean					isNullable;
 	private int						maximumWidth;
-	/** @see TypeDescriptor.getCollationType */
+	/** @see TypeDescriptor#getCollationType() */
 	private int						collationType;
-	/** @see TypeDescriptor.getCollationDerivation() */
-	private String					collationDerivation = TypeDescriptor.COLLATION_DERIVATION_INCORRECT;
+	/** @see TypeDescriptor#getCollationDerivation() */
+	private int					collationDerivation = StringDataValue.COLLATION_DERIVATION_IMPLICIT;
 
 	/**
 	 * Public niladic constructor. Needed for Formatable interface to work.
@@ -331,26 +333,26 @@
 		isNullable = nullable;
 	}
 
-	/** @see TypeDescriptor.getCollationType */
+	/** @see TypeDescriptor#getCollationType() */
 	public int	getCollationType()
 	{
 		return collationType;
 	}
 
-	/** @see TypeDescriptor.setCollationType */
+	/** @see TypeDescriptor#setCollationType(int) */
 	public void	setCollationType(int collationTypeValue)
 	{
 		collationType = collationTypeValue;
 	}
 
-	/** @see TypeDescriptor.getCollationDerivation */
-	public String	getCollationDerivation()
+	/** @see TypeDescriptor#getCollationDerivation() */
+	public int	getCollationDerivation()
 	{
 		return collationDerivation;
 	}
 
-	/** @see TypeDescriptor.setCollationDerivation */
-	public void	setCollationDerivation(String collationDerivationValue)
+	/** @see TypeDescriptor#setCollationDerivation(int) */
+	public void	setCollationDerivation(int collationDerivationValue)
 	{
 		collationDerivation = collationDerivationValue;
 	}
@@ -402,7 +404,7 @@
 		if(!this.getTypeName().equals(typeDescriptor.getTypeName()) ||
 		   this.precision != typeDescriptor.getPrecision() ||
 		   this.scale != typeDescriptor.getScale() ||
-		   this.collationDerivation.equals(typeDescriptor.getCollationDerivation()) ||
+		   this.collationDerivation == typeDescriptor.getCollationDerivation() ||
 		   this.collationType == typeDescriptor.getCollationType() || 
 		   this.isNullable != typeDescriptor.isNullable() ||
 		   this.maximumWidth != typeDescriptor.getMaximumWidth())
@@ -427,6 +429,16 @@
 		typeId = (BaseTypeIdImpl) in.readObject();
 		precision = in.readInt();
 		
+		//Scale does not apply to character data types. Starting 10.3 release,
+		//the scale field in TypeDescriptor in SYSCOLUMNS will be used to save
+		//the collation type of the character data types. Because of this, in
+		//this method, we check if we are dealing with character types. If yes,
+		//then read the on-disk scale field of TypeDescriptor into collation
+		//type. In other words, the on-disk scale field has 2 different 
+		//meanings depending on what kind of data type we are dealing with.
+		//For character data types, it really represents the collation type of
+		//the character data type. For all the other data types, it represents
+		//the scale of that data type.
 		switch (typeId.getJDBCTypeId()) {
 		case Types.CHAR:
 		case Types.VARCHAR:
@@ -439,12 +451,12 @@
 			//columns always have the collation derivation of implicit, I will 
 			//simply use that value for collation derivation here for character 
 			//string type columns.
-			collationDerivation = TypeDescriptor.COLLATION_DERIVATION_IMPLICIT;
+			collationDerivation = StringDataValue.COLLATION_DERIVATION_IMPLICIT;
 			break;
 		default:
 			scale = in.readInt();
 			collationType = 0;
-			collationDerivation = TypeDescriptor.COLLATION_DERIVATION_INCORRECT;
+			collationDerivation = StringDataValue.COLLATION_DERIVATION_IMPLICIT;
 			break;
 		}
 		
@@ -465,6 +477,18 @@
 		out.writeObject( typeId );
 		out.writeInt( precision );
 
+		//Scale does not apply to character data types. Starting 10.3 release,
+		//the scale field in TypeDescriptor in SYSCOLUMNS will be used to save
+		//the collation type of the character data types. Because of this, in
+		//this method, we check if we are dealing with character types. If yes,
+		//then write the collation type into the on-disk scale field of 
+		//TypeDescriptor. But if we are dealing with non-character data types,
+		//then write the scale of that data type into the on-disk scale field
+		//of TypeDescriptor. In other words, the on-disk scale field has 2 
+		//different meanings depending on what kind of data type we are dealing 
+		//with. For character data types, it really represents the collation 
+		//type of the character data type. For all the other data types, it 
+		//represents the scale of that data type.
 		switch (typeId.getJDBCTypeId()) {
 		case Types.CHAR:
 		case Types.VARCHAR:

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?view=diff&rev=525729&r1=525728&r2=525729
==============================================================================
--- 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 Wed Apr  4 23:41:54 2007
@@ -777,26 +777,26 @@
 		return typeDescriptor.getScale();
 	}
 
-	/** @see TypeDescriptor.getCollationType */
+	/** @see TypeDescriptor#getCollationType() */
 	public int	getCollationType()
 	{
 		return typeDescriptor.getCollationType();
 	}
 
-	/** @see TypeDescriptor.setCollationType */
+	/** @see TypeDescriptor#setCollationType(int) */
 	public void	setCollationType(int collationTypeValue)
 	{
 		typeDescriptor.setCollationType(collationTypeValue);
 	}
 
-	/** @see TypeDescriptor.getCollationDerivation */
-	public String	getCollationDerivation()
+	/** @see TypeDescriptor#getCollationDerivation() */
+	public int	getCollationDerivation()
 	{
 		return typeDescriptor.getCollationDerivation();
 	}
 
-	/** @see TypeDescriptor.setCollationDerivation */
-	public void	setCollationDerivation(String collationDerivationValue)
+	/** @see TypeDescriptor#setCollationDerivation(int) */
+	public void	setCollationDerivation(int collationDerivationValue)
 	{
 		typeDescriptor.setCollationDerivation(collationDerivationValue);
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java?view=diff&rev=525729&r1=525728&r2=525729
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java Wed Apr  4 23:41:54 2007
@@ -31,6 +31,33 @@
 	public static final int LEADING		= 2;
 
 	/**
+	  For a character string type, the collation derivation should always be 
+	  "explicit"(not possible in Derby 10.3), "implicit" or "none". We will 
+	  start by setting it to "none" in TypeDescriptorImpl. At runtime, only 
+	  character string types which are results of aggregate methods dealing 
+	  with operands with different collation types should have a collation 
+	  derivation of "none". All the other character string types should have 
+	  their collation derivation set to "implicit". 
+	 */
+	public	static	int COLLATION_DERIVATION_NONE = 0;
+	/** @see StringDataValue#COLLATION_DERIVATION_NONE */
+	public	static	int COLLATION_DERIVATION_IMPLICIT = 1;
+	/** @see StringDataValue#COLLATION_DERIVATION_NONE */
+	public	static	int COLLATION_DERIVATION_EXPLICIT = 2;
+	/**
+	 * In Derby 10.3, it is possible to have database with one of the following
+	 * two configurations
+	 * 1)all the character columns will have a collation type of UCS_BASIC. 
+	 * This is same as what we do in Derby 10.2 release. 
+	 * 2)all the character string columns belonging to system tables will have 
+	 * collation type of UCS_BASIC but all the character string columns 
+	 * belonging to user tables will have collation type of TERRITORY_BASED.
+	 */
+	public	static	int COLLATION_TYPE_UCS_BASIC = 0;
+	/** @see StringDataValue#COLLATION_TYPE_UCS_BASIC */
+	public	static	int COLLATION_TYPE_TERRITORY_BASED = 1;
+
+	/**
 	 * The SQL concatenation '||' operator.
 	 *
 	 * @param leftOperand	String on the left hand side of '||'