harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r905210 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/SqlUtil.java test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
Date Mon, 01 Feb 2010 08:21:09 GMT
Author: zhoukevin
Date: Mon Feb  1 08:21:09 2010
New Revision: 905210

URL: http://svn.apache.org/viewvc?rev=905210&view=rev
Log:
Fix SqlUtil.validateType(int) method by using reflection of Types.class to search those public&static&final&int
fields, and add a test case

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java?rev=905210&r1=905209&r2=905210&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/SqlUtil.java
Mon Feb  1 08:21:09 2010
@@ -17,49 +17,33 @@
 
 package javax.sql.rowset;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 import java.sql.SQLException;
 import java.sql.Types;
 import org.apache.harmony.sql.internal.nls.Messages;
 
 class SqlUtil {
-    /*
-     * FIXME:Validate column types is defined by java.sql.Types, current
-     * implementation is ugly, need to find an elegant and effient way to check
-     * all constants defined in java.util.sql.Types
-     */
+
     static void validateType(int type) throws SQLException {
-        switch (type) {
-        case Types.ARRAY:
-        case Types.BIGINT:
-        case Types.BINARY:
-        case Types.BIT:
-        case Types.BLOB:
-        case Types.BOOLEAN:
-        case Types.CHAR:
-        case Types.CLOB:
-        case Types.DATALINK:
-        case Types.DATE:
-        case Types.DECIMAL:
-        case Types.DISTINCT:
-        case Types.DOUBLE:
-        case Types.FLOAT:
-        case Types.INTEGER:
-        case Types.JAVA_OBJECT:
-        case Types.LONGVARBINARY:
-        case Types.LONGVARCHAR:
-        case Types.NULL:
-        case Types.NUMERIC:
-        case Types.OTHER:
-        case Types.REAL:
-        case Types.REF:
-        case Types.SMALLINT:
-        case Types.STRUCT:
-        case Types.TIME:
-        case Types.TIMESTAMP:
-        case Types.TINYINT:
-        case Types.VARBINARY:
-        case Types.VARCHAR:
-            return;
+        try {
+            int modifiers = -1;
+            Field[] fields = Types.class.getFields();
+            for (int index = 0; index < fields.length; index++) {
+                // field should be int type
+                if (int.class == fields[index].getType()) {
+                    modifiers = fields[index].getModifiers();
+                    // field should be static and final
+                    if (Modifier.isStatic(modifiers)
+                            && Modifier.isFinal(modifiers)) {
+                        if (type == fields[index].getInt(Types.class)) {
+                            return;
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            // ignored: this should never happen
         }
         throw new SQLException(Messages.getString("sql.28")); //$NON-NLS-1$
     }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java?rev=905210&r1=905209&r2=905210&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
Mon Feb  1 08:21:09 2010
@@ -826,6 +826,13 @@
         } catch (SQLException e) {
             // expected
         }
+        
+        try {
+            metaDataImpl.setColumnType(2, 59);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
     }
 
     /**



Mime
View raw message