Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 61412 invoked from network); 1 Apr 2007 06:41:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Apr 2007 06:41:24 -0000 Received: (qmail 87154 invoked by uid 500); 1 Apr 2007 06:41:31 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 87127 invoked by uid 500); 1 Apr 2007 06:41:31 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 87116 invoked by uid 99); 1 Apr 2007 06:41:31 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 31 Mar 2007 23:41:31 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 31 Mar 2007 23:41:22 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 8E3641A9838; Sat, 31 Mar 2007 23:41:01 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r524545 - in /db/derby/code/trunk/java/engine/org/apache/derby/iapi: services/io/ types/ Date: Sun, 01 Apr 2007 06:41:01 -0000 To: derby-commits@db.apache.org From: mamta@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070401064101.8E3641A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mamta Date: Sat Mar 31 23:41:00 2007 New Revision: 524545 URL: http://svn.apache.org/viewvc?view=rev&rev=524545 Log: This commit provides collation sensitive subclasses of SQLVarchar, SQLLongvarchar, SQLClob namely, CollatorSQLVarchar, CollatorSQLLongvarchar and CollatorSQLClob. This new classes differ from their superclasses in how a non-default Collator is used for collation sensitive methods. The main problem that I came across while working on this patch is that Java does not allow multiple inheritence. Currently, the iapi.types package has SQLChar as the base class. From this SQLChar, we have 2 subclasses, namely, CollatorSQLChar and SQLVarchar. At the moment, CollatorSQLChar overrides the collation sensitive methods(currently, there is only one collation sensitive method in CollatorSQLChar called like. More will be added later) from SQLChar. In order to provide a non-default collation implementation of SQLVarchar, I need to subclass SQLVarchar, but I can't simultaneously inherit from CollatorSQLChar method to get the collation sensitive implementation of the like method. Becuase of this limitation, one option is to duplicate the implementation ofcollation sensitive methods from CollatorSQLChar into CollatorSQLVarchar. That also means that we will have to duplicate the code in Collation sensitive subclasses of SQLLongvarchar and SQLClob. That is code duplicaito n in 4 classes. In order to avoid this code duplication, I am introducing a new helper class called WorkHorseForCollatorDatatype. This new class will keep the Collator and the SQLChar object whose data needs to be collated. The new class's like method will user the Collator object on SQLChar to do the comparison. Now, the non-default collation implementation of SQLChar and SQLVarchar can simply instantiate the new WorkHorseForCollatorDatatype class and delegate all the work for like method to WorkHorseForCollatorDatatype. This will avoid the code duplication and will keep the code in one central place. In addition, I have added a new interface called CollationElementsInterface. This interface should be mplemented by all the non-default collation implementation subclasses. The methods defined in the interface will be used by the like method(and other collation methods in future) in WorkHorseForCollatorDatatype. These new non-default collation implementations for all the char datatypes are not hooked into Derby at query compile phase and hence they do not currently get used. More code to follow later to make these classes active in Derby. One other change in this package is to remove the formatid for CollatorSQLChar. These formatid changes for CollatorSQLChar went into revision 516864. But since then, we have changed the design and rather than adding new datatypes for non-default collation implementations, we will simply associate a RuleBasedCollator with them and this collator will get used during collation at runtime. Because of this design change, I am removing the changes related to new formatid that went in revision 516864. This impacts RegisteredFormatIds.java, StoredFormatIds.java and CollatorSQLChar.java Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java (with props) db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (with props) db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java (with props) db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java (with props) db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java (with props) Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DTSClassInfo.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java?view=diff&rev=524545&r1=524544&r2=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java Sat Mar 31 23:41:00 2007 @@ -527,8 +527,5 @@ /* 463 */ "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo", /* 464 */ "org.apache.derby.iapi.types.SqlXmlUtil", /* 465 */ "org.apache.derby.impl.store.raw.data.CompressSpacePageOperation", - - /// --- For CollatorSQLChar - /* 466 */ "org.apache.derby.iapi.types.DTSClassInfo", //InstanceGetter }; } Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java?view=diff&rev=524545&r1=524544&r2=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java Sat Mar 31 23:41:00 2007 @@ -1474,9 +1474,6 @@ public static final int SQL_INTEGER_ID = (MIN_ID_2 + 80); - - static public final int SQL_CHAR_WITH_NON_DEFAULT_COLLATION_ID = - (MIN_ID_2 + 466); public static final int SQL_REAL_ID = (MIN_ID_2 + 81); @@ -1866,7 +1863,7 @@ * Make sure this is updated when a new module is added */ public static final int MAX_ID_2 = - (MIN_ID_2 + 466); + (MIN_ID_2 + 465); // DO NOT USE 4 BYTE IDS ANYMORE static public final int MAX_ID_4 = Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java?view=auto&rev=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java (added) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java Sat Mar 31 23:41:00 2007 @@ -0,0 +1,52 @@ +/* + + Derby - Class org.apache.derby.iapi.types.CollationElementsInterface + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derby.iapi.types; + +import org.apache.derby.iapi.error.StandardException; + +/** + * CollationElementsInterface is an interface which will be implemented by + * all the Collator sensitive char data types. These methods will be called by + * WorkHorseForCollatorDatatypes's collation sensitive methods + * "like, stringcompare" etc. + */ +public interface CollationElementsInterface +{ + /** + * This method translates the string into a series of collation elements. + * These elements will get used in the like method. + * + * @return an array of collation elements for the string + * @throws StandardException + */ + public int[] getCollationElementsForString() throws StandardException; + + /** + * This method returns the count of collation elements for this instance of + * CollationElementsInterface. This method will return the correct value only if + * method getCollationElementsForString has been called previously on this + * instance of CollationElementsInterface. + * + * @return count of collation elements for this instance of CollatorSQLChar + */ + public int getCountOfCollationElements(); +} Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java ------------------------------------------------------------------------------ svn:eol-style = native 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=524545&r1=524544&r2=524545 ============================================================================== --- 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 Sat Mar 31 23:41:00 2007 @@ -21,15 +21,10 @@ package org.apache.derby.iapi.types; -import org.apache.derby.iapi.types.DataValueDescriptor; -import org.apache.derby.iapi.types.BooleanDataValue; - -import org.apache.derby.iapi.services.io.StoredFormatIds; - import org.apache.derby.iapi.error.StandardException; + import org.apache.derby.iapi.services.sanity.SanityManager; -import java.text.CollationElementIterator; import java.text.RuleBasedCollator; /** @@ -41,25 +36,13 @@ * * In Derby 10.3, this class will be passed a RuleBasedCollator which is based * on the database's territory. In future releases of Derby, this class can be - * used to do other kinds of collation like case-insensitive collation etc by + * used to do other kinds of collations like case-insensitive collation etc by * just passing an appropriate RuleBasedCollator object for that kind of * collation. */ -public class CollatorSQLChar extends SQLChar +public class CollatorSQLChar extends SQLChar implements CollationElementsInterface { - /** Use this object for collation on character datatypes */ - RuleBasedCollator collatorForCharacterDatatypes; - /** - * Following is the array holding a series of collation elements for the - * string. It will be used in the like method - */ - private int[] collationElementsForString; - /** - * Number of valid collation elements in the array above. Note that this - * might be smaller than the actual size of the array above - */ - private int countOfCollationElements; - + WorkHorseForCollatorDatatypes holderForCollationSensitiveInfo; /* * constructors */ @@ -74,7 +57,8 @@ public CollatorSQLChar(String val, RuleBasedCollator collatorForCharacterDatatypes) { super(val); - this.collatorForCharacterDatatypes = collatorForCharacterDatatypes; + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); } /** @@ -83,105 +67,20 @@ */ private void setCollator(RuleBasedCollator collatorForCharacterDatatypes) { - this.collatorForCharacterDatatypes = collatorForCharacterDatatypes; - } - - /** - * This method translates the string into a series of collation elements. - * These elements will get used in the like method. - * - * @return an array of collation elements for the string - * @throws StandardException - */ - private int[] getCollationElementsForString() - throws StandardException - { - if (isNull()) - { - return (int[]) null; - } - - if (collationElementsForString != null) - { - return collationElementsForString; - } - - // countOfCollationElements should always be 0 when collationElementsForString is null - if (SanityManager.DEBUG) - { - if (countOfCollationElements != 0) - { - SanityManager.THROWASSERT( - "countOfCollationElements expected to be 0, not " + countOfCollationElements); - } - } - - collationElementsForString = new int[getLength()]; - - CollationElementIterator cei = collatorForCharacterDatatypes.getCollationElementIterator(getString()); - int nextInt; - while ((nextInt = cei.next()) != CollationElementIterator.NULLORDER) - { - /* Believe it or not, a String might have more - * collation elements than characters. - * So, we handle that case by increasing the int array - * by 5 and copying array elements. - */ - if (countOfCollationElements == collationElementsForString.length) - { - int[] expandedArray = new int[countOfCollationElements + 5]; - System.arraycopy(collationElementsForString, 0, expandedArray, - 0, collationElementsForString.length); - collationElementsForString = expandedArray; - } - collationElementsForString[countOfCollationElements++] = nextInt; - } - - return collationElementsForString; + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); } - - - /** - * This method returns the count of collation elements for this instance of - * CollatorSQLChar. This method will return the correct value only if - * method getCollationElementsForString has been called previously on this - * instance of CollatorSQLChar. - * - * @return count of collation elements for this instance of CollatorSQLChar - */ - private int getCountOfCollationElements() + + /** @see CollationElementsInterface#getCollationElementsForString */ + public int[] getCollationElementsForString() throws StandardException { - return countOfCollationElements; + return holderForCollationSensitiveInfo.getCollationElementsForString(); } - /** - * This method implements the like function for char (with no escape value). - * The difference in this method and the same method in superclass is that - * here we use special Collator object to do the comparison rather than - * using the Collator object associated with the default jvm locale. - * - * @param pattern The pattern to use - * - * @return A SQL boolean value telling whether the first operand is - * like the second operand - * - * @exception StandardException Thrown on error - */ - public BooleanDataValue like(DataValueDescriptor pattern) - throws StandardException + /** @see CollationElementsInterface#getCountOfCollationElements */ + public int getCountOfCollationElements() { - Boolean likeResult; - - CollatorSQLChar patternSQLChar = (CollatorSQLChar) pattern; - likeResult = Like.like(getCollationElementsForString(), - getCountOfCollationElements(), - patternSQLChar.getCollationElementsForString(), - patternSQLChar.getCountOfCollationElements(), - collatorForCharacterDatatypes); - - return SQLBoolean.truthValue(this, - pattern, - likeResult); + return holderForCollationSensitiveInfo.getCountOfCollationElements(); } /* @@ -195,7 +94,8 @@ { try { - return new CollatorSQLChar(getString(), collatorForCharacterDatatypes); + return new CollatorSQLChar(getString(), + holderForCollationSensitiveInfo.getCollatorForCollation()); } catch (StandardException se) { @@ -211,18 +111,27 @@ public DataValueDescriptor getNewNull() { CollatorSQLChar result = new CollatorSQLChar(); - result.setCollator(collatorForCharacterDatatypes); + result.setCollator( + holderForCollationSensitiveInfo.getCollatorForCollation()); return result; } - /* - * Storable interface - */ - /** - * @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId - */ - public int getTypeFormatId() { - return StoredFormatIds.SQL_CHAR_WITH_NON_DEFAULT_COLLATION_ID; + * This method implements the like function for char (with no escape value). + * The difference in this method and the same method in superclass is that + * here we use special Collator object to do the comparison rather than + * using the Collator object associated with the default jvm locale. + * + * @param pattern The pattern to use + * + * @return A SQL boolean value telling whether the first operand is + * like the second operand + * + * @exception StandardException Thrown on error + */ + public BooleanDataValue like(DataValueDescriptor pattern) + throws StandardException + { + return(holderForCollationSensitiveInfo.like(pattern)); } } Added: 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=auto&rev=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (added) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java Sat Mar 31 23:41:00 2007 @@ -0,0 +1,137 @@ +/* + + Derby - Class org.apache.derby.iapi.types.CollatorSQLClob + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derby.iapi.types; + +import org.apache.derby.iapi.error.StandardException; +import org.apache.derby.iapi.services.sanity.SanityManager; + +import java.text.RuleBasedCollator; + +/** + * CollatorSQLClob class differs from SQLClob based on how the 2 classes + * use different collations to collate their data. SQLClob uses Derby's + * default collation which is UCS_BASIC. Whereas, this class uses the + * RuleBasedCollator object that was passed to it in it's constructor and that + * RuleBasedCollator object decides the collation. + * + * In Derby 10.3, this class will be passed a RuleBasedCollator which is based + * on the database's territory. In future releases of Derby, this class can be + * used to do other kinds of collations like case-insensitive collation etc by + * just passing an appropriate RuleBasedCollator object for that kind of + * collation. + */ +public class CollatorSQLClob extends SQLClob implements CollationElementsInterface +{ + WorkHorseForCollatorDatatypes holderForCollationSensitiveInfo; + + /* + * constructors + */ + + /** + no-arg constructor, required by Formattable. + */ + public CollatorSQLClob() + { + } + + public CollatorSQLClob(String val, RuleBasedCollator collatorForCharacterDatatypes) + { + super(val); + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); + } + + /** + * Set the RuleBasedCollator for this instance of CollatorSQLClob. It will + * be used to do the collation. + */ + private void setCollator(RuleBasedCollator collatorForCharacterDatatypes) + { + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); + } + + /** @see CollationElementsInterface#getCollationElementsForString */ + public int[] getCollationElementsForString() throws StandardException + { + return holderForCollationSensitiveInfo.getCollationElementsForString(); + } + + /** @see CollationElementsInterface#getCountOfCollationElements */ + public int getCountOfCollationElements() + { + return holderForCollationSensitiveInfo.getCountOfCollationElements(); + } + + /* + * DataValueDescriptor interface + */ + + /** + * @see DataValueDescriptor#getClone + */ + public DataValueDescriptor getClone() + { + try + { + return new CollatorSQLClob(getString(), + holderForCollationSensitiveInfo.getCollatorForCollation()); + } + catch (StandardException se) + { + if (SanityManager.DEBUG) + SanityManager.THROWASSERT("Unexpected exception " + se); + return null; + } + } + + /** + * @see DataValueDescriptor#getNewNull + */ + public DataValueDescriptor getNewNull() + { + CollatorSQLClob result = new CollatorSQLClob(); + result.setCollator( + holderForCollationSensitiveInfo.getCollatorForCollation()); + return result; + } + + /** + * This method implements the like function for char (with no escape value). + * The difference in this method and the same method in superclass is that + * here we use special Collator object to do the comparison rather than + * using the Collator object associated with the default jvm locale. + * + * @param pattern The pattern to use + * + * @return A SQL boolean value telling whether the first operand is + * like the second operand + * + * @exception StandardException Thrown on error + */ + public BooleanDataValue like(DataValueDescriptor pattern) + throws StandardException + { + return(holderForCollationSensitiveInfo.like(pattern)); + } +} Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=auto&rev=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java (added) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java Sat Mar 31 23:41:00 2007 @@ -0,0 +1,137 @@ +/* + + Derby - Class org.apache.derby.iapi.types.CollatorSQLLongvarchar + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derby.iapi.types; + +import org.apache.derby.iapi.error.StandardException; +import org.apache.derby.iapi.services.sanity.SanityManager; + +import java.text.RuleBasedCollator; + +/** + * CollatorSQLLongvarchar class differs from SQLLongvarchar based on how the 2 classes + * use different collations to collate their data. SQLLongvarchar uses Derby's + * default collation which is UCS_BASIC. Whereas, this class uses the + * RuleBasedCollator object that was passed to it in it's constructor and that + * RuleBasedCollator object decides the collation. + * + * In Derby 10.3, this class will be passed a RuleBasedCollator which is based + * on the database's territory. In future releases of Derby, this class can be + * used to do other kinds of collations like case-insensitive collation etc by + * just passing an appropriate RuleBasedCollator object for that kind of + * collation. + */ +public class CollatorSQLLongvarchar extends SQLLongvarchar implements CollationElementsInterface +{ + WorkHorseForCollatorDatatypes holderForCollationSensitiveInfo; + + /* + * constructors + */ + + /** + no-arg constructor, required by Formattable. + */ + public CollatorSQLLongvarchar() + { + } + + public CollatorSQLLongvarchar(String val, RuleBasedCollator collatorForCharacterDatatypes) + { + super(val); + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); + } + + /** + * Set the RuleBasedCollator for this instance of CollatorSQLLongvarchar. + * It will be used to do the collation. + */ + private void setCollator(RuleBasedCollator collatorForCharacterDatatypes) + { + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); + } + + /** @see CollationElementsInterface#getCollationElementsForString */ + public int[] getCollationElementsForString() throws StandardException + { + return holderForCollationSensitiveInfo.getCollationElementsForString(); + } + + /** @see CollationElementsInterface#getCountOfCollationElements */ + public int getCountOfCollationElements() + { + return holderForCollationSensitiveInfo.getCountOfCollationElements(); + } + + /* + * DataValueDescriptor interface + */ + + /** + * @see DataValueDescriptor#getClone + */ + public DataValueDescriptor getClone() + { + try + { + return new CollatorSQLLongvarchar(getString(), + holderForCollationSensitiveInfo.getCollatorForCollation()); + } + catch (StandardException se) + { + if (SanityManager.DEBUG) + SanityManager.THROWASSERT("Unexpected exception " + se); + return null; + } + } + + /** + * @see DataValueDescriptor#getNewNull + */ + public DataValueDescriptor getNewNull() + { + CollatorSQLLongvarchar result = new CollatorSQLLongvarchar(); + result.setCollator( + holderForCollationSensitiveInfo.getCollatorForCollation()); + return result; + } + + /** + * This method implements the like function for char (with no escape value). + * The difference in this method and the same method in superclass is that + * here we use special Collator object to do the comparison rather than + * using the Collator object associated with the default jvm locale. + * + * @param pattern The pattern to use + * + * @return A SQL boolean value telling whether the first operand is + * like the second operand + * + * @exception StandardException Thrown on error + */ + public BooleanDataValue like(DataValueDescriptor pattern) + throws StandardException + { + return(holderForCollationSensitiveInfo.like(pattern)); + } +} Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=auto&rev=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java (added) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java Sat Mar 31 23:41:00 2007 @@ -0,0 +1,137 @@ +/* + + Derby - Class org.apache.derby.iapi.types.CollatorSQLVarchar + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derby.iapi.types; + +import org.apache.derby.iapi.error.StandardException; +import org.apache.derby.iapi.services.sanity.SanityManager; + +import java.text.RuleBasedCollator; + +/** + * CollatorSQLVarchar class differs from SQLVarchar based on how the 2 classes + * use different collations to collate their data. SQLVarchar uses Derby's + * default collation which is UCS_BASIC. Whereas, this class uses the + * RuleBasedCollator object that was passed to it in it's constructor and that + * RuleBasedCollator object decides the collation. + * + * In Derby 10.3, this class will be passed a RuleBasedCollator which is based + * on the database's territory. In future releases of Derby, this class can be + * used to do other kinds of collations like case-insensitive collation etc by + * just passing an appropriate RuleBasedCollator object for that kind of + * collation. + */ +public class CollatorSQLVarchar extends SQLVarchar implements CollationElementsInterface +{ + WorkHorseForCollatorDatatypes holderForCollationSensitiveInfo; + + /* + * constructors + */ + + /** + no-arg constructor, required by Formattable. + */ + public CollatorSQLVarchar() + { + } + + public CollatorSQLVarchar(String val, RuleBasedCollator collatorForCharacterDatatypes) + { + super(val); + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); + } + + /** + * Set the RuleBasedCollator for this instance of CollatorSQLVarchar. It will + * be used to do the collation. + */ + private void setCollator(RuleBasedCollator collatorForCharacterDatatypes) + { + holderForCollationSensitiveInfo = + new WorkHorseForCollatorDatatypes(collatorForCharacterDatatypes, this); + } + + /** @see CollationElementsInterface#getCollationElementsForString */ + public int[] getCollationElementsForString() throws StandardException + { + return holderForCollationSensitiveInfo.getCollationElementsForString(); + } + + /** @see CollationElementsInterface#getCountOfCollationElements */ + public int getCountOfCollationElements() + { + return holderForCollationSensitiveInfo.getCountOfCollationElements(); + } + + /* + * DataValueDescriptor interface + */ + + /** + * @see DataValueDescriptor#getClone + */ + public DataValueDescriptor getClone() + { + try + { + return new CollatorSQLVarchar(getString(), + holderForCollationSensitiveInfo.getCollatorForCollation()); + } + catch (StandardException se) + { + if (SanityManager.DEBUG) + SanityManager.THROWASSERT("Unexpected exception " + se); + return null; + } + } + + /** + * @see DataValueDescriptor#getNewNull + */ + public DataValueDescriptor getNewNull() + { + CollatorSQLVarchar result = new CollatorSQLVarchar(); + result.setCollator( + holderForCollationSensitiveInfo.getCollatorForCollation()); + return result; + } + + /** + * This method implements the like function for char (with no escape value). + * The difference in this method and the same method in superclass is that + * here we use special Collator object to do the comparison rather than + * using the Collator object associated with the default jvm locale. + * + * @param pattern The pattern to use + * + * @return A SQL boolean value telling whether the first operand is + * like the second operand + * + * @exception StandardException Thrown on error + */ + public BooleanDataValue like(DataValueDescriptor pattern) + throws StandardException + { + return(holderForCollationSensitiveInfo.like(pattern)); + } +} Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DTSClassInfo.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DTSClassInfo.java?view=diff&rev=524545&r1=524544&r2=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DTSClassInfo.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DTSClassInfo.java Sat Mar 31 23:41:00 2007 @@ -59,8 +59,6 @@ case StoredFormatIds.SQL_CLOB_ID: return new SQLClob(); case StoredFormatIds.SQL_NCLOB_ID: return new SQLNClob(); case StoredFormatIds.XML_ID: return new XML(); - case StoredFormatIds.SQL_CHAR_WITH_NON_DEFAULT_COLLATION_ID: - return new CollatorSQLChar(); /* Type ids */ case StoredFormatIds.BIT_TYPE_ID: Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java?view=auto&rev=524545 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java (added) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java Sat Mar 31 23:41:00 2007 @@ -0,0 +1,191 @@ +/* + + Derby - Class org.apache.derby.iapi.types.WorkHorseForCollatorDatatypes + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derby.iapi.types; + +import org.apache.derby.iapi.types.DataValueDescriptor; +import org.apache.derby.iapi.types.BooleanDataValue; + +import org.apache.derby.iapi.services.io.StoredFormatIds; + +import org.apache.derby.iapi.error.StandardException; +import org.apache.derby.iapi.services.sanity.SanityManager; + +import java.text.CollationElementIterator; +import java.text.RuleBasedCollator; + +/** + * WorkHorseForCollatorDatatypes class holds on to RuleBasedCollator, + * and the base SQLChar object for the collation sensitive SQLChar, + * SQLVarchar, SQLLongvarchar and SQLClob. This class uses RuleBasedCollator + * and SQLChar object in the collation sensitive methods to do the comparison. + * The reason for encapsulating this here is that the collation version of + * SQLChar, SQLVarchar, SQLLongvarchar and SQLClob do not all have to duplicate + * the code for collation sensitive methods. Instead, they can simply delegate + * the work to methods defined in this class. + */ +public class WorkHorseForCollatorDatatypes +{ + /** + * Use this object for collation on character datatype. This collator + * object is passed as a parameter to the constructor. + */ + RuleBasedCollator collatorForCharacterDatatypes; + /** + * collatorForCharacterDatatypes will be used on this SQLChar to determine + * collationElementsForString. The collationElementsForString is used by + * the like method to do Collator specific comparison. + * This SQLChar object is passed as a parameter to the constructor. + */ + SQLChar stringData; + /** + * Following is the array holding a series of collation elements for the + * string. It will be used in the like method. This gets initialized when + * the like method is first invoked. + */ + private int[] collationElementsForString; + /** + * Number of valid collation elements in the array above. Note that this + * might be smaller than the actual size of the array above. Gets + * initialized when the like method is first invoked. + */ + private int countOfCollationElements; + + public WorkHorseForCollatorDatatypes( + RuleBasedCollator collatorForCharacterDatatypes, + SQLChar stringData) + { + this.collatorForCharacterDatatypes = collatorForCharacterDatatypes; + this.stringData = stringData; + } + + /** + * This method implements the like function for char (with no escape value). + * The difference in this method and the same method in SQLChar is that + * here we use special Collator object to do the comparison rather than + * using the Collator object associated with the default jvm locale. + * + * @param pattern The pattern to use + * + * @return A SQL boolean value telling whether the first operand is + * like the second operand + * + * @exception StandardException Thrown on error + */ + public BooleanDataValue like(DataValueDescriptor pattern) + throws StandardException + { + Boolean likeResult; + + if (SanityManager.DEBUG) + SanityManager.ASSERT( + pattern instanceof CollationElementsInterface, + "Both the operands must be instances of CollationElementsInterface"); + CollationElementsInterface patternToCheck = (CollationElementsInterface) pattern; + likeResult = Like.like( + getCollationElementsForString(), + getCountOfCollationElements(), + patternToCheck.getCollationElementsForString(), + patternToCheck.getCountOfCollationElements(), + collatorForCharacterDatatypes); + + return SQLBoolean.truthValue(stringData, + pattern, + likeResult); + } + + /** + * Get the RuleBasedCollator which is getting used for collation sensitive + * methods. + */ + protected RuleBasedCollator getCollatorForCollation() + { + return(collatorForCharacterDatatypes); + } + + /** + * This method returns the count of collation elements for SQLChar object. + * It method will return the correct value only if method + * getCollationElementsForString has been called previously on the SQLChar + * object. + * + * @return count of collation elements for this instance of CollatorSQLChar + */ + protected int getCountOfCollationElements() + { + return countOfCollationElements; + } + + /** + * This method translates the string into a series of collation elements. + * These elements will get used in the like method. + * + * @return an array of collation elements for the string + * @throws StandardException + */ + protected int[] getCollationElementsForString() + throws StandardException + { + if (stringData.isNull()) + { + return (int[]) null; + } + + if (collationElementsForString != null) + { + return collationElementsForString; + } + + // countOfCollationElements should always be 0 when collationElementsForString is null + if (SanityManager.DEBUG) + { + if (countOfCollationElements != 0) + { + SanityManager.THROWASSERT( + "countOfCollationElements expected to be 0, not " + countOfCollationElements); + } + } + + collationElementsForString = new int[stringData.getLength()]; + + CollationElementIterator cei = collatorForCharacterDatatypes.getCollationElementIterator( + stringData.getString()); + int nextInt; + while ((nextInt = cei.next()) != CollationElementIterator.NULLORDER) + { + /* Believe it or not, a String might have more + * collation elements than characters. + * So, we handle that case by increasing the int array + * by 5 and copying array elements. + */ + if (countOfCollationElements == collationElementsForString.length) + { + int[] expandedArray = new int[countOfCollationElements + 5]; + System.arraycopy(collationElementsForString, 0, expandedArray, + 0, collationElementsForString.length); + collationElementsForString = expandedArray; + } + collationElementsForString[countOfCollationElements++] = nextInt; + } + + return collationElementsForString; + } +} Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java ------------------------------------------------------------------------------ svn:eol-style = native