db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel John Debrunner (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-3448) Allow the MailJdbc system test to run under junit.
Date Tue, 26 Feb 2008 23:34:51 GMT

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

Daniel John Debrunner commented on DERBY-3448:
----------------------------------------------

I think that's because your save state and reset logic is not laid out correctly. The code
is logically currently laid out like this:

 boolean ac = conn.getAutoCommit();
 try {
   // do SQL stuff
  conn.setAutoCommit(ac);
 } catch (SQLException sqle)
 {
   // error handling
 }

The issue with this is that if the SQL stuff throws an exception then you will never reset
the auto-commit state (and the isolation state in the real code).

If you want to ensure the state is always reset then you need to put in the finally block,
or after the try-catch block if the catch block does not re-thrown an exception, e.g.

boolean ac = conn.getAutoCommit();
 try {
   // do SQL stuff
  
 } catch (SQLException sqle)
 {
   // error handling
 }
 finallly {
 {
    conn.setAutoCommit(ac);
 }

Now this does lead to your outer method having to throw SQLException, but I think that's just
a fact of life with JDBC applications.

In fact the whole code may become clearer if you only catch SQLException's at a very high
level rather than in each logical operation.
So only have try/catch blocks where you need to perform some action (e.g. rollback, resetting
connection state) rather than just for error logging.

> Allow the MailJdbc system test to run under junit.
> --------------------------------------------------
>
>                 Key: DERBY-3448
>                 URL: https://issues.apache.org/jira/browse/DERBY-3448
>             Project: Derby
>          Issue Type: Improvement
>          Components: Test
>            Reporter: Daniel John Debrunner
>            Assignee: Manjula Kutty
>            Priority: Minor
>         Attachments: DERBY-3448_diff.txt_02_26_ver2.txt, DERBY-3448_diff_02_26.txt, DERBY-3448_stat_02_26.txt,
derby_3448_dbtasks_cleanup.txt
>
>
> It would be good to get the mailjdbc test to run under junit to allow use of the utilities
there and decorators such as running the test getting all connections from a data source with
a statement caching.
> Could still allow the test to run standalone in its current form

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message