openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1533640 - /openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
Date Fri, 18 Oct 2013 21:25:56 GMT
Author: struberg
Date: Fri Oct 18 21:25:56 2013
New Revision: 1533640

URL: http://svn.apache.org/r1533640
Log:
OPENJPA-2440 close connection after not using it anymore

this prevents leaks like the one reported by rmannibucau.

Modified:
    openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java

Modified: openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java?rev=1533640&r1=1533639&r2=1533640&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
(original)
+++ openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
Fri Oct 18 21:25:56 2013
@@ -438,11 +438,17 @@ public class SchemaTool {
             for (int j = 0; j < ts.length; j++)
                 tables.add(ts[j]);
         }
-        Table[] tableArray = (Table[]) tables.toArray(new Table[tables.size()]);
-        String[] sql = _conf.getDBDictionaryInstance()
-            .getDeleteTableContentsSQL(tableArray,_ds.getConnection());
-        if (!executeSQL(sql))
-            _log.warn(_loc.get("delete-table-contents"));
+        Table[] tableArray = tables.toArray(new Table[tables.size()]);
+        Connection conn = _ds.getConnection();
+        try {
+            String[] sql = _conf.getDBDictionaryInstance()
+                .getDeleteTableContentsSQL(tableArray, conn);
+            if (!executeSQL(sql)) {
+                _log.warn(_loc.get("delete-table-contents"));
+            }
+        } finally {
+            closeConnection(conn);
+        }
     }
 
     /**
@@ -1099,7 +1105,13 @@ public class SchemaTool {
      */
     public boolean dropForeignKey(ForeignKey fk)
         throws SQLException {
-        return executeSQL(_dict.getDropForeignKeySQL(fk,_ds.getConnection()));
+        Connection conn = _ds.getConnection();
+        try {
+            return executeSQL(_dict.getDropForeignKeySQL(fk,conn));
+        } finally {
+            closeConnection(conn);
+        }
+
     }
 
     /**
@@ -1240,11 +1252,14 @@ public class SchemaTool {
                 }
             }
             finally {
-                if (!wasAuto)
+                if (!wasAuto) {
                     conn.setAutoCommit(false);
+                }
+
                 try {
-                    conn.close();
+                    closeConnection(conn);
                 } catch (SQLException se) {
+                    //X TODO why catch silently?
                 }
             }
         } else {
@@ -1538,6 +1553,12 @@ public class SchemaTool {
         return true;
     }
 
+    private void closeConnection(Connection conn) throws SQLException {
+        if (conn != null && !conn.isClosed()) {
+            conn.close();
+        }
+    }
+
     /**
      * Run flags.
      */



Mime
View raw message