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 ka...@apache.org on 2010/03/30 14:43:00 UTC
svn commit: r929111 - in /db/derby/code/trunk/java:
engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/iapi/types/
engine/org/apache/derby/impl/sql/catalog/
engine/org/apache/derby/impl/sql/compile/
testing/org/apache/derbyTesting/function...
Author: kahatlen
Date: Tue Mar 30 12:42:59 2010
New Revision: 929111
URL: http://svn.apache.org/viewvc?rev=929111&view=rev
Log:
DERBY-1748: Global case insensitive setting
Patch contributed by Gunnar Grim.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.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/DataValueFactoryImpl.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java?rev=929111&r1=929110&r2=929111&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java Tue Mar 30 12:42:59 2010
@@ -915,13 +915,22 @@ public interface Property {
public static final String SERVICE_LOCALE = "derby.serviceLocale";
public static final String COLLATION = "derby.database.collation";
- // These are the 2 possible values for collation type if the collation
+ // These are the six possible values for collation type if the collation
// derivation is not NONE. If collation derivation is NONE, then collation
- // type should be ignored.
+ // type should be ignored. The TERRITORY_BASED collation uses the default
+ // collator strength while the four with a colon uses a specific strength.
public static final String UCS_BASIC_COLLATION =
"UCS_BASIC";
public static final String TERRITORY_BASED_COLLATION =
"TERRITORY_BASED";
+ public static final String TERRITORY_BASED_PRIMARY_COLLATION =
+ "TERRITORY_BASED:PRIMARY";
+ public static final String TERRITORY_BASED_SECONDARY_COLLATION =
+ "TERRITORY_BASED:SECONDARY";
+ public static final String TERRITORY_BASED_TERTIARY_COLLATION =
+ "TERRITORY_BASED:TERTIARY";
+ public static final String TERRITORY_BASED_IDENTICAL_COLLATION =
+ "TERRITORY_BASED:IDENTICAL";
// Define a static string for collation derivation NONE
public static final String COLLATION_NONE =
"NONE";
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=929111&r1=929110&r2=929111&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 Tue Mar 30 12:42:59 2010
@@ -1090,13 +1090,27 @@ public final class DataTypeDescriptor im
}
/**
- * Gets the name of this datatype.
- * <p>
- * Used to generate strings decribing collation type for error messages.
- *
- *
- * @return the name of the collation being used in this type.
- */
+ * Obtain the collation type from a collation property value.
+ * @return The collation type, or -1 if not recognized.
+ */
+ public static int getCollationType(String collationName)
+ {
+ if (collationName.equalsIgnoreCase(Property.UCS_BASIC_COLLATION))
+ return StringDataValue.COLLATION_TYPE_UCS_BASIC;
+ else if (collationName.equalsIgnoreCase(Property.TERRITORY_BASED_COLLATION))
+ return StringDataValue.COLLATION_TYPE_TERRITORY_BASED;
+ else if (collationName.equalsIgnoreCase(Property.TERRITORY_BASED_PRIMARY_COLLATION))
+ return StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY;
+ else if (collationName.equalsIgnoreCase(Property.TERRITORY_BASED_SECONDARY_COLLATION))
+ return StringDataValue.COLLATION_TYPE_TERRITORY_BASED_SECONDARY;
+ else if (collationName.equalsIgnoreCase(Property.TERRITORY_BASED_TERTIARY_COLLATION))
+ return StringDataValue.COLLATION_TYPE_TERRITORY_BASED_TERTIARY;
+ else if (collationName.equalsIgnoreCase(Property.TERRITORY_BASED_IDENTICAL_COLLATION))
+ return StringDataValue.COLLATION_TYPE_TERRITORY_BASED_IDENTICAL;
+ else
+ return -1;
+ }
+
/**
* Gets the name of the collation type in this descriptor if the collation
* derivation is not NONE. If the collation derivation is NONE, then this
@@ -1110,15 +1124,36 @@ public final class DataTypeDescriptor im
*/
public String getCollationName()
{
- return(
- getCollationDerivation() == StringDataValue.COLLATION_DERIVATION_NONE ?
- Property.COLLATION_NONE :
- getCollationType() == StringDataValue.COLLATION_TYPE_UCS_BASIC ?
- Property.UCS_BASIC_COLLATION :
- Property.TERRITORY_BASED_COLLATION);
+ if (getCollationDerivation() == StringDataValue.COLLATION_DERIVATION_NONE)
+ return Property.COLLATION_NONE;
+ else
+ return getCollationName(getCollationType());
}
/**
+ * Gets the name of the specified collation type.
+ * @param collationType The collation type.
+ * @return The name, e g "TERRITORY_BASED:PRIMARY".
+ */
+ public static String getCollationName(int collationType)
+ {
+ switch (collationType) {
+ case StringDataValue.COLLATION_TYPE_TERRITORY_BASED :
+ return Property.TERRITORY_BASED_COLLATION;
+ case StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY :
+ return Property.TERRITORY_BASED_PRIMARY_COLLATION;
+ case StringDataValue.COLLATION_TYPE_TERRITORY_BASED_SECONDARY :
+ return Property.TERRITORY_BASED_SECONDARY_COLLATION;
+ case StringDataValue.COLLATION_TYPE_TERRITORY_BASED_TERTIARY :
+ return Property.TERRITORY_BASED_TERTIARY_COLLATION;
+ case StringDataValue.COLLATION_TYPE_TERRITORY_BASED_IDENTICAL :
+ return Property.TERRITORY_BASED_IDENTICAL_COLLATION;
+ default :
+ return Property.UCS_BASIC_COLLATION;
+ }
+ }
+
+ /**
* Get the collation derivation for this type. This applies only for
* character string types. For the other types, this api should be
* ignored.
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java?rev=929111&r1=929110&r2=929111&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java Tue Mar 30 12:42:59 2010
@@ -150,13 +150,17 @@ abstract class DataValueFactoryImpl impl
//If the user has requested for territory based database, then
//verify that JVM has Collator support for the database locale.
String userDefinedCollation =
- properties.getProperty(Attribute.COLLATION);
+ properties.getProperty(Attribute.COLLATION);
if (userDefinedCollation != null) {//Invalid value handling
- if (!userDefinedCollation.equalsIgnoreCase(Property.UCS_BASIC_COLLATION)
- && !userDefinedCollation.equalsIgnoreCase(Property.TERRITORY_BASED_COLLATION))
- throw StandardException.newException(SQLState.INVALID_COLLATION, userDefinedCollation);
- if (userDefinedCollation.equalsIgnoreCase(Property.TERRITORY_BASED_COLLATION))
- collatorForCharacterTypes = verifyCollatorSupport();
+ int collationType = DataTypeDescriptor.getCollationType(userDefinedCollation);
+ if (collationType != StringDataValue.COLLATION_TYPE_UCS_BASIC) {
+ if (collationType >= StringDataValue.COLLATION_TYPE_TERRITORY_BASED
+ && collationType < StringDataValue.COLLATION_TYPE_TERRITORY_BASED_IDENTICAL) {
+ int strength = collationType - StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY;
+ collatorForCharacterTypes = verifyCollatorSupport(strength);
+ } else
+ throw StandardException.newException(SQLState.INVALID_COLLATION, userDefinedCollation);
+ }
}
}
}
@@ -1047,7 +1051,9 @@ abstract class DataValueFactoryImpl impl
//This is the first access to Collator because otherwise
//it will not be null. Verify that JVM has support for
//the Collator for the database locale.
- collatorForCharacterTypes = verifyCollatorSupport();
+ // Calculate the collator strength. COLLATION_TYPE_TERRITORY_BASED use strength -1, i e unspecified.
+ int strength = collationType - StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY;
+ collatorForCharacterTypes = verifyCollatorSupport(strength);
return collatorForCharacterTypes;
} else
return collatorForCharacterTypes;
@@ -1055,11 +1061,12 @@ abstract class DataValueFactoryImpl impl
/**
* Verify that JVM has support for the Collator for the datbase's locale.
- *
+ *
+ * @param strength Collator strength or -1 for locale default.
* @return Collator for database's locale
* @throws StandardException if JVM does not have support for Collator
*/
- private RuleBasedCollator verifyCollatorSupport()
+ private RuleBasedCollator verifyCollatorSupport(int strength)
throws StandardException {
Locale[] availLocales = Collator.getAvailableLocales();
//Verify that Collator can be instantiated for the given locale.
@@ -1076,7 +1083,12 @@ abstract class DataValueFactoryImpl impl
SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE,
databaseLocale.toString());
- return (RuleBasedCollator) Collator.getInstance(databaseLocale);
+ RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);
+
+ if (strength != -1)
+ collator.setStrength(strength);
+
+ return collator;
}
/**
* @see DataValueFactory#getNull(int, int)
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?rev=929111&r1=929110&r2=929111&view=diff
==============================================================================
--- 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 Tue Mar 30 12:42:59 2010
@@ -59,14 +59,21 @@ public interface StringDataValue extends
* belonging to user tables will have collation type of TERRITORY_BASED.
*
* Data types will start with collation type defaulting to UCS_BASIC in
- * TypeDescriptorImpl. This collation type ofcourse makes sense fpr
+ * TypeDescriptorImpl. This collation type of course makes sense for
* character string types only. It will be ignored for the rest of the
* types. If a character's collation type should be TERRITORY_BASED, then
* DTD.setCollationType can be called to change the default of UCS_BASIC.
+ *
+ * The collation types TERRITORY_BASED:PRIMARY through TERRITORY_BASED:IDENTICAL
+ * are variants of the TERRITORY_BASED type, with explicit collation strength.
*/
public static final int COLLATION_TYPE_UCS_BASIC = 0;
/** @see StringDataValue#COLLATION_TYPE_UCS_BASIC */
public static final int COLLATION_TYPE_TERRITORY_BASED = 1;
+ public static final int COLLATION_TYPE_TERRITORY_BASED_PRIMARY = 2;
+ public static final int COLLATION_TYPE_TERRITORY_BASED_SECONDARY = 3;
+ public static final int COLLATION_TYPE_TERRITORY_BASED_TERTIARY = 4;
+ public static final int COLLATION_TYPE_TERRITORY_BASED_IDENTICAL = 5;
/**
* The SQL concatenation '||' operator.
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=929111&r1=929110&r2=929111&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Tue Mar 30 12:42:59 2010
@@ -708,12 +708,11 @@ public final class DataDictionaryImpl
Property.COLLATION, Property.UCS_BASIC_COLLATION);
}
- //Initialize the collation type of user schemas after looking at
+ //Initialize the collation type of user schemas by looking at
//collation property/attribute.
- if (userDefinedCollation.equalsIgnoreCase(Property.UCS_BASIC_COLLATION))
- collationTypeOfUserSchemas = StringDataValue.COLLATION_TYPE_UCS_BASIC;
- else
- collationTypeOfUserSchemas = StringDataValue.COLLATION_TYPE_TERRITORY_BASED;
+ collationTypeOfUserSchemas = DataTypeDescriptor.getCollationType(userDefinedCollation);
+ if (SanityManager.DEBUG)
+ SanityManager.ASSERT((collationTypeOfUserSchemas != -1), "Invalid collation type: "+userDefinedCollation);
//Now is also a good time to create schema descriptor for global
//temporary tables. Since this is a user schema, it should use the
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java?rev=929111&r1=929110&r2=929111&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java Tue Mar 30 12:42:59 2010
@@ -356,15 +356,10 @@ public class CreateTableNode extends DDL
if (dtd.getTypeId().isStringTypeId() &&
dtd.getCollationType() != schemaCollationType)
{
- String schemaCollationName =
- (schemaCollationType ==
- StringDataValue.COLLATION_TYPE_UCS_BASIC ?
- Property.UCS_BASIC_COLLATION :
- Property.TERRITORY_BASED_COLLATION);
throw StandardException.newException(
SQLState.LANG_CAN_NOT_CREATE_TABLE,
dtd.getCollationName(),
- schemaCollationName);
+ DataTypeDescriptor.getCollationName(schemaCollationType));
}
ColumnDefinitionNode column = (ColumnDefinitionNode) getNodeFactory().getNode
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=929111&r1=929110&r2=929111&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java Tue Mar 30 12:42:59 2010
@@ -480,7 +480,7 @@ public void testNorwayCollation() throws
/**
* Test order by with English collation
- *
+ *
* @throws SQLException
*/
public void testEnglishCollation() throws SQLException {
@@ -490,13 +490,13 @@ public void testEnglishCollation() throw
setUpTable(s);
//The collation should be TERRITORY_BASED for this database
- checkLangBasedQuery(s,
+ checkLangBasedQuery(s,
"VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY('derby.database.collation')",
new String[][] {{"TERRITORY_BASED"}});
checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER ORDER BY NAME",
new String[][] {{"6","aacorn"},{"4","Acorn"},{"2","\u0104corn"},{"0","Smith"},
- {"5","\u015Amith"},{"1","Zebra"},{"3","\u017Bebra"} });
+ {"5","\u015Amith"},{"1","Zebra"},{"3","\u017Bebra"} });
//COMPARISONS INVOLVING CONSTANTS
//In English, 'aacorn' != 'Acorn'
@@ -505,7 +505,7 @@ public void testEnglishCollation() throw
//In English, 'aacorn' is < 'Acorn'
checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' < 'Acorn'",
new String[][] {{"0","Smith"}, {"1","Zebra"}, {"2","\u0104corn"},
- {"3","\u017Bebra"}, {"4","Acorn"}, {"5","\u015Amith"},
+ {"3","\u017Bebra"}, {"4","Acorn"}, {"5","\u015Amith"},
{"6","aacorn"} });
//COMPARISONS INVOLVING CONSTANT and PERSISTENT COLUMN
@@ -513,19 +513,19 @@ public void testEnglishCollation() throw
new String[][] {{"0","Smith"}, {"2","\u0104corn"}, {"4","Acorn"},
{"6","aacorn"} });
checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER WHERE NAME between 'Acorn' and 'Zebra' ",
- new String[][] {{"0","Smith"}, {"1","Zebra"}, {"2","\u0104corn"},
+ new String[][] {{"0","Smith"}, {"1","Zebra"}, {"2","\u0104corn"},
{"4","Acorn"}, {"5","\u015Amith"} });
- //After index creation, the query above will return same data but in
+ //After index creation, the query above will return same data but in
//different order
/*s.executeUpdate("CREATE INDEX CUSTOMER_INDEX1 ON CUSTOMER(NAME)");
s.executeUpdate("INSERT INTO CUSTOMER VALUES (NULL, NULL)");
- checkLangBasedQuery(s,
- "SELECT ID, NAME FROM CUSTOMER -- derby-properties index=customer_index1 \r WHERE NAME between 'Acorn' and " +
+ checkLangBasedQuery(s,
+ "SELECT ID, NAME FROM CUSTOMER -- derby-properties index=customer_index1 \r WHERE NAME between 'Acorn' and " +
" 'Zebra'", //ORDER BY NAME",
- new String[][] {{"4","Acorn"}, {"2","\u0104corn"}, {"0","Smith"},
+ new String[][] {{"4","Acorn"}, {"2","\u0104corn"}, {"0","Smith"},
{"5","\u015Amith"}, {"1","Zebra"} });
*/
- //For collated databases, COMPARISONS OF USER PERSISTENT CHARACTER
+ //For collated databases, COMPARISONS OF USER PERSISTENT CHARACTER
//COLUMN AND CHARACTER CONSTANT WILL FAIL IN SYSTEM SCHEMA.
s.executeUpdate("set schema SYS");
assertStatementError("42818", s, "SELECT ID, NAME FROM APP.CUSTOMER WHERE NAME <= 'Smith' ");
@@ -533,9 +533,67 @@ public void testEnglishCollation() throw
//Do some testing with MAX/MIN operators
s.executeUpdate("set schema APP");
checkLangBasedQuery(s, "SELECT MAX(NAME) maxName FROM CUSTOMER ORDER BY maxName ",
- new String[][] {{"\u017Bebra"}});
+ new String[][] {{"\u017Bebra"}});
checkLangBasedQuery(s, "SELECT MIN(NAME) minName FROM CUSTOMER ORDER BY minName ",
- new String[][] {{"aacorn"}});
+ new String[][] {{"aacorn"}});
+
+ commonTestingForTerritoryBasedDB(s);
+
+ s.close();
+ }
+
+ /**
+ * Test with Swedish case insensitive collation
+ *
+ * @throws SQLException
+ */
+public void testSwedishCaseInsensitiveCollation() throws SQLException {
+
+ getConnection().setAutoCommit(false);
+ Statement s = createStatement();
+ setUpTable(s);
+
+ //The collation should be TERRITORY_BASED for this database
+ checkLangBasedQuery(s,
+ "VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY('derby.database.collation')",
+ new String[][] {{"TERRITORY_BASED:SECONDARY"}});
+
+ checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER ORDER BY NAME",
+ new String[][] {{"6","aacorn"},{"4","Acorn"},{"2","\u0104corn"},{"0","Smith"},
+ {"5","\u015Amith"},{"1","Zebra"},{"3","\u017Bebra"} });
+
+ //COMPARISONS INVOLVING CONSTANTS
+ //In Swedish, 'aacorn' != 'Acorn'
+ checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER where 'aacorn' = 'Acorn' ",
+ null);
+
+ //In case insensitive Swedish, 'aacorn' == 'AaCorn'
+ checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER where NAME = 'AaCorn' ORDER BY NAME ",
+ new String[][] {{"6","aacorn"}});
+
+ //Selection with LIKE
+ checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER where NAME like 'a%'",
+ new String[][] {{"4","Acorn"}, {"6","aacorn"} });
+
+ //COMPARISONS INVOLVING CONSTANT and PERSISTENT COLUMN
+ checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER WHERE NAME <= 'Smith' ",
+ new String[][] {{"0","Smith"}, {"2","\u0104corn"}, {"4","Acorn"},
+ {"6","aacorn"} });
+ checkLangBasedQuery(s, "SELECT ID, NAME FROM CUSTOMER WHERE NAME between 'acorn' and 'zebra' ",
+ new String[][] {{"0","Smith"}, {"1","Zebra"}, {"2","\u0104corn"},
+ {"4","Acorn"}, {"5","\u015Amith"} });
+
+ //For collated databases, COMPARISONS OF USER PERSISTENT CHARACTER
+ //COLUMN AND CHARACTER CONSTANT WILL FAIL IN SYSTEM SCHEMA.
+ s.executeUpdate("set schema SYS");
+ assertStatementError("42818", s, "SELECT ID, NAME FROM APP.CUSTOMER WHERE NAME <= 'Smith' ");
+
+ //Do some testing with MAX/MIN operators
+ s.executeUpdate("set schema APP");
+ checkLangBasedQuery(s, "SELECT MAX(NAME) maxName FROM CUSTOMER ORDER BY maxName ",
+ new String[][] {{"\u017Bebra"}});
+ checkLangBasedQuery(s, "SELECT MIN(NAME) minName FROM CUSTOMER ORDER BY minName ",
+ new String[][] {{"aacorn"}});
commonTestingForTerritoryBasedDB(s);
@@ -1304,7 +1362,7 @@ public void testMissingCollatorSupport()
suite.addTest(new CleanDatabaseTestSetup(
new CollationTest("testDefaultCollation")));
- suite.addTest(collatedSuite("en", "testEnglishCollation"));
+ suite.addTest(collatedSuite("en", false, "testEnglishCollation"));
// Only add tests for other locales if they are in fact supported
// by the jvm.
@@ -1312,6 +1370,7 @@ public void testMissingCollatorSupport()
boolean norwegian = false;
boolean polish = false;
boolean french = false;
+ boolean swedish = false;
for (int i=0; i<availableLocales.length ; i++) {
if("no".equals(availableLocales[i].getLanguage())) {
norwegian = true;
@@ -1322,15 +1381,21 @@ public void testMissingCollatorSupport()
if("fr".equals(availableLocales[i].getLanguage())) {
french = true;
}
+ if("sv".equals(availableLocales[i].getLanguage())) {
+ swedish = true;
+ }
}
if(norwegian) {
- suite.addTest(collatedSuite("no", "testNorwayCollation"));
+ suite.addTest(collatedSuite("no", false, "testNorwayCollation"));
}
if(polish) {
- suite.addTest(collatedSuite("pl", "testPolishCollation"));
+ suite.addTest(collatedSuite("pl", false, "testPolishCollation"));
}
if(french) {
- suite.addTest(collatedSuite("fr", "testFrenchCollation"));
+ suite.addTest(collatedSuite("fr", false, "testFrenchCollation"));
+ }
+ if(swedish) {
+ suite.addTest(collatedSuite("sv", true, "testSwedishCaseInsensitiveCollation"));
}
return suite;
}
@@ -1354,10 +1419,11 @@ public void testMissingCollatorSupport()
* a primary fixture from this test plus potentially other
* fixtures.
* @param locale Locale to use for the database
+ * @param caseInsensitive Indicates if the database should use a case insensitive collation.
* @param baseFixture Base fixture from this test.
* @return suite of tests to run for the given locale
*/
- private static Test collatedSuite(String locale, String baseFixture)
+ private static Test collatedSuite(String locale, boolean caseInsensitive, String baseFixture)
{
TestSuite suite = new TestSuite("CollationTest:territory=" + locale);
suite.addTest(new CollationTest(baseFixture));
@@ -1376,7 +1442,9 @@ public void testMissingCollatorSupport()
suite.addTest(GroupByExpressionTest.suite());
suite.addTest(UpdatableResultSetTest.suite());
}
- return Decorator.territoryCollatedDatabase(suite, locale);
+ return caseInsensitive
+ ? Decorator.territoryCollatedCaseInsensitiveDatabase(suite, locale)
+ : Decorator.territoryCollatedDatabase(suite, locale);
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java?rev=929111&r1=929110&r2=929111&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java Tue Mar 30 12:42:59 2010
@@ -157,6 +157,25 @@ public class Decorator {
}
/**
+ * Decorate a set of tests to use an single
+ * use database with TERRITORY_BASED:SECONDARY collation
+ * set to the passed in locale. Database is created
+ * by the setUp method of the decorator.
+ * @param locale Locale used to set territory JDBC attribute. If null
+ * then only collation=TERRITORY_BASED:SECONDARY will be set.
+ */
+ public static Test territoryCollatedCaseInsensitiveDatabase(Test test, final String locale)
+ {
+
+ String attributes = "collation=TERRITORY_BASED:SECONDARY";
+
+ if (locale != null)
+ attributes = attributes.concat(";territory=" + locale);
+
+ return attributesDatabase(attributes, test);
+ }
+
+ /**
* Decorate a test (or suite of tests) to use a single use database
* as the default database. The database is created by the setUp
* method of the decorator. The database will be created using