Hi.

Bug #870 describes that Statements and ResultSets are not always closed in 
SQLEngine.load().

The same applies to SQLEngine.delete(). If any of the three 
PersistenceExceptions is thrown, the statement will never get closed.

As a general rule I would suggest, that all resources HAVE to be put into a "try 
- finally" block. Otherwise, a Bug like #870 will occur again and again. To make 
the code more readable, I would add a small helper method to close statements 
and connections:

----+----+----+----+----+----
public void methodLikeSQLEngineDelete(Object conn) {
     PreparedStatement stmt = null;
     try {
         stmt = ...;
     }
     finally {
         closeStatement(stmt);
     }
}

protected void closeStatement(Statement statement) {
     if (statement != null) {
         try {
             statement.close();
         }
         catch (Exception e) {}
         statement = null;
     }
}

protected void closeConnection(Connection connection) {
     if (connection != null) {
         try {
             connection.close();
         }
         catch (Exception e) {}
         connection = null;
     }
}
----+----+----+----+----+----


Martin

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to