From f4b5012d20abe94c62e8d3b3c3d8ed626dff925b Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 23 Oct 2007 18:09:08 +0000 Subject: Deprecated use of ExceptionTransformer in TransactionManager. --- .../repo/jdbc/JDBCTransactionManager.java | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/jdbc') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java index 7fa3fcc..862152d 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import com.amazon.carbonado.FetchException; import com.amazon.carbonado.IsolationLevel; +import com.amazon.carbonado.PersistException; import com.amazon.carbonado.Transaction; import com.amazon.carbonado.spi.TransactionManager; @@ -34,12 +35,14 @@ import com.amazon.carbonado.spi.TransactionManager; * @author Brian S O'Neill */ class JDBCTransactionManager extends TransactionManager { + private final JDBCExceptionTransformer mExTransformer; + // Weakly reference repository because thread locals are not cleaned up // very quickly. private final WeakReference mRepositoryRef; JDBCTransactionManager(JDBCRepository repository) { - super(repository.getExceptionTransformer()); + mExTransformer = repository.getExceptionTransformer(); mRepositoryRef = new WeakReference(repository); } @@ -75,20 +78,28 @@ class JDBCTransactionManager extends TransactionManager { return new JDBCTransaction(repo.getConnectionForTxn(level)); } - protected boolean commitTxn(JDBCTransaction txn) throws SQLException { - txn.commit(); - return true; + protected boolean commitTxn(JDBCTransaction txn) throws PersistException { + try { + txn.commit(); + return true; + } catch (Throwable e) { + throw mExTransformer.toPersistException(e); + } } - protected void abortTxn(JDBCTransaction txn) throws SQLException, FetchException { - Connection con; - if ((con = txn.abort()) != null) { - JDBCRepository repo = mRepositoryRef.get(); - if (repo == null) { - con.close(); - } else { - repo.yieldConnection(con); + protected void abortTxn(JDBCTransaction txn) throws PersistException { + try { + Connection con; + if ((con = txn.abort()) != null) { + JDBCRepository repo = mRepositoryRef.get(); + if (repo == null) { + con.close(); + } else { + repo.yieldConnection(con); + } } + } catch (Throwable e) { + throw mExTransformer.toPersistException(e); } } } -- cgit v1.2.3