OPENJPA-2440 close connection after not using it anymore

this prevents leaks like the one reported by rmannibucau.


git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1533641 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Struberg 2013-10-18 21:28:57 +00:00
parent 67082453b3
commit a76249e143

View File

@ -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.
*/