db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r755147 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/Agent.java client/org/apache/derby/client/am/BatchUpdateException.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
Date Tue, 17 Mar 2009 08:26:25 GMT
Author: kahatlen
Date: Tue Mar 17 08:26:24 2009
New Revision: 755147

URL: http://svn.apache.org/viewvc?rev=755147&view=rev
Log:
DERBY-4097: BatchUpdateException in NullableUniqueConstraintTest

Improve error reporting when a BatchUpdateException is thrown by the
client driver. Use initCause() to put the underlying exception in the
chain of exceptions printed by printStackTrace(). Note that there may
be more than one underlying exception for a BatchUpdateException and
only one of them will be printed by printStackTrace(). To see the rest
of the exceptions, getNextException() has to be used (as before).

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java?rev=755147&r1=755146&r2=755147&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java Tue Mar 17 08:26:24
2009
@@ -267,11 +267,9 @@
             }
         }
         if (accumulatedExceptions != null) {
-            BatchUpdateException bue = new BatchUpdateException(logWriter_,
+            throw new BatchUpdateException(logWriter_,
                 new ClientMessageId(SQLState.BATCH_NON_ATOMIC_FAILURE),
-                updateCounts);
-            bue.setNextException(accumulatedExceptions.getSQLException());
-            throw bue;
+                null, updateCounts, accumulatedExceptions);
         }
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java?rev=755147&r1=755146&r2=755147&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java Tue
Mar 17 08:26:24 2009
@@ -37,7 +37,7 @@
         SqlException.getMessageUtil();
 
     public BatchUpdateException(LogWriter logWriter, ClientMessageId msgid,
-        Object[] args, int[] updateCounts)
+        Object[] args, int[] updateCounts, SqlException cause)
     {
         super(
             msgutil_.getCompleteMessage(
@@ -50,11 +50,21 @@
         if (logWriter != null) {
             logWriter.traceDiagnosable(this);
         }
+
+        if (cause != null) {
+            initCause(cause);
+            setNextException(cause.getSQLException());
+        }
     }
     
     // Syntactic sugar constructors to make it easier to create
     // a BatchUpdateException with substitution parameters
     public BatchUpdateException(LogWriter logWriter, ClientMessageId msgid,
+        Object[] args, int[] updateCounts) {
+        this(logWriter, msgid, args, updateCounts, null);
+    }
+
+    public BatchUpdateException(LogWriter logWriter, ClientMessageId msgid,
         int[] updateCounts)
     {
         this(logWriter, msgid, (Object [])null, updateCounts);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java?rev=755147&r1=755146&r2=755147&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
Tue Mar 17 08:26:24 2009
@@ -22,6 +22,8 @@
 
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.sql.BatchUpdateException;
 import java.sql.CallableStatement;
 import java.sql.Connection;
@@ -1488,4 +1490,35 @@
         conn2.rollback();
         conn2.close();
     }
+
+    /**
+     * Test that the underlying exception is included in the output when we
+     * call printStackTrace() on a BatchUpdateException. Earlier, with the
+     * client driver, the underlying cause of a BatchUpdateException could not
+     * be seen without calling getNextException().
+     */
+    public void testUnderlyingExceptionIsVisible() throws SQLException {
+        setAutoCommit(false);
+        Statement s = createStatement();
+        s.addBatch("create table t(x int unique not null)");
+        for (int i = 0; i < 3; i++) {
+            s.addBatch("insert into t values 1");
+        }
+
+        BatchUpdateException bue = null;
+        try {
+            s.executeBatch();
+        } catch (BatchUpdateException e) {
+            bue = e;
+        }
+        assertNotNull("Did not get duplicate key exception", bue);
+
+        StringWriter w = new StringWriter();
+        bue.printStackTrace(new PrintWriter(w, true));
+
+        String stackTrace = w.toString();
+        if (stackTrace.indexOf("duplicate key") == -1) {
+            fail("Could not see 'duplicate key' in printStackTrace()", bue);
+        }
+    }
 }



Mime
View raw message