db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r755156 - in /db/derby/code/branches/10.5/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 09:00:54 GMT
Author: kahatlen
Date: Tue Mar 17 09:00:54 2009
New Revision: 755156

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

Improved error reporting in the client driver. Merged from trunk
revision 755147.

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

Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/client/am/Agent.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/client/am/Agent.java?rev=755156&r1=755155&r2=755156&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/client/am/Agent.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/client/am/Agent.java Tue Mar
17 09:00:54 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/branches/10.5/java/client/org/apache/derby/client/am/BatchUpdateException.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/client/am/BatchUpdateException.java?rev=755156&r1=755155&r2=755156&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/client/am/BatchUpdateException.java
(original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/client/am/BatchUpdateException.java
Tue Mar 17 09:00:54 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/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java?rev=755156&r1=755155&r2=755156&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
Tue Mar 17 09:00:54 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