You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Maciek Siemczyk (JIRA)" <ji...@apache.org> on 2016/05/04 21:02:12 UTC

[jira] [Commented] (DBUTILS-112) Provide DbUtils.rollbackQuietly() method

    [ https://issues.apache.org/jira/browse/DBUTILS-112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15271430#comment-15271430 ] 

Maciek Siemczyk commented on DBUTILS-112:
-----------------------------------------

I would like to second adding this. I don't think this library should dictate how we structure our code and therefore there is a need for rollbackQueitly().

For example our code is structured similarly to this:

try {
 connectToDatabases();
 
 try (PreparedStatement selectStatement = readDbConnection.prepareStatement();
      PreparedStatement insertStatement = writeDbConnection.prepareStatement()) {
 
    // bunch of code in here
 
    } catch (SQLException exception) {
        final String message = "Database error occured during XXXXX.";
                    
        try {
            writeDbConnection.rollback();
        } catch (SQLException rollbackException) {
        }

        log.error(message, exception);
        throw new SQLException(message, exception);
    }
} finally {
    DbUtils.closeQuietly(writeDbConnection);
    DbUtils.closeQuietly(readDbConnection);
}

The way code is structured the null is not possible writeDbConnection on the catch block, but I also don't care if rollback failed as we are exiting anyways. So instead of wrapping rollback everywhere I would prefer to call DbUtils.rollbackQuietly() even for the sake of improving code coverage it is worth in my opinion.

I modified your code myself and will be adding patch for it shortly. I hope this can be included in 1.7 release.


> Provide DbUtils.rollbackQuietly() method
> ----------------------------------------
>
>                 Key: DBUTILS-112
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-112
>             Project: Commons DbUtils
>          Issue Type: Wish
>    Affects Versions: 1.5
>            Reporter: alexander brack
>            Priority: Trivial
>              Labels: features
>             Fix For: 1.7
>
>   Original Estimate: 5m
>  Remaining Estimate: 5m
>
> One has to surround DbUtils.rollback(conn) method-call with try/catch wich produces cluttered code. Connection has to remain open, that's why DbUtils.rollbackAndCloseQuietly(conn) method is ruled out.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)