Author: tfischer Date: Wed Jul 25 05:17:28 2012 New Revision: 1365449 URL: http://svn.apache.org/viewvc?rev=1365449&view=rev Log: do not use Torque.getConnection() and Torque.closeConnection() - this kills pluggable transaction handling
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java?rev=1365449&r1=1365448&r2=1365449&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java Wed Jul 25 05:17:28 2012 @@ -235,7 +235,7 @@ public class IDBroker implements Runnabl Connection dbCon = null; try { - dbCon = Torque.getConnection(databaseName); + dbCon = Transaction.begin(databaseName); } catch (Throwable t) { @@ -247,6 +247,8 @@ public class IDBroker implements Runnabl try { transactionsSupported = dbCon.getMetaData().supportsTransactions(); + Transaction.commit(dbCon); + dbCon = null; } catch (Exception e) { @@ -258,16 +260,9 @@ public class IDBroker implements Runnabl } finally { - try - { - // Return the connection to the pool. - dbCon.close(); - } - catch (Exception e) + if (dbCon != null) { - log.warn("Could not close the connection which was used " - + "for testing whether transactions are supported", - e); + Transaction.safeRollback(dbCon); } } if (!transactionsSupported) @@ -512,22 +507,19 @@ public class IDBroker implements Runnabl Connection dbCon = null; try { - dbCon = Torque.getConnection(databaseName); + dbCon = Transaction.begin(databaseName); Statement statement = dbCon.createStatement(); ResultSet rs = statement.executeQuery(query); exists = rs.next(); statement.close(); + Transaction.commit(dbCon); + dbCon = null; } finally { - // Return the connection to the pool. - try + if (dbCon != null) { - dbCon.close(); - } - catch (Exception e) - { - log.error("Release of connection failed.", e); + Transaction.safeRollback(dbCon); } } return exists; @@ -736,7 +728,7 @@ public class IDBroker implements Runnabl { if (useNewConnection) { - Transaction.rollback(connection); + Transaction.safeRollback(connection); } throw e; } @@ -794,8 +786,7 @@ public class IDBroker implements Runnabl if (connection == null || configuration .getBoolean(DB_IDBROKER_USENEWCONNECTION, true)) { - // Get a connection to the db - dbCon = Torque.getConnection(databaseName); + dbCon = Transaction.begin(databaseName); } // Read the row from the ID_TABLE. @@ -804,6 +795,8 @@ public class IDBroker implements Runnabl // QUANTITY column. quantity = results[1]; quantityStore.put(tableName, quantity); + Transaction.commit(dbCon); + dbCon = null; } catch (Exception e) { @@ -811,14 +804,9 @@ public class IDBroker implements Runnabl } finally { - // Return the connection to the pool. - try - { - dbCon.close(); - } - catch (Exception e) + if (dbCon != null) { - log.error("Release of connection failed.", e); + Transaction.safeRollback(dbCon); } } } Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java?rev=1365449&r1=1365448&r2=1365449&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java Wed Jul 25 05:17:28 2012 @@ -206,13 +206,18 @@ public class BasePeerImpl implements Ser Connection con = null; try { - // Get a connection to the db. - con = Torque.getConnection(Torque.getDefaultDB()); - return deleteAll(con, table, column, value); + con = Transaction.begin(Torque.getDefaultDB()); + int result = deleteAll(con, table, column, value); + Transaction.commit(con); + con = null; + return result; } finally { - Torque.closeConnection(con); + if (con != null) + { + Transaction.safeRollback(con); + } } } @@ -1924,17 +1929,21 @@ public class BasePeerImpl implements Ser throws TorqueException { Connection con = null; - int rowCount = -1; try { - con = Torque.getConnection(dbName); - rowCount = executeStatement(statementString, con); + con = Transaction.begin(dbName); + int rowCount = executeStatement(statementString, con); + Transaction.commit(con); + con = null; + return rowCount; } finally { - Torque.closeConnection(con); + if (con != null) + { + Transaction.safeRollback(con); + } } - return rowCount; } /** Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java?rev=1365449&r1=1365448&r2=1365449&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java Wed Jul 25 05:17:28 2012 @@ -584,7 +584,7 @@ public class LargeSelect<T> implements R } // Get a connection to the db. - conn = Torque.getConnection(dbName); + conn = Transaction.begin(dbName); // Execute the query. if (log.isDebugEnabled()) @@ -686,6 +686,9 @@ public class LargeSelect<T> implements R log.debug("run(): - blockEnd: " + blockEnd); log.debug("run(): - results.size(): " + results.size()); } + + Transaction.commit(conn); + conn = null; } catch (Exception e) { @@ -693,7 +696,10 @@ public class LargeSelect<T> implements R } finally { - Torque.closeConnection(conn); + if (conn != null) + { + Transaction.safeRollback(conn); + } threadRunning = false; // Make sure getResults() finally returns if we die. @@ -1157,6 +1163,7 @@ public class LargeSelect<T> implements R * * @return some basic information about this instance of LargeSelect. */ + @Override public String toString() { StringBuffer result = new StringBuffer(); --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org For additional commands, e-mail: torque-dev-h...@db.apache.org