groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject groovy git commit: Move create statements to try block
Date Sat, 13 Feb 2016 20:18:16 GMT
Repository: groovy
Updated Branches:
  refs/heads/master ce1727dc2 -> 8f122af6a


Move create statements to try block

Ensure that if SQLException is thrown connection is closed, important if DataSource is used.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8f122af6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8f122af6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8f122af6

Branch: refs/heads/master
Commit: 8f122af6a6d34f86795939d4d3a381a5374486e8
Parents: ce1727d
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sat Feb 13 12:08:24 2016 -0800
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Sat Feb 13 12:15:58 2016 -0800

----------------------------------------------------------------------
 subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/8f122af6/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
index 72ceebe..1345486 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
@@ -217,7 +217,7 @@ import static org.codehaus.groovy.runtime.SqlGroovyMethods.toRowResult;
  * For advanced usage, the class provides numerous extension points for overriding the
  * facade behavior associated with the various aspects of managing
  * the interaction with the underlying database.
- *
+ * <p>
  * This class is <b>not</b> thread-safe.
  *
  * @author Chris Stevenson
@@ -951,9 +951,10 @@ public class Sql {
      */
     public void query(String sql, Closure closure) throws SQLException {
         Connection connection = createConnection();
-        Statement statement = getStatement(connection, sql);
+        Statement statement = null;
         ResultSet results = null;
         try {
+            statement = getStatement(connection, sql);
             results = statement.executeQuery(sql);
             closure.call(results);
         } catch (SQLException e) {
@@ -1182,9 +1183,10 @@ public class Sql {
      */
     public void eachRow(String sql, Closure metaClosure, int offset, int maxRows, Closure
rowClosure) throws SQLException {
         Connection connection = createConnection();
-        Statement statement = getStatement(connection, sql);
+        Statement statement = null;
         ResultSet results = null;
         try {
+            statement = getStatement(connection, sql);
             results = statement.executeQuery(sql);
             if (metaClosure != null) metaClosure.call(results.getMetaData());
             boolean cursorAtRow = moveCursor(results, offset);
@@ -3003,9 +3005,10 @@ public class Sql {
      */
     public int call(String sql, List<Object> params) throws Exception {
         Connection connection = createConnection();
-        CallableStatement statement = connection.prepareCall(sql);
+        CallableStatement statement = null;
         try {
             LOG.fine(sql + " | " + params);
+            statement = connection.prepareCall(sql);
             setParameters(params, statement);
             configure(statement);
             return statement.executeUpdate();


Mime
View raw message