I don't think this particular patch is correct. First of all it calls 
"select.close()" twice, second nesting of close operations is suspect 
(select.close() after c.commit()).

On the general semantics of JDBC code. What are are normally using in Cayenne 
(with the exception of a few overlooked cases like this one), is a nested set 
of try { } finally {} over ResultSet, Statement, Connection. This ensures that 
"close" is called in the right sequence and regardless of the exception state. 
Also this seems to work pretty well (no bugs were reported that I can attribute 
to this code).

Andrus

On Feb 16, 2011, at 10:56 AM, [email protected] wrote:
> Modified: 
> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java
> URL: 
> http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java?rev=1071175&r1=1071174&r2=1071175&view=diff
> ==============================================================================
> --- 
> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java
>  (original)
> +++ 
> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java
>  Wed Feb 16 08:56:55 2011
> @@ -58,9 +58,10 @@ public class DerbyPkGenerator extends Jd
>        }
> 
>        Connection c = node.getDataSource().getConnection();
> +        PreparedStatement select = null;
> 
>        try {
> -            PreparedStatement select = c.prepareStatement(
> +            select = c.prepareStatement(
>                    SELECT_QUERY,
>                    ResultSet.TYPE_FORWARD_ONLY,
>                    ResultSet.CONCUR_UPDATABLE);
> @@ -91,6 +92,9 @@ public class DerbyPkGenerator extends Jd
>            return nextId;
>        }
>        finally {
> +            if (select != null) {
> +                select.close();
> +            }
>            c.close();
>        }
>    }

Reply via email to