cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r1072900 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java
Date Mon, 21 Feb 2011 09:22:31 GMT
Author: andrey
Date: Mon Feb 21 09:22:31 2011
New Revision: 1072900

URL: http://svn.apache.org/viewvc?rev=1072900&view=rev
Log:
correct exception handling in DerbyPkGenerator

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java

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=1072900&r1=1072899&r2=1072900&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
Mon Feb 21 09:22:31 2011
@@ -58,43 +58,44 @@ public class DerbyPkGenerator extends Jd
         }
 
         Connection c = node.getDataSource().getConnection();
-        PreparedStatement select = null;
-
         try {
-            select = c.prepareStatement(
+            PreparedStatement select = c.prepareStatement(
                     SELECT_QUERY,
                     ResultSet.TYPE_FORWARD_ONLY,
                     ResultSet.CONCUR_UPDATABLE);
-
-            select.setString(1, entity.getName());
-            ResultSet rs = select.executeQuery();
-
-            if (!rs.next()) {
-                throw new CayenneException("PK lookup failed for table: "
-                        + entity.getName());
+            try {
+                select.setString(1, entity.getName());
+                ResultSet rs = select.executeQuery();
+    
+                try {
+                    if (!rs.next()) {
+                        throw new CayenneException("PK lookup failed for table: "
+                                + entity.getName());
+                    }
+        
+                    long nextId = rs.getLong(1);
+        
+                    rs.updateLong(1, nextId + pkCacheSize);
+                    rs.updateRow();
+        
+                    if (rs.next()) {
+                        throw new CayenneException("More than one PK record for table: "
+                                + entity.getName());
+                    }
+                    
+                    c.commit();
+
+                    return nextId;
+                }
+                finally {
+                    rs.close();
+                }
             }
-
-            long nextId = rs.getLong(1);
-
-            rs.updateLong(1, nextId + pkCacheSize);
-            rs.updateRow();
-
-            if (rs.next()) {
-                throw new CayenneException("More than one PK record for table: "
-                        + entity.getName());
+            finally {
+                select.close();
             }
-
-            rs.close();
-
-            select.close();
-            c.commit();
-
-            return nextId;
         }
         finally {
-            if (select != null) {
-                select.close();
-            }
             c.close();
         }
     }



Mime
View raw message