db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aaron Digulla (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-4443) Wrap rollback in exception handlers in try-catch
Date Wed, 16 Mar 2011 19:21:29 GMT

    [ https://issues.apache.org/jira/browse/DERBY-4443?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007637#comment-13007637

Aaron Digulla commented on DERBY-4443:

The usual solution is to use a mock connection that throws Exceptions when rollback() is called.

If you look at the code, then you'll see that the connection is created with a call to getDefaultConn().
This will query the InternalDriver for a connection.

In your tests, extend InternalDriver and override connect() to return a connection object
which throws exceptions for prepareStatement() and rollback():

public PreparedStatement prepareStatement(String sql) { throw SQLException( "Error in prepareStatement"
); }

public void rollback() { throw SQLException( "Error in rollback" ); }

Make sure that correct exception is visible outside.

Note that this messes with internal static variables. To fix that, you may need to create
a new driver instance in the tearDown() of your tests.

> Wrap rollback in exception handlers in try-catch
> ------------------------------------------------
>                 Key: DERBY-4443
>                 URL: https://issues.apache.org/jira/browse/DERBY-4443
>             Project: Derby
>          Issue Type: Bug
>          Components: Demos/Scripts, Documentation, Eclipse Plug-in, JDBC, Network Client,
Network Server, Replication, Services, SQL, Test, Tools
>    Affects Versions:
>            Reporter: Aaron Digulla
>              Labels: derby_triage10_8
>         Attachments: DERBY-4443.patch
> Avoid this pattern everywhere:
> 		}catch(SQLException se){
> 			//issue a rollback on any errors
> 			conn.rollback();
> 			throw  se;
> 		}
> because an error in rollback will shadow the original exception.

This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

View raw message