You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by da...@apache.org on 2006/03/17 21:47:46 UTC

svn commit: r386710 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/suites/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/

Author: davidvc
Date: Fri Mar 17 12:47:45 2006
New Revision: 386710

URL: http://svn.apache.org/viewcvs?rev=386710&view=rev
Log:
DERBY-1117 - Fix bug in SqlException where we weren't chaining exceptions.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java   (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=386710&r1=386709&r2=386710&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Fri Mar 17 12:47:45 2006
@@ -114,6 +114,8 @@
                 args),
             ExceptionUtil.getSQLStateFromIdentifier(msgid.msgid),
             ExceptionUtil.getSeverityFromIdentifier(msgid.msgid));
+        
+        this.setThrowable(cause);
     }
 
     public SqlException(LogWriter logWriter, MessageId messageId, Throwable cause)
@@ -286,7 +288,8 @@
             getErrorCode());
 
         // If we're in a runtime that supports chained exceptions, set the cause 
-        // of the SQLException to be this SqlException.
+        // of the SQLException to be this SqlException.  Otherwise the stack
+        // trace is lost.
          if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
         {
             sqle.initCause(this);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall?rev=386710&r1=386709&r2=386710&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetclientmats.runall Fri Mar 17 12:47:45 2006
@@ -3,3 +3,4 @@
 jdbcapi/xaStateTran.sql
 jdbcapi/lobStreams.java
 jdbcapi/XATest.java
+derbynet/SqlExceptionTest.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java?rev=386710&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java Fri Mar 17 12:47:45 2006
@@ -0,0 +1,86 @@
+/*
+   Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.SqlExceptionTest
+ 
+   Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ 
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+ 
+ */
+package org.apache.derbyTesting.functionTests.tests.derbynet;
+
+import org.apache.derbyTesting.functionTests.util.BaseTestCase;
+import org.apache.derby.client.am.SqlException;
+import org.apache.derby.client.am.MessageId;
+import org.apache.derby.shared.common.reference.SQLState;
+import java.sql.SQLException;
+import java.io.IOException;
+
+/**
+ * This is used for testing the SqlException class.  This test can be added
+ * to.  My itch right now is to verify that exception chaining is working
+ * correctly.
+ */
+
+public class SqlExceptionTest extends BaseTestCase
+{    
+    public SqlExceptionTest(String name)
+    {
+        super(name);
+    }
+    
+    /**
+     * Makes sure exception chaining works correctly (DERBY-1117)
+     */
+    public void testChainedException() {
+        IOException ioe = new IOException("Test exception");
+        SqlException sqle = new SqlException(null,
+            new MessageId(SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION),
+            ioe);
+        SQLException javae = sqle.getSQLException();
+        
+        // The underlying SqlException is the first cause; the IOException
+        // should be the second cause        
+        assertEquals(sqle, javae.getCause());
+        assertEquals(ioe, javae.getCause().getCause());
+        assertNull(sqle.getNextException());
+    }
+    
+    /**
+     * Make sure a SQLException is chained as a nextSQLException()
+     * rather than as a chained exception
+     */
+    public void testNextException() {
+        SQLException nexte = new SQLException("test");
+        SqlException sqle = new SqlException(null,
+            new MessageId(SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION),
+            nexte);
+        SQLException javae = sqle.getSQLException();
+        
+        assertEquals(sqle, javae.getCause());
+        assertNull(javae.getCause().getCause());
+        assertEquals(nexte, javae.getNextException());
+        
+        // Make sure exception chaining works with Derby's SqlException
+        // just as well as java.sql.SQLException
+        SqlException internalException = 
+            new SqlException(null, 
+                new MessageId("08000"));
+        
+        javae = new SqlException(null, 
+            new MessageId(SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION),
+            internalException).getSQLException();
+        
+        assertNotNull(javae.getNextException());
+        assertEquals(javae.getNextException().getSQLState(), "08000");
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native