db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r711128 - /db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/MetaDataColumnDescriptor.java
Date Mon, 03 Nov 2008 23:49:01 GMT
Author: tomdz
Date: Mon Nov  3 15:49:00 2008
New Revision: 711128

URL: http://svn.apache.org/viewvc?rev=711128&view=rev
Log:
Applied patch for DDLUTILS-217: Retrieve columns by name iso index

Modified:
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/MetaDataColumnDescriptor.java

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/MetaDataColumnDescriptor.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/MetaDataColumnDescriptor.java?rev=711128&r1=711127&r2=711128&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/MetaDataColumnDescriptor.java
(original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/MetaDataColumnDescriptor.java
Mon Nov  3 15:49:00 2008
@@ -103,44 +103,61 @@
      */
     public Object readColumn(ResultSet resultSet) throws SQLException
     {
-        ResultSetMetaData metaData = resultSet.getMetaData();
-        int               foundIdx = -1;
+        Object result = null;
 
-        for (int idx = 1; (foundIdx < 0) && (idx <= metaData.getColumnCount());
idx++)
-        {
-            if (_columnName.equals(metaData.getColumnName(idx).toUpperCase()))
-            {
-                foundIdx = idx;
-            }
-        }
-        if (foundIdx > 0)
+        try
         {
-            Object result = null;
-
             switch (_jdbcType)
             {
                 case Types.BIT:
-                    result = new Boolean(resultSet.getBoolean(foundIdx));
+                    result = new Boolean(resultSet.getBoolean(_columnName));
                     break;
                 case Types.INTEGER:
-                    result = new Integer(resultSet.getInt(foundIdx));
+                    result = new Integer(resultSet.getInt(_columnName));
                     break;
                 case Types.TINYINT:
-                    result = new Short(resultSet.getShort(foundIdx));
+                    result = new Short(resultSet.getShort(_columnName));
                     break;
                 default:
-                    result = resultSet.getString(foundIdx);
+                    result = resultSet.getString(_columnName);
                 break;
             }
             if (resultSet.wasNull())
             {
                 result = null;
             }
-            return result;
         }
-        else
+        catch (SQLException ex)
+        {
+            if (isColumnInResultSet(resultSet))
+            {
+                throw ex;
+            }
+            else
+            {
+                result = _defaultValue;
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Determines whether a value for the specified column is present in the given result
set.
+     * 
+     * @param resultSet The result set
+     * @return <code>true</code> if the column is present in the result set
+     */
+    private boolean isColumnInResultSet(ResultSet resultSet) throws SQLException
+    {
+        ResultSetMetaData metaData = resultSet.getMetaData();
+
+        for (int idx = 1; idx <= metaData.getColumnCount(); idx++)
         {
-            return _defaultValue;
+            if (_columnName.equals(metaData.getColumnName(idx).toUpperCase()))
+            {
+                return true;
+            }
         }
+        return false;
     }
 }



Mime
View raw message