db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r530546 - in /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types: DTSClassInfo.java DataValueFactory.java DataValueFactoryImpl.java
Date Thu, 19 Apr 2007 21:03:24 GMT
Author: mamta
Date: Thu Apr 19 14:03:23 2007
New Revision: 530546

URL: http://svn.apache.org/viewvc?view=rev&rev=530546
Log:
DERBY-2557 : This commit renames getInstanceUsingFormatIdAndCollationType method on DVF to
getNull. It also changes the implementation of 
the that method so that it bypasses the InstanceGetter. This implementation is much simpler
than the old one because there is no 
InstanceGetter involved. Lastly, the code associated with getting a DVD from a format id is
moved out of DTSClassinfo into a static
method on DataValueFactoryImpl. This static method will be called by DTSClassinfo.

The changes made in the patch are as follows 
1)DataValueFactory 
Changed the name of the new interface from getInstanceUsingFormatIdAndCollationType to getNull.
This interface now returns a DVD rather 
than an Object. The functionality of the interface remains the same but the implementation
has changed. 
2)DataValueFactoryImpl 
a)Removed the class level array and the code associated with InstanceGetter. 
b)Added a new static method called getNullDVDWithUCS_BASICcollation(int formatId). This static
method handles all the format ids associated 
with DVDs with the exception of Decimals. The class to be returned for Decimals depends on
what VM is being used. This dependency on the VM 
is handled by getNullDecimal defined on DVF. But since getNullDecimal is not a static method,
it can't be called by static method 
getNullDVDWithUCS_BASICcollation. I could go the path of defining getNullDecimal as static
but that will require changes in 
NumericTypeCompiler.nullMethodName method. Also, all the other getNullXXX on DVF are non-static
So, the code for returning the right DVD 
for Decimal is not in getNullDVDWithUCS_BASICcollation. Rather it is in the calling method,
getNull. For other format ids associated with 
DVDs, getNull will check if the DVD is of type StringDataValue and the collation type is territory
based and if so, then it will return 
((StringDataValue)returnDVD).getValue(getCharacterCollator(collationType)); 
3)DTSClassInfo 
This class now calls the static method in DVF to get the DVDs. But if the format id is not
for a DVD, then it checks if it needs to return 
TypeId. 

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DTSClassInfo.java
    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/DTSClassInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DTSClassInfo.java?view=diff&rev=530546&r1=530545&r2=530546
==============================================================================
--- 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 Thu Apr
19 14:03:23 2007
@@ -28,38 +28,15 @@
 
         public Object getNewInstance() {
         	
-        	
-        		// Does not handle StoredFormatIds.SQL_DECIMAL_ID as
-        		// different implementations are required for different VMs.
-
-                switch (fmtId) {
-                /* Wrappers */
-                case StoredFormatIds.SQL_BIT_ID: return new SQLBit();
-                case StoredFormatIds.SQL_BOOLEAN_ID: return new SQLBoolean();
-                case StoredFormatIds.SQL_CHAR_ID: return new SQLChar();
-                case StoredFormatIds.SQL_DATE_ID: return new SQLDate();
-                case StoredFormatIds.SQL_DOUBLE_ID: return new SQLDouble();
-                case StoredFormatIds.SQL_INTEGER_ID: return new SQLInteger();
-                case StoredFormatIds.SQL_LONGINT_ID: return new SQLLongint();
-                case StoredFormatIds.SQL_NATIONAL_CHAR_ID: return new SQLNationalChar();
-                case StoredFormatIds.SQL_NATIONAL_LONGVARCHAR_ID: return new SQLNationalLongvarchar();
-                case StoredFormatIds.SQL_NATIONAL_VARCHAR_ID: return new SQLNationalVarchar();
-                case StoredFormatIds.SQL_REAL_ID: return new SQLReal();
-                case StoredFormatIds.SQL_REF_ID: return new SQLRef();
-                case StoredFormatIds.SQL_SMALLINT_ID: return new SQLSmallint();
-                case StoredFormatIds.SQL_TIME_ID: return new SQLTime();
-                case StoredFormatIds.SQL_TIMESTAMP_ID: return new SQLTimestamp();
-                case StoredFormatIds.SQL_TINYINT_ID: return new SQLTinyint();
-                case StoredFormatIds.SQL_VARCHAR_ID: return new SQLVarchar();
-                case StoredFormatIds.SQL_LONGVARCHAR_ID: return new SQLLongvarchar();
-                case StoredFormatIds.SQL_VARBIT_ID: return new SQLVarbit();
-                case StoredFormatIds.SQL_LONGVARBIT_ID: return new SQLLongVarbit();
-                case StoredFormatIds.SQL_USERTYPE_ID_V3: return new UserType();
-                case StoredFormatIds.SQL_BLOB_ID: return new SQLBlob();
-                case StoredFormatIds.SQL_CLOB_ID: return new SQLClob();
-                case StoredFormatIds.SQL_NCLOB_ID: return new SQLNClob();
-                case StoredFormatIds.XML_ID: return new XML();
+        	// Does not handle StoredFormatIds.SQL_DECIMAL_ID as different
+        	// implementations are required for different VMs.
 
+        	//The format id for DVDs are handled first.  
+        	Object returnObject = DataValueFactoryImpl.getNullDVDWithUCS_BASICcollation(fmtId);
+        	if (returnObject != null) return returnObject;
+        	//If we are still here, then it means that we are not working with
+        	//format id for DVD. Handle the other format ids in following code.
+        	switch (fmtId) {        	
                 /* Type ids */
                 case StoredFormatIds.BIT_TYPE_ID: 
                 case StoredFormatIds.BOOLEAN_TYPE_ID: 

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=530546&r1=530545&r2=530546
==============================================================================
--- 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 Thu
Apr 19 14:03:23 2007
@@ -730,9 +730,9 @@
          * @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 
+         * @return DataValueDescriptor which will be constructed using the 
+         * passed parameters 
          */
-        Object getInstanceUsingFormatIdAndCollationType(int formatId, int collationType)
+        DataValueDescriptor getNull(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=530546&r1=530545&r2=530546
==============================================================================
--- 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
Thu Apr 19 14:03:23 2007
@@ -79,12 +79,6 @@
     	//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()
         {
         }
@@ -1117,96 +1111,83 @@
     }
 
     /** 
-     * @see DataValueFactory#getInstanceUsingFormatIdAndCollationType(int, int)
+     * @see DataValueFactory#getNull(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 
-				//return a StringDataValue with territory based collation.
-				if (returnObject instanceof StringDataValue) 
-					return ((StringDataValue)returnObject).getValue(getCharacterCollator(collationType));
-			}
-			//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()*/);
-		}
+    public DataValueDescriptor getNull(int formatId, int collationType) 
+    throws StandardException {
 
-		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 
-					//return a StringDataValue with territory based collation.
-					if (returnObject instanceof StringDataValue) 
-						return ((StringDataValue)returnObject).getValue(getCharacterCollator(collationType));
-				}
-				//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);
+    	//For StoredFormatIds.SQL_DECIMAL_ID, different implementations are 
+    	//required for different VMs. getNullDecimal method is not static and 
+    	//hence can't be called in the static getNullDVDWithUCS_BASICcollation
+    	//method in this class. That is why StoredFormatIds.SQL_DECIMAL_ID is 
+    	//getting handled here.
+    	if (formatId == StoredFormatIds.SQL_DECIMAL_ID)
+    		return getNullDecimal(null);
+		else {
+			DataValueDescriptor returnDVD = 
+				DataValueFactoryImpl.getNullDVDWithUCS_BASICcollation(formatId);
+			//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 returnDVD;			
+			//If we are dealing with territory based collation and returnDVD is 
+			//of type StringDataValue, then we need to return a StringDataValue   
+			//with territory based collation.
+			if (returnDVD instanceof StringDataValue) 
+				return ((StringDataValue)returnDVD).getValue(getCharacterCollator(collationType));
+			else
+				return returnDVD;			
 		}
-		throw StandardException.newException(SQLState.REGISTERED_CLASS_NONE, FormatIdUtil.formatIdToString(formatId));
   	
+    }
+    
+    /**
+     * This method will return a DVD based on the formatId. It doesn't take
+     * into account the collation that should be associated with collation
+     * sensitive DVDs, which are all the character type DVDs. Such DVDs 
+     * returned from this method have default UCS_BASIC collation associated
+     * with them. If collation associated should be terriotry based, then that
+     * needs to be handled by the caller of this method. An example of such 
+     * code in the caller can be seen in DataValueFactory.getNull method.
+     * 
+     * Another thing to note is this method does not deal with format id
+     * associated with decimal. This is because different implementation are
+     * required for different VMs. This is again something that needs to be
+     * handled by the caller. An example of such code in the caller can be 
+     * seen in DataValueFactory.getNull method.
+     *  
+     * @param formatId Return a DVD based on the format id
+     * @return DataValueDescriptor with default collation of UCS_BASIC 
+     */
+    public static DataValueDescriptor getNullDVDWithUCS_BASICcollation(int formatId){
+        switch (formatId) {
+        /* Wrappers */
+        case StoredFormatIds.SQL_BIT_ID: return new SQLBit();
+        case StoredFormatIds.SQL_BOOLEAN_ID: return new SQLBoolean();
+        case StoredFormatIds.SQL_CHAR_ID: return new SQLChar();
+        case StoredFormatIds.SQL_DATE_ID: return new SQLDate();
+        case StoredFormatIds.SQL_DOUBLE_ID: return new SQLDouble();
+        case StoredFormatIds.SQL_INTEGER_ID: return new SQLInteger();
+        case StoredFormatIds.SQL_LONGINT_ID: return new SQLLongint();
+        case StoredFormatIds.SQL_NATIONAL_CHAR_ID: return new SQLNationalChar();
+        case StoredFormatIds.SQL_NATIONAL_LONGVARCHAR_ID: return new SQLNationalLongvarchar();
+        case StoredFormatIds.SQL_NATIONAL_VARCHAR_ID: return new SQLNationalVarchar();
+        case StoredFormatIds.SQL_REAL_ID: return new SQLReal();
+        case StoredFormatIds.SQL_REF_ID: return new SQLRef();
+        case StoredFormatIds.SQL_SMALLINT_ID: return new SQLSmallint();
+        case StoredFormatIds.SQL_TIME_ID: return new SQLTime();
+        case StoredFormatIds.SQL_TIMESTAMP_ID: return new SQLTimestamp();
+        case StoredFormatIds.SQL_TINYINT_ID: return new SQLTinyint();
+        case StoredFormatIds.SQL_VARCHAR_ID: return new SQLVarchar();
+        case StoredFormatIds.SQL_LONGVARCHAR_ID: return new SQLLongvarchar();
+        case StoredFormatIds.SQL_VARBIT_ID: return new SQLVarbit();
+        case StoredFormatIds.SQL_LONGVARBIT_ID: return new SQLLongVarbit();
+        case StoredFormatIds.SQL_USERTYPE_ID_V3: return new UserType();
+        case StoredFormatIds.SQL_BLOB_ID: return new SQLBlob();
+        case StoredFormatIds.SQL_CLOB_ID: return new SQLClob();
+        case StoredFormatIds.SQL_NCLOB_ID: return new SQLNClob();
+        case StoredFormatIds.XML_ID: return new XML();
+        default:return null;
+        }
     }
 
         // RESOLVE: This is here to find the LocaleFinder (i.e. the Database)



Mime
View raw message