db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r515946 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils: platform/PlatformImplBase.java util/Jdbc3Utils.java
Date Thu, 08 Mar 2007 07:00:06 GMT
Author: tomdz
Date: Wed Mar  7 23:00:05 2007
New Revision: 515946

URL: http://svn.apache.org/viewvc?view=rev&rev=515946
Log:
Fix for DDLUTILS-158

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/util/Jdbc3Utils.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?view=diff&rev=515946&r1=515945&r2=515946
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Wed Mar
 7 23:00:05 2007
@@ -1494,13 +1494,30 @@
                 closeStatement(statement);
                 afterInsert(connection, table);
 
-                int sum = 0;
+                boolean hasSum = true;
+                int     sum    = 0;
 
                 for (int idx = 0; (results != null) && (idx < results.length);
idx++)
                 {
-                    sum += results[idx];
+                    if (results[idx] < 0)
+                    {
+                        hasSum = false;
+                        if (Jdbc3Utils.supportsJava14BatchResultCodes())
+                        {
+                            String msg = Jdbc3Utils.getBatchResultMessage(table.getName(),
idx, results[idx]);
+
+                            if (msg != null)
+                            {
+                                _log.warn(msg);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        sum += results[idx];
+                    }
                 }
-                if (sum != numRows)
+                if (hasSum && (sum != numRows))
                 {
                     _log.warn("Attempted to insert " + numRows + " rows into table " + table.getName()
+ " but changed " + sum + " rows");
                 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/util/Jdbc3Utils.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/util/Jdbc3Utils.java?view=diff&rev=515946&r1=515945&r2=515946
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/util/Jdbc3Utils.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/util/Jdbc3Utils.java Wed Mar  7 23:00:05
2007
@@ -19,12 +19,14 @@
  * under the License.
  */
 
+import java.sql.Statement;
 import java.sql.Types;
 
 import org.apache.ddlutils.model.TypeMap;
 
 /**
- * Little helper class providing functions for dealing with the newer JDBC functionality.
+ * Little helper class providing functions for dealing with the newer JDBC functionality
+ * in a way that is safe to compile with Java 1.3.
  * 
  * @version $Revision: 289996 $
  */
@@ -82,6 +84,65 @@
         catch (Exception ex)
         {
             throw new UnsupportedOperationException("The jdbc type DATALINK is not supported");
+        }
+    }
+
+    /**
+     * Determines whether the system supports the Java 1.4 batch result codes.
+     *   
+     * @return <code>true</code> if SUCCESS_NO_INFO and EXECUTE_FAILED are available
+     *         in the {@link java.sql.Statement} class
+     */
+    public static boolean supportsJava14BatchResultCodes()
+    {
+        try
+        {
+            return (Statement.class.getField("SUCCESS_NO_INFO") != null) &&
+                   (Statement.class.getField("EXECUTE_FAILED") != null);
+        }
+        catch (Exception ex)
+        {
+            return false;
+        }
+    }
+
+    /**
+     * Returns the logging message corresponding to the given result code of a batch message.
+     * Note that these code values are only available in JDBC 3 and newer (see
+     * {@link java.sql.Statement} for details).
+     * 
+     * @param tableName  The name of the table that the batch update/insert was performed
on
+     * @param rowIdx     The index of the row within the batch for which this code is
+     * @param resultCode The code
+     * @return The string message or <code>null</code> if the code does not indicate
an error
+     */
+    public static String getBatchResultMessage(String tableName, int rowIdx, int resultCode)
+    {
+        if (resultCode < 0)
+        {
+            try
+            {
+                if (resultCode == Statement.class.getField("SUCCESS_NO_INFO").getInt(null))
+                {
+                    return null;
+                }
+                else if (resultCode == Statement.class.getField("EXECUTE_FAILED").getInt(null))
+                {
+                    return "The batch insertion of row " + rowIdx + " into table " + tableName
+ " failed but the driver is able to continue processing";
+                }
+                else
+                {
+                    return "The batch insertion of row " + rowIdx + " into table " + tableName
+ " returned an undefined status value " + resultCode;
+                }
+            }
+            catch (Exception ex)
+            {
+                throw new UnsupportedOperationException("The batch result codes are not supported");
+            }
+        }
+        else
+        {
+            return null;
         }
     }
 }



Mime
View raw message