Author: tfischer
Date: Sat May 12 13:41:27 2012
New Revision: 1337539
URL: http://svn.apache.org/viewvc?rev=1337539&view=rev
Log:
Properly closing statements in lockTables and unlockTables
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java?rev=1337539&r1=1337538&r2=1337539&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
Sat May 12 13:41:27 2012
@@ -23,6 +23,9 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* This is used to connect to an embedded Apache Derby Database using
* the supplied JDBC driver.
@@ -37,6 +40,9 @@ public class DBDerby extends AbstractDBA
*/
private static final long serialVersionUID = 6265962681516206415L;
+ /** The class log. */
+ private static Log log = LogFactory.getLog(DBDerby.class);
+
/**
* Empty constructor.
*/
@@ -104,11 +110,31 @@ public class DBDerby extends AbstractDBA
public void lockTable(Connection con, String table)
throws SQLException
{
- Statement statement = con.createStatement();
- StringBuffer stmt = new StringBuffer();
- stmt.append("LOCK TABLE ")
- .append(table).append(" IN EXCLUSIVE MODE");
- statement.executeUpdate(stmt.toString());
+ Statement statement = null;
+ try
+ {
+ statement = con.createStatement();
+ StringBuffer stmt = new StringBuffer();
+ stmt.append("LOCK TABLE ")
+ .append(table).append(" IN EXCLUSIVE MODE");
+ statement.executeUpdate(stmt.toString());
+ statement.close();
+ statement = null;
+ }
+ finally
+ {
+ if (statement != null)
+ {
+ try
+ {
+ statement.close();
+ }
+ catch (SQLException e)
+ {
+ log.warn("Could not close statement", e);
+ }
+ }
+ }
}
/**
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java?rev=1337539&r1=1337538&r2=1337539&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
Sat May 12 13:41:27 2012
@@ -23,6 +23,8 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.torque.sql.Query;
/**
@@ -47,6 +49,9 @@ public class DBMM extends AbstractDBAdap
*/
private static final long serialVersionUID = 7547291410802807010L;
+ /** The class log. */
+ private static Log log = LogFactory.getLog(DBDerby.class);
+
/**
* Empty protected constructor.
*/
@@ -111,10 +116,30 @@ public class DBMM extends AbstractDBAdap
@Override
public void lockTable(Connection con, String table) throws SQLException
{
- Statement statement = con.createStatement();
- StringBuffer stmt = new StringBuffer();
- stmt.append("LOCK TABLE ").append(table).append(" WRITE");
- statement.executeUpdate(stmt.toString());
+ Statement statement = null;
+ try
+ {
+ statement = con.createStatement();
+ StringBuffer stmt = new StringBuffer();
+ stmt.append("LOCK TABLE ").append(table).append(" WRITE");
+ statement.executeUpdate(stmt.toString());
+ statement.close();
+ statement = null;
+ }
+ finally
+ {
+ if (statement != null)
+ {
+ try
+ {
+ statement.close();
+ }
+ catch (SQLException e)
+ {
+ log.warn("Could not close statement", e);
+ }
+ }
+ }
}
/**
@@ -128,8 +153,28 @@ public class DBMM extends AbstractDBAdap
@Override
public void unlockTable(Connection con, String table) throws SQLException
{
- Statement statement = con.createStatement();
- statement.executeUpdate("UNLOCK TABLES");
+ Statement statement = null;
+ try
+ {
+ statement = con.createStatement();
+ statement.executeUpdate("UNLOCK TABLES");
+ statement.close();
+ statement = null;
+ }
+ finally
+ {
+ if (statement != null)
+ {
+ try
+ {
+ statement.close();
+ }
+ catch (SQLException e)
+ {
+ log.warn("Could not close statement", e);
+ }
+ }
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]