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/09 09:49:19 UTC

svn commit: r526668 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/

Author: mamta
Date: Mon Apr  9 00:49:18 2007
New Revision: 526668

URL: http://svn.apache.org/viewvc?view=rev&rev=526668
Log:
I am committing an intermediate patch for language based ordering. This patch is also attached to DERBY-2534 as 
DERBY2534_getValue_On_StringDataValue_v1_diff.txt. The patch adds a new api to StringDataValue interface and the new api looks as follows
public StringDataValue getValue(RuleBasedCollator collatorForComparison);

The new api will be needed in quite a few different places. 2 distinct uses that I can see at this point are
1)Store will have a format id and collation type when it is trying to construct a DVD template. Using the formatid, we will first
always get the base class DVD for char datatypes namely SQLChar, SQLVarchar, SQLLongvarchar or SQLClob. But, if the collation type
is not 0  ie it is not UCS_BASIC, then we want to use Collation sensitive DVDs of base char DVDs because we want to use the passed
Collator for collation rather than the default UCS_BASIC Collator. The collation sensitive DVDs of char datatypes are CollatorSQLChar, 
CollatorSQLVarchar, CollatorSQLLongvarchar and CollatorSQLClob. In order to derive these collation sensitive DVDs of character datatypes, 
we will use this new api called getValue on base character DVDs. The getValue method will have the Collator object as parameter to it. 
If the Collator object is null, then we can continue to use the base DVD. But if the Collator object is not null, then we want to 
construct collation sensitive DVD. The new api on StringDataValue will help achieve this behavior.
2)Another place which I can envision using this new api is in DataTypeDescriptor.getNull() method which returns a DVD. Currently, the
implementation of this method looks as follows
	public DataValueDescriptor getNull() {
		return typeId.getNull();
	}
So, if the typeid of DTD is character data type, this method will always return base char DVD, no matter what is the collation type of
the DTD. But, if the DTD has a territory based collation set for it, then this method should return collation sensitive char DVD. This 
functionality can be achieved by using the new api on StringDataValue.

I do not anticipate this new method ever getting called on collation sensitive DVDs in Derby 10.3 In future, when Derby will start 
supporting SQL standard COLLATE clause, this method might get called on the collation sensitive DVDs but for Derby 10.3, the new api
in collation sensitive DVDs is just a place holder.


Another change to note is I have changed all the collation sensitive subclasses to have their method setCollator changed from private to
protected. This is so that the getValue method from their correspoding base classes can call the setCollator method on subclasses.

The files changed by this commit are
svn stat -q
M      java\engine\org\apache\derby\iapi\types\SQLLongvarchar.java
M      java\engine\org\apache\derby\iapi\types\StringDataValue.java
M      java\engine\org\apache\derby\iapi\types\CollatorSQLChar.java
M      java\engine\org\apache\derby\iapi\types\CollatorSQLClob.java
M      java\engine\org\apache\derby\iapi\types\CollatorSQLVarchar.java
M      java\engine\org\apache\derby\iapi\types\SQLChar.java
M      java\engine\org\apache\derby\iapi\types\SQLClob.java
M      java\engine\org\apache\derby\iapi\types\SQLVarchar.java
M      java\engine\org\apache\derby\iapi\types\CollatorSQLLongvarchar.java

The code compiles ok with my changes. None of the tests should get impacted because currently, this new api on StringDataValue is 
not called by any other code in Derby. 

If anyone has any feedback, please let me know.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLLongvarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java Mon Apr  9 00:49:18 2007
@@ -65,7 +65,7 @@
 	 * Set the RuleBasedCollator for this instance of CollatorSQLChar. It will
 	 * be used to do the collation.
 	 */
-	private void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
+	protected void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
 	{
 		holderForCollationSensitiveInfo = 
 			new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this);
@@ -114,6 +114,31 @@
 		result.setCollator(
 				holderForCollationSensitiveInfo.getCollatorForCollation());
 		return result;
+	}
+
+	/**
+	 * We do not anticipate this method on collation sensitive DVD to be
+	 * ever called in Derby 10.3 In future, when Derby will start supporting
+	 * SQL standard COLLATE clause, this method might get called on the
+	 * collation sensitive DVDs.
+	 *  
+	 * @see StringDataValue#getValue(RuleBasedCollator) 
+	 */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison != null)
+		{
+			//non-null collatorForComparison means use this collator sensitive
+			//implementation of SQLChar
+		    setCollator(collatorForComparison);
+		    return this;			
+		} else {
+			//null collatorForComparison means use UCS_BASIC for collation.
+			//For that, we need to use the base class SQLChar
+			SQLChar s = new SQLChar();
+			s.copyState(this);
+			return s;
+		}
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java Mon Apr  9 00:49:18 2007
@@ -65,7 +65,7 @@
 	 * Set the RuleBasedCollator for this instance of CollatorSQLClob. It will
 	 * be used to do the collation.
 	 */
-	private void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
+	protected void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
 	{
 		holderForCollationSensitiveInfo = 
 			new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this);
@@ -114,6 +114,31 @@
 		result.setCollator(
 				holderForCollationSensitiveInfo.getCollatorForCollation());
 		return result;
+	}
+
+	/**
+	 * We do not anticipate this method on collation sensitive DVD to be
+	 * ever called in Derby 10.3 In future, when Derby will start supporting
+	 * SQL standard COLLATE clause, this method might get called on the
+	 * collation sensitive DVDs.
+	 *  
+	 * @see StringDataValue#getValue(RuleBasedCollator) 
+	 */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison != null)
+		{
+			//non-null collatorForComparison means use this collator sensitive
+			//implementation of SQLClob
+		    setCollator(collatorForComparison);
+		    return this;			
+		} else {
+			//null collatorForComparison means use UCS_BASIC for collation.
+			//For that, we need to use the base class SQLClob
+			SQLClob s = new SQLClob();
+			s.copyState(this);
+			return s;
+		}
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java Mon Apr  9 00:49:18 2007
@@ -65,7 +65,7 @@
 	 * Set the RuleBasedCollator for this instance of CollatorSQLLongvarchar. 
 	 * It will be used to do the collation.
 	 */
-	private void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
+	protected void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
 	{
 		holderForCollationSensitiveInfo = 
 			new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this);
@@ -114,6 +114,31 @@
 		result.setCollator(
 				holderForCollationSensitiveInfo.getCollatorForCollation());
 		return result;
+	}
+
+	/**
+	 * We do not anticipate this method on collation sensitive DVD to be
+	 * ever called in Derby 10.3 In future, when Derby will start supporting
+	 * SQL standard COLLATE clause, this method might get called on the
+	 * collation sensitive DVDs.
+	 *  
+	 * @see StringDataValue#getValue(RuleBasedCollator) 
+	 */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison != null)
+		{
+			//non-null collatorForComparison means use this collator sensitive
+			//implementation of SQLLongvarchar
+		    setCollator(collatorForComparison);
+		    return this;			
+		} else {
+			//null collatorForComparison means use UCS_BASIC for collation.
+			//For that, we need to use the base class SQLLongvarchar
+			SQLLongvarchar s = new SQLLongvarchar();
+			s.copyState(this);
+			return s;
+		}
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java Mon Apr  9 00:49:18 2007
@@ -65,7 +65,7 @@
 	 * Set the RuleBasedCollator for this instance of CollatorSQLVarchar. It will
 	 * be used to do the collation.
 	 */
-	private void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
+	protected void setCollator(RuleBasedCollator collatorForCharacterDatatypes)
 	{
 		holderForCollationSensitiveInfo = 
 			new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this);
@@ -114,6 +114,31 @@
 		result.setCollator(
 				holderForCollationSensitiveInfo.getCollatorForCollation());
 		return result;
+	}
+
+	/**
+	 * We do not anticipate this method on collation sensitive DVD to be
+	 * ever called in Derby 10.3 In future, when Derby will start supporting
+	 * SQL standard COLLATE clause, this method might get called on the
+	 * collation sensitive DVDs.
+	 *  
+	 * @see StringDataValue#getValue(RuleBasedCollator) 
+	 */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison != null)
+		{
+			//non-null collatorForComparison means use this collator sensitive
+			//implementation of SQLVarchar
+		    setCollator(collatorForComparison);
+		    return this;			
+		} else {
+			//null collatorForComparison means use UCS_BASIC for collation.
+			//For that, we need to use the base class SQLVarchar
+			SQLVarchar s = new SQLVarchar();
+			s.copyState(this);
+			return s;
+		}
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java Mon Apr  9 00:49:18 2007
@@ -954,6 +954,22 @@
 		return new SQLChar();
 	}
 
+	/** @see StringDataValue#getValue(RuleBasedCollator) */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison == null)
+		{//null collatorForComparison means use UCS_BASIC for collation
+		    return this;			
+		} else {
+			//non-null collatorForComparison means use collator sensitive
+			//implementation of SQLChar
+		     CollatorSQLChar s = new CollatorSQLChar();
+		     s.copyState(this);
+		     s.setCollator(collatorForComparison);
+		     return s;
+		}
+	}
+
 	/** 
 	 * @see DataValueDescriptor#setValueFromResultSet 
 	 *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java Mon Apr  9 00:49:18 2007
@@ -36,6 +36,7 @@
 import java.sql.SQLException;
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.text.RuleBasedCollator;
 import java.util.Calendar;
 
 
@@ -92,6 +93,22 @@
 	public DataValueDescriptor getNewNull()
 	{
 		return new SQLClob();
+	}
+
+	/** @see StringDataValue#getValue(RuleBasedCollator) */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison == null)
+		{//null collatorForComparison means use UCS_BASIC for collation
+		    return this;			
+		} else {
+			//non-null collatorForComparison means use collator sensitive
+			//implementation of SQLClob
+		     CollatorSQLClob s = new CollatorSQLClob();
+		     s.copyState(this);
+		     s.setCollator(collatorForComparison);
+		     return s;
+		}
 	}
 
 	/*

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLLongvarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLLongvarchar.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLLongvarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLLongvarchar.java Mon Apr  9 00:49:18 2007
@@ -21,6 +21,8 @@
 
 package org.apache.derby.iapi.types;
 
+import java.text.RuleBasedCollator;
+
 import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.TypeId;
@@ -91,6 +93,22 @@
 	public DataValueDescriptor getNewNull()
 	{
 		return new SQLLongvarchar();
+	}
+
+	/** @see StringDataValue#getValue(RuleBasedCollator) */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison == null)
+		{//null collatorForComparison means use UCS_BASIC for collation
+		    return this;			
+		} else {
+			//non-null collatorForComparison means use collator sensitive
+			//implementation of SQLLongvarchar
+		     CollatorSQLLongvarchar s = new CollatorSQLLongvarchar();
+		     s.copyState(this);
+		     s.setCollator(collatorForComparison);
+		     return s;
+		}
 	}
 
 	/*

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java?view=diff&rev=526668&r1=526667&r2=526668
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java Mon Apr  9 00:49:18 2007
@@ -21,6 +21,8 @@
 
 package org.apache.derby.iapi.types;
 
+import java.text.RuleBasedCollator;
+
 import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.TypeId;
@@ -90,6 +92,22 @@
 	public DataValueDescriptor getNewNull()
 	{
 		return new SQLVarchar();
+	}
+
+	/** @see StringDataValue#getValue(RuleBasedCollator) */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison)
+	{
+		if (collatorForComparison == null)
+		{//null collatorForComparison means use UCS_BASIC for collation
+		    return this;			
+		} else {
+			//non-null collatorForComparison means use collator sensitive
+			//implementation of SQLVarchar
+		     CollatorSQLVarchar s = new CollatorSQLVarchar();
+		     s.copyState(this);
+		     s.setCollator(collatorForComparison);
+		     return s;
+		}
 	}
 
 

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=526668&r1=526667&r2=526668
==============================================================================
--- 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 Mon Apr  9 00:49:18 2007
@@ -23,6 +23,8 @@
 
 import org.apache.derby.iapi.error.StandardException;
 
+import java.text.RuleBasedCollator;
+
 public interface StringDataValue extends ConcatableDataValue
 {
 	// TRIM() types
@@ -175,4 +177,13 @@
 	 */
 	public char[] getCharArray() throws StandardException;
 
+	/**
+	 * Gets either SQLChar/SQLVarchar/SQLLongvarchar/SQLClob(base classes) or 
+	 * CollatorSQLChar/CollatorSQLVarchar/CollatorSQLLongvarch/CollatorSQLClob
+	 * (subclasses). Whether this method returns the base class or the subclass 
+	 * depends on the value of the RuleBasedCollator. If RuleBasedCollator is 
+	 * null, then the object returned would be baseclass otherwise it would be 
+	 * subcalss.
+	 */
+	public StringDataValue getValue(RuleBasedCollator collatorForComparison);
 }