Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 2005 invoked from network); 28 May 2007 14:01:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 May 2007 14:01:24 -0000 Received: (qmail 17842 invoked by uid 500); 28 May 2007 14:01:28 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 17799 invoked by uid 500); 28 May 2007 14:01:28 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 17788 invoked by uid 99); 28 May 2007 14:01:28 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 May 2007 07:01:28 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 May 2007 07:01:22 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 9389E1A981A; Mon, 28 May 2007 07:01:02 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070528140102.9389E1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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) | | (...) | * |======================| |======================| |======================| * + * *

A plain local connection must 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 Throwable in an SQLException. + * + * @param thrownException a Throwable + * @return thrownException, if it is an + * SQLException; otherwise, an SQLException which + * wraps thrownException + */ 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); } /*