db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r532627 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
Date Thu, 26 Apr 2007 06:35:45 GMT
Author: mamta
Date: Wed Apr 25 23:35:44 2007
New Revision: 532627

URL: http://svn.apache.org/viewvc?view=rev&rev=532627
Log:
This is more of a code cleanup for DERBY-2569.
Rather than using switch statement to check for individual format ids, this patch uses isXXX
methods wherever applicable to determine if two
types are comparable or not. This is because with format id checking, in future, when say
another numeric type is added, we will have to 
modify the switch statement to look for that new numeric type's format id. Instead, if we
check for isXXX() method, then the formatid checks 
won't have to be maintained because the new numeric type will fall into existing isXXX() umbrella.
 


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

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?view=diff&rev=532627&r1=532626&r2=532627
==============================================================================
--- 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 Wed
Apr 25 23:35:44 2007
@@ -850,7 +850,13 @@
 		TypeId compareWithTypeID = compareWithDTD.getTypeId();
 		int compareWithJDBCTypeId = compareWithTypeID.getJDBCTypeId();
 
-		// Long types cannot be compared
+		// Long types cannot be compared. 
+		// XML types also fall in this window
+		// Says SQL/XML[2003] spec:
+		// 4.2.2 XML comparison and assignment
+		// "XML values are not comparable."
+		// An XML value cannot be compared to any type--
+		// not even to other XML values.
 		if (compareWithTypeID.isLongConcatableTypeId() || typeId.isLongConcatableTypeId())
 			return false;
 
@@ -864,122 +870,86 @@
 		if (!(typeId.isUserDefinedTypeId()) && 
 				(compareWithTypeID.isUserDefinedTypeId()))
 			return compareWithDTD.comparable(this, forEquals, cf);
-		
-        switch (typeId.getJDBCTypeId()) 
-		{
-                case Types.DECIMAL:
-                case Types.BIGINT:
-                case Types.DOUBLE:
-                case Types.INTEGER:
-                case Types.NUMERIC:
-                case Types.REAL:
-                case Types.SMALLINT:
-                case Types.TINYINT:
-                	// Numeric types are comparable to numeric types, boolean 
-                	//types and to comparable user types
-            		return (compareWithTypeID.isNumericTypeId() ||
+
+    	//Numeric types are comparable to numeric types, boolean types and to 
+		//comparable user types
+		if (typeId.isNumericTypeId())
+    		return (compareWithTypeID.isNumericTypeId() || 
             		compareWithTypeID.isBooleanTypeId());
 
-                case Types.CHAR:
-                case Types.LONGVARCHAR:
-                case Types.VARCHAR:
-            		// CHAR and VARCHAR are comparable to strings, boolean, 
-                	// DATE/TIME/TIMESTAMP and to comparable user types
-            		if((compareWithTypeID.isDateTimeTimeStampTypeID() ||
-            				compareWithTypeID.isBooleanTypeId()))
-            				return true;
-            		//If both the types are string types, then we need to make
-            		//sure they have the same collation set on them
-            		if (compareWithTypeID.isStringTypeId() && typeId.isStringTypeId())
{
-            			if (getCollationDerivation() == compareWithDTD.getCollationDerivation() &&
-            					getCollationType() == compareWithDTD.getCollationType())
-            				return true;
-            			else
-            				return false;
-            		} else
-            			return false;
-            		
-
-                case Types.BIT:
-                case JDBC30Translation.SQL_TYPES_BOOLEAN:
-            		/* Are comparable to Boolean, string, numeric and to 
-            		 * comparable user types */
-            		return (compareWithTypeID.getSQLTypeName().equals(typeId.getSQLTypeName())
||
-            				compareWithTypeID.isStringTypeId() ||
-            				compareWithTypeID.isNumericTypeId()); 
-
-                case Types.DATE:
-                	/*
-                	 * Dates are comparable to dates, strings and to comparable
-                	 * user types.
-                	 */
-            		if (compareWithJDBCTypeId == Types.DATE || 
-            				compareWithTypeID.isStringTypeId())
-            			return true;
-            		else
-            			return false;
-
-                case Types.TIME:
-                	/*
-                	 * Times are comparable to times, strings and to comparable
-                	 * user types.
-                	 */
-            		if (compareWithJDBCTypeId == Types.TIME || 
-            				compareWithTypeID.isStringTypeId())
-            			return true;
-            		else
-            			return false;
-
-                case Types.TIMESTAMP:
-                	/*
-                	 * Timestamps are comparable to timestamps, strings and to 
-                	 * comparable user types.
-                	 */
-            		if (compareWithJDBCTypeId == Types.TIMESTAMP || 
-            				compareWithTypeID.isStringTypeId())
-            			return true;
-            		else
-            			return false;
-
-                case Types.BINARY:
-                case Types.LONGVARBINARY:
-                case Types.VARBINARY:
-                	//Are comparable to other bit types and comparable user types
-                	return (compareWithTypeID.isBitTypeId()); 
-
-                case org.apache.derby.iapi.reference.JDBC20Translation.SQL_TYPES_JAVA_OBJECT:
-                case Types.OTHER:
-                	/*
-                	 * User types are comparable to other user types only if
-                	 * (for now) they are the same type and are being used to
-                	 * implement some JDBC type.  This is sufficient for
-                	 * date/time types; it may be generalized later for e.g.
-                	 * comparison of any user type with one of its subtypes.
-                	 */
-                	if (forEquals)
-                		return true;
-                	try {
-                	
-                		Class thisClass = cf.getClassInspector().getClass(
-    					typeId.getCorrespondingJavaTypeName());
-                		
-                		return java.lang.Comparable.class.isAssignableFrom(thisClass);
-                	} catch (ClassNotFoundException cnfe) {
-                		return false;
-                	}
-
-                case StoredFormatIds.XML_TYPE_ID:
-                    /*
-                     * Tell whether this type (XML) can be compared to the given type.
-                     * Says SQL/XML[2003] spec:
-                     *
-                     * 4.2.2 XML comparison and assignment
-                     * "XML values are not comparable."
-                     * 
-                     * An XML value cannot be compared to any type--
-                     * not even to other XML values.
-                     */ 
-                	return false;
+		//CHAR, VARCHAR and LONGVARCHAR are comparable to strings, boolean, 
+		//DATE/TIME/TIMESTAMP and to comparable user types
+		if (typeId.isStringTypeId()) {
+    		if((compareWithTypeID.isDateTimeTimeStampTypeID() ||
+    				compareWithTypeID.isBooleanTypeId()))
+    				return true;
+    		//If both the types are string types, then we need to make sure
+    		//they have the same collation set on them
+    		if (compareWithTypeID.isStringTypeId() && typeId.isStringTypeId()) {
+    			if (getCollationDerivation() == compareWithDTD.getCollationDerivation() &&
+    					getCollationType() == compareWithDTD.getCollationType())
+    				return true;//collation matches
+    			else
+    				return false;//collation does not match
+    		} else
+    			return false;//can't be compared			
+		}
+
+    	//Are comparable to other bit types and comparable user types
+		if (typeId.isBitTypeId()) 
+        	return (compareWithTypeID.isBitTypeId()); 
+		
+		//Booleans are comparable to Boolean, string, numeric and to 
+		//comparable user types 
+		if (typeId.isBooleanTypeId())
+    		return (compareWithTypeID.getSQLTypeName().equals(typeId.getSQLTypeName()) ||
+    				compareWithTypeID.isStringTypeId() ||
+    				compareWithTypeID.isNumericTypeId()); 
+
+		//Dates are comparable to dates, strings and to comparable
+		//user types.
+		if (typeId.getJDBCTypeId() == Types.DATE)
+    		if (compareWithJDBCTypeId == Types.DATE || 
+    				compareWithTypeID.isStringTypeId())
+    			return true;
+    		else
+    			return false;
+
+    	//Times are comparable to times, strings and to comparable
+		//user types.
+		if (typeId.getJDBCTypeId() == Types.TIME)
+    		if (compareWithJDBCTypeId == Types.TIME || 
+    				compareWithTypeID.isStringTypeId())
+    			return true;
+    		else
+    			return false;
+
+    	//Timestamps are comparable to timestamps, strings and to
+		//comparable user types.
+		if (typeId.getJDBCTypeId() == Types.TIMESTAMP)
+    		if (compareWithJDBCTypeId == Types.TIMESTAMP || 
+    				compareWithTypeID.isStringTypeId())
+    			return true;
+    		else
+    			return false;
+
+		//User types are comparable to other user types only if
+		//(for now) they are the same type and are being used to
+		//implement some JDBC type.  This is sufficient for
+		//date/time types; it may be generalized later for e.g.
+		//comparison of any user type with one of its subtypes.
+		if (typeId.isUserDefinedTypeId() || typeId.getJDBCTypeId() == Types.OTHER) {
+        	if (forEquals)
+        		return true;
+        	try {
+        	
+        		Class thisClass = cf.getClassInspector().getClass(
+				typeId.getCorrespondingJavaTypeName());
+        		
+        		return java.lang.Comparable.class.isAssignableFrom(thisClass);
+        	} catch (ClassNotFoundException cnfe) {
+        		return false;
+        	}			
 		}
 
 		return false;



Mime
View raw message