[ 
https://issues.apache.org/jira/browse/DERBY-6488?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Knut Anders Hatlen updated DERBY-6488:
--------------------------------------

    Attachment: d6488-2a.diff

Except one call in EmbedResultSet, the Util.newEmbedSQLException() methods were 
only used by Util itself. The attached patch, d6488-2a.diff, makes 
EmbedResultSet use Util.generateCsSQLException() instead, makes Util use 
SQLExceptionFactory directly, and removes all of the newEmbedSQLException() 
methods.

The patch also adds a Throwable parameter to the Util.seeNextException() method 
for the root cause. This was done primarily to allow Util.javaException() to 
reuse it. A side effect of this change is that the "see next" exceptions will 
now include the root cause when you call printStackTrace() on it, and you don't 
have to call getNextException() or consult derby.log in order to see what the 
real problem is.

Example:

Where printStackTrace() previously would give this information:

{noformat}
java.sql.SQLException: Failed to start database 'db' with class loader 
sun.misc.Launcher$AppClassLoader@500ab58d, see the next exception for details.
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:107)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:137)
        at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:287)
...
Caused by: ERROR XJ040: Failed to start database 'db' with class loader 
sun.misc.Launcher$AppClassLoader@500ab58d, see the next exception for details.
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:288)
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:162)
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:74)
{noformat}

It will now give the root cause as well:

{noformat}
java.sql.SQLException: Failed to start database 'db' with class loader 
sun.misc.Launcher$AppClassLoader@500ab58d, see the next exception for details.
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:107)
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:133)
        at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:255)
...
Caused by: ERROR XJ040: Failed to start database 'db' with class loader 
sun.misc.Launcher$AppClassLoader@500ab58d, see the next exception for details.
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:288)
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:162)
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:74)
        ... 20 more
Caused by: ERROR XCW00: Unsupported upgrade from '10.10' to '10.11 beta'.
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:288)
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:283)
        at 
org.apache.derby.iapi.services.monitor.Monitor.isFullUpgrade(Monitor.java:717)
...
{noformat}

All regression tests ran cleanly with the patch.

> Get rid of the EmbedSQLException class
> --------------------------------------
>
>                 Key: DERBY-6488
>                 URL: https://issues.apache.org/jira/browse/DERBY-6488
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.11.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: d6488-1a.diff, d6488-2a.diff
>
>
> EmbedSQLException used to be the top-level exception raised on error in the 
> JDBC 3 version of the embedded driver. The primary purpose of the 
> EmbedSQLException class is gone now that JDBC 4.0 is the minimum JDBC level, 
> and all top-level exceptions are vanilla java.sql.SQLExceptions or one of its 
> specialized subtypes.
> The top-level SQLException still links to an EmbedSQLException in order to 
> provide some extra information (such as the message id) that the network 
> server needs when encoding the exception for transport over the wire. I think 
> it should be possible for the network server to get this information from the 
> StandardException which is typically also in the exception chain.
> When embedded Derby raises an exception currently, it is typically a 
> java.sql.SQLException (or subclass) that's linked to an EmbedSQLException 
> that's linked to a StandardException. If we could find a way to eliminate the 
> EmbedSQLException from the exception chain, the stack traces would be easier 
> to read, and the structure of the exception chains would be more consistent 
> with the client exceptions.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to