db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r529697 - in /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types: DataValueFactory.java DataValueFactoryImpl.java
Date Tue, 17 Apr 2007 18:08:50 GMT
Author: mamta
Date: Tue Apr 17 11:08:49 2007
New Revision: 529697

URL: http://svn.apache.org/viewvc?view=rev&rev=529697
Log:
This change provides a new interface on DataValueFactory(DVF) which will be used by Store.
Store has format ids and collation types and needs 
to have Objects created based on that information. This object creation will be supported
by the new interface on DVF and it is called
getInstanceUsingFormatIdAndCollationType. 
DVF will keep an array of InstanceGetters for all the format ids supported by Derby. Initially,
this array won't have anything. Every time
this new interface is called on a new format id, the InstnaceGetter obtained will be saved
in that array so next time around, we don't need
to create a new InstanceGetter for the same format id. The next time around, the new interface
will find the InstanceGetter in the array
and will use that to create an object based on format id. If the collation type passed to
the interface is UCS_BASIC, then the new interface
will simply return that object. If the collation type is territory based and the object returned
for the format id is of type 
StringDataValue, then the new interface will create a new DVD which is based on the territory
based collation by calling
DVD.getValue(TerritoryBasedCollator).

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java?view=diff&rev=529697&r1=529696&r2=529697
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java Tue
Apr 17 11:08:49 2007
@@ -715,4 +715,24 @@
          *  Collator based on territory if the collation type is TERRITORY_BASED
          */
         RuleBasedCollator getCharacterCollator(int collationType);
+        
+        /**
+         * Return an object based on the format id and collation type. For
+         * format ids which do not correspond to character types, a format id
+         * is sufficient to get the right DVD. But for character types, Derby
+         * uses same format id for collation sensitive character types and for
+         * character types that use the default JVM collation. To get the
+         * correct DVD for character types, we need to know the collation type.
+         * Using collation type, we will determine if we need to construct
+         * collation sensitive DVD and associate the correct RuleBasedCollator
+         * with such DVDs.
+         *  
+         * @param formatId Format id for the DVD
+         * @param collationType this is meaningful only for character types.
+         * 
+         * @return Object which will be constructed using the passed
+         * parameters 
+         */
+        Object getInstanceUsingFormatIdAndCollationType(int formatId, int collationType)
+        throws StandardException;
 }

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?view=diff&rev=529697&r1=529696&r2=529697
==============================================================================
--- 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 Apr 17 11:08:49 2007
@@ -39,10 +39,17 @@
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
 import org.apache.derby.iapi.services.i18n.LocaleFinder;
+import org.apache.derby.iapi.services.io.FormatableInstanceGetter;
+import org.apache.derby.iapi.services.io.FormatIdUtil;
 import org.apache.derby.iapi.services.io.RegisteredFormatIds;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.iapi.services.monitor.ModuleControl;
 
+import org.apache.derby.iapi.services.loader.ClassInfo;
+import org.apache.derby.iapi.services.loader.InstanceGetter;
+
+import org.apache.derby.iapi.reference.SQLState;
+
 import java.sql.Date;
 import java.sql.Time;
 import java.sql.Timestamp;
@@ -72,6 +79,12 @@
     	//Following Collator object will be initialized using databaseLocale.  
     	private RuleBasedCollator collatorForCharacterTypes;
 
+    	/** 
+    	 * For performance purposes, cache InstanceGetters for various formatid
+    	 * as we get them in getInstanceUsingFormatIdAndCollationType method.
+    	 */ 
+    	private InstanceGetter[] instanceGettersForFormatIds;
+
         DataValueFactoryImpl()
         {
         }
@@ -1100,8 +1113,102 @@
     	if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
     		return (RuleBasedCollator)null;
     	else
-    		return collatorForCharacterTypes;
-    	
+    		return collatorForCharacterTypes;    	
+    }
+
+    /** 
+     * @see DataValueFactory#getInstanceUsingFormatIdAndCollationType(int, int)
+     */
+    public Object getInstanceUsingFormatIdAndCollationType(
+    		int formatId, int collationType) throws StandardException {
+		String className;
+		int fmtIdPositionInInstanceGetterArray;
+		InstanceGetter instanceGetter;
+
+		try {
+			fmtIdPositionInInstanceGetterArray = 
+				formatId - StoredFormatIds.MIN_TWO_BYTE_FORMAT_ID;
+			//If this is the first time this method is getting called, then
+			//instanceGettersForFormatIds will be null. If so, allocate it.
+			if (instanceGettersForFormatIds == null) {
+				instanceGettersForFormatIds = new InstanceGetter[RegisteredFormatIds.TwoByte.length];
+			}
+			//Check if we have already called this method for the passed format
+			//id. 
+			instanceGetter = 
+				instanceGettersForFormatIds[fmtIdPositionInInstanceGetterArray];
+			//If following if is true, then this method has already been called
+			//for the passed format id. We can just use the cached InstanceGetter
+			//from instanceGettersForFormatIds
+			if (instanceGetter != null) {
+				//Get the object from the InstanceGetter
+				Object returnObject = instanceGetter.getNewInstance();
+				//If we are dealing with default collation, then we have 
+				//got the right DVD already. Just return it.
+				if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
+					return returnObject;
+				//If we are dealing with territory based collation and 
+				//the object is of type StringDataValue, then we need to 
+				//create a StringDataValue with territory based collation.
+				if (returnObject instanceof StringDataValue) 
+					((StringDataValue)returnObject).getValue(getCharacterCollator(collationType));
+				return returnObject;
+			}
+			//This is the first time this method has been called for the passed
+			//format id and hence it's InstanceGetter is not in 
+			//instanceGettersForFormatIds. Get the InstanceGetter's name for
+			//this format id from RegisteredFormatIds
+			className = RegisteredFormatIds.TwoByte[fmtIdPositionInInstanceGetterArray];
+		} catch (ArrayIndexOutOfBoundsException aioobe) {
+			className = null;
+			fmtIdPositionInInstanceGetterArray = 0;
+		} catch (Exception ite) {
+			throw StandardException.newException(SQLState.REGISTERED_CLASS_INSTANCE_ERROR,
+					ite, new Integer(formatId), "XX" /*ci.getClassName()*/);
+		}
+
+		if (className != null) {
+			Throwable t;
+			try {
+				Class clazz = Class.forName(className);
+				// See if the InstanceGetter class for this format id is a 
+				//FormatableInstanceGetter
+				if (FormatableInstanceGetter.class.isAssignableFrom(clazz)) {
+					FormatableInstanceGetter tfig = (FormatableInstanceGetter) clazz.newInstance();
+					tfig.setFormatId(formatId);
+					//Cache this InstanceGetter in instanceGettersForFormatIds
+					instanceGettersForFormatIds[fmtIdPositionInInstanceGetterArray] = tfig;
+					//Get the object from the InstanceGetter
+					Object returnObject = tfig.getNewInstance();
+					//If we are dealing with default collation, then we have 
+					//got the right DVD already. Just return it.
+					if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
+						return returnObject;
+					//If we are dealing with territory based collation and 
+					//the object is of type StringDataValue, then we need to 
+					//create a StringDataValue with territory based collation.
+					if (returnObject instanceof StringDataValue) 
+						((StringDataValue)returnObject).getValue(getCharacterCollator(collationType));
+						return returnObject;
+				}
+				//InstanceGetter is not of the type FormatableInstanceGetter
+				instanceGettersForFormatIds[fmtIdPositionInInstanceGetterArray] = new ClassInfo(clazz);
+				return instanceGettersForFormatIds[fmtIdPositionInInstanceGetterArray].getNewInstance();
+			} catch (ClassNotFoundException cnfe) {
+				t = cnfe;
+			} catch (IllegalAccessException iae) {
+				t = iae;
+			} catch (InstantiationException ie) {
+				t = ie;
+			} catch (LinkageError le) {
+				t = le;
+			} catch (java.lang.reflect.InvocationTargetException ite) {
+				t = ite;
+			}
+			throw StandardException.newException(SQLState.REGISTERED_CLASS_LINAKGE_ERROR,
+				t, FormatIdUtil.formatIdToString(formatId), className);
+		}
+		throw StandardException.newException(SQLState.REGISTERED_CLASS_NONE, FormatIdUtil.formatIdToString(formatId));
   	
     }
 
         // RESOLVE: This is here to find the LocaleFinder (i.e. the Database)



Mime
View raw message