db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mamta Satoor" <msat...@gmail.com>
Subject Should COLLATION attribute related code go in BasicDatabase?
Date Tue, 13 Mar 2007 16:42:50 GMT
Hi,

Based on the discussion in DERBY-2336 (Enable collation based ordering for
CHAR data type.), we want to move towards making DataValueFactory keep track
of locale related stuff. In order to move in that direction, I think the
knowledge that user has requested territory based collation should also go
in DataValueFactory.

So, in Derby code, when there is a need to generate a SQLChar datatype for
non-system columns, Derby code can make a call like
DataValueFactory.isCollatorSQLCharRequired and if this call returns true
then the Derby code should call
DataValueFactory.getCollatorCharDataValuerather than
DataValueFactory.getCharDataValue. (Please note that I don't think I can
simply change implementation of DataValueFactory.getCharDataValue to return
either SQLChar or CollatorSQLChar depending on COLLATION attribute because
for char columns from SYS schema, we always want to return SQLChar no matter
what the value of COLLATION attribute is).

Currently, the COLLATION attribute is read in DataDictionary.boot method but
by this time, the DataValueFactory and store has already booted. And the
store code might need to generate SQLChar or CollatorSQLChar before
DataDictionary gets booted. So, before store gets booted, we should let
DataValueFactory know about COLLATION attribute value. To do this, the
COLLATION attribute code should go in BasicDatabase.boot(rather than
DataDictionary.boot) method prior to DataValueFactory is loaded. And once
DataValueFactory is loaded, we should call a method like
DataValueFactory.setTerritoryBasedCollation if user has requested territory
based collation. This way, the information about collator is available in
DataValueFactory right after it has booted.

Following is the prototype code I am proposing in BasicDatabase.boot method
  if (create)
    String userDefinedCollation = startParams.getProperty(
Attribute.COLLATION);
    if (userDefinedCollation == null)
     userDefinedCollation = Property.UCS_BASIC_COLLATION;
    else {//Invalid value handling
     if (!userDefinedCollation.equalsIgnoreCase(Property.UCS_BASIC_COLLATION
)
       && !userDefinedCollation.equalsIgnoreCase(
Property.TERRITORY_BASED_COLLATION))
      throw StandardException.newException(SQLState.INVALID_COLLATION,
userDefinedCollation);
     }
    bootingTC.setProperty(Property.COLLATION,userDefinedCollation,true);
   }
   //Load DataValueFactory module
   if(PropertyUtil.getDatabaseProperty(bootingTC,Property.COLLATION
).equalsIgnoreCase(Property.TERRITORY_BASED_COLLATION))
    dvf.setTerritoryBasedCollation();
   //Load Store module
   //Load DataDictionary module

The prototype code in DataValueFactory will look as follows
        // Class level field which will hold territory based collator if
user has requested one
        RuleBasedCollator ruleBasedCollator;

        public boolean isCollatorSQLCharRequired () {
                return (ruleBasedCollator==null?false:true);
        }
        // this method will be called by BasicDatabase.boot only
if COLLATION attribute is set to territory based collation.
        // If not, then ruleBasedCollator will stay null
        public void setTerritoryBasedCollation() throws StandardException {
                ruleBasedCollator = getLocaleFinder().getCollator();
        }
        // CHAR with special Collator
        public StringDataValue getCollatorCharDataValue(String value)
        {
                return new CollatorSQLChar(value,ruleBasedCollator);
        }

I would appreciate any feedback on my proposal,
Mamta

Mime
View raw message