db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r542232 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
Date Mon, 28 May 2007 14:01:02 GMT
Author: kahatlen
Date: Mon May 28 07:01:01 2007
New Revision: 542232

URL: http://svn.apache.org/viewvc?view=rev&rev=542232
Log:
DERBY-1440: jdk 1.6 client driver omits SQLStates and chained
exceptions in error messages

Follow-up patch which simplifies wrapInSQLException() and improves the
comments.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java?view=diff&rev=542232&r1=542231&r2=542232
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TransactionResourceImpl.java
Mon May 28 07:01:01 2007
@@ -101,6 +101,7 @@
  * |  (EmbedStatement)    |  |  (EmbedResultSet)    |  |  (...)               |
  * |======================|  |======================|  |======================|
  *
+ * </PRE>
  * <P>A plain local connection <B>must</B> be attached (doubly linked with)
to a
  * TransactionResource at all times.  A detachable connection can be without a
  * TransactionResource, and a TransactionResource for an XATransaction
@@ -127,7 +128,7 @@
 	protected Database database;
 	protected LanguageConnectionContext lcc;
 
-	/*
+	/**
 	 * create a brand new connection for a brand new transaction
 	 */
 	TransactionResourceImpl(
@@ -159,7 +160,7 @@
 		cm = csf.newContextManager();
 	}
 
-	/*
+	/**
 	 * Called only in EmbedConnection construtor.
 	 * The Local Connection sets up the database in its constructor and sets it
 	 * here.
@@ -187,7 +188,7 @@
 		lcc = database.setupConnection(cm, username, drdaID, dbname);
 	}
 
-	/*
+	/**
 	 * Return instance variables to EmbedConnection.  RESOLVE: given time, we
 	 * should perhaps stop giving out reference to these things but instead use
 	 * the transaction resource itself.
@@ -199,7 +200,7 @@
 		return  csf;
 	}
 
-	/*
+	/**
 	 * need to be public because it is in the XATransactionResource interface
 	 */
 	ContextManager getContextManager() {
@@ -225,7 +226,7 @@
 		return se;
 	}
 
-	/*
+	/**
 	 * local transaction demarcation - note that global or xa transaction
 	 * cannot commit thru the connection, they can only commit thru the
 	 * XAResource, which uses the xa_commit or xa_rollback interface as a 
@@ -284,7 +285,7 @@
 	 * exception handling
 	 */
 
-	/*
+	/**
 	 * clean up the error and wrap the real exception in some SQLException.
 	 */
 	final SQLException handleException(Throwable thrownException,
@@ -360,37 +361,46 @@
 		}
 
 	}
-		 
+
+    /**
+     * Wrap a <code>Throwable</code> in an <code>SQLException</code>.
+     *
+     * @param thrownException a <code>Throwable</code>
+     * @return <code>thrownException</code>, if it is an
+     * <code>SQLException</code>; otherwise, an <code>SQLException</code>
which
+     * wraps <code>thrownException</code>
+     */
 	public static SQLException wrapInSQLException(Throwable thrownException) {
 
 		if (thrownException == null)
 			return null;
 
-		SQLException nextSQLException;
-
 		if (thrownException instanceof SQLException) {
-
-			// server side JDBC can end up with a SQLException in the nested stack
-			nextSQLException = (SQLException) thrownException;
+            // Server side JDBC can end up with a SQLException in the nested
+            // stack. Return the exception with no wrapper.
+            return (SQLException) thrownException;
 		}
-		else if (thrownException instanceof StandardException) {
+
+        if (thrownException instanceof StandardException) {
 
 			StandardException se = (StandardException) thrownException;
 
             if (se.getCause() == null) {
-                nextSQLException = Util.generateCsSQLException(se);
-            } else {
-                nextSQLException = Util.seeNextException(se.getMessageId(),
-                        se.getArguments(), wrapInSQLException(se.getCause()));
+                // se is a single, unchained exception. Just convert it to an
+                // SQLException.
+                return Util.generateCsSQLException(se);
             }
 
-		} else {
-
-			nextSQLException = Util.javaException(thrownException);
-
-		}
+            // se contains a non-empty exception chain. We want to put all of
+            // the exceptions (including Java exceptions) in the next-exception
+            // chain. Therefore, call wrapInSQLException() recursively to
+            // convert the cause chain into a chain of SQLExceptions.
+            return Util.seeNextException(se.getMessageId(),
+                        se.getArguments(), wrapInSQLException(se.getCause()));
+        }
 
-		return nextSQLException;
+        // thrownException is a Java exception
+        return Util.javaException(thrownException);
 	}
 
 	/*



Mime
View raw message