summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCTransactionManager.java35
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBTransactionManager.java23
-rw-r--r--src/main/java/com/amazon/carbonado/spi/TransactionManager.java28
3 files changed, 64 insertions, 22 deletions
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<JDBCTransaction> {
+ private final JDBCExceptionTransformer mExTransformer;
+
// Weakly reference repository because thread locals are not cleaned up
// very quickly.
private final WeakReference<JDBCRepository> mRepositoryRef;
JDBCTransactionManager(JDBCRepository repository) {
- super(repository.getExceptionTransformer());
+ mExTransformer = repository.getExceptionTransformer();
mRepositoryRef = new WeakReference<JDBCRepository>(repository);
}
@@ -75,20 +78,28 @@ class JDBCTransactionManager extends TransactionManager<JDBCTransaction> {
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);
}
}
}
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBTransactionManager.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBTransactionManager.java
index 58a9e8d..f9b0c6c 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBTransactionManager.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBTransactionManager.java
@@ -22,6 +22,7 @@ import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;
import com.amazon.carbonado.IsolationLevel;
+import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.Transaction;
import com.amazon.carbonado.spi.ExceptionTransformer;
@@ -35,12 +36,14 @@ import com.amazon.carbonado.spi.TransactionManager;
* @author Brian S O'Neill
*/
class BDBTransactionManager<Txn> extends TransactionManager<Txn> {
+ private final ExceptionTransformer mExTransformer;
+
// Weakly reference repository because thread locals are not cleaned up
// very quickly and BDB environments hang on to a ton of memory.
private final WeakReference<BDBRepository<Txn>> mRepositoryRef;
BDBTransactionManager(ExceptionTransformer exTransformer, BDBRepository<Txn> repository) {
- super(exTransformer);
+ mExTransformer = exTransformer;
mRepositoryRef = new WeakReference<BDBRepository<Txn>>(repository);
}
@@ -69,13 +72,21 @@ class BDBTransactionManager<Txn> extends TransactionManager<Txn> {
}
}
- protected boolean commitTxn(Txn txn) throws Exception {
- repository().txn_commit(txn);
- return false;
+ protected boolean commitTxn(Txn txn) throws PersistException {
+ try {
+ repository().txn_commit(txn);
+ return false;
+ } catch (Throwable e) {
+ throw mExTransformer.toPersistException(e);
+ }
}
- protected void abortTxn(Txn txn) throws Exception {
- repository().txn_abort(txn);
+ protected void abortTxn(Txn txn) throws PersistException {
+ try {
+ repository().txn_abort(txn);
+ } catch (Throwable e) {
+ throw mExTransformer.toPersistException(e);
+ }
}
private BDBRepository<Txn> repository() {
diff --git a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java
index 355af7c..676a15d 100644
--- a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java
+++ b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java
@@ -50,6 +50,9 @@ public abstract class TransactionManager<Txn> {
private boolean mClosed;
+ /**
+ * @deprecated
+ */
public TransactionManager(ExceptionTransformer exTransformer) {
// The use of a fair lock is essential for shutdown hooks that attempt
// to acquire the locks of all TransactionManagers. Otherwise, the
@@ -58,8 +61,14 @@ public abstract class TransactionManager<Txn> {
mExTransformer = exTransformer;
}
+ public TransactionManager() {
+ this(null);
+ }
+
/**
* Returns the exception transformer in use.
+ *
+ * @deprecated
*/
public ExceptionTransformer getExceptionTransformer() {
return mExTransformer;
@@ -337,12 +346,12 @@ public abstract class TransactionManager<Txn> {
*
* @return true if transaction object is still valid
*/
- protected abstract boolean commitTxn(Txn txn) throws Exception;
+ protected abstract boolean commitTxn(Txn txn) throws PersistException;
/**
* Aborts and closes the given internal transaction.
*/
- protected abstract void abortTxn(Txn txn) throws Exception;
+ protected abstract void abortTxn(Txn txn) throws PersistException;
private static class TransactionImpl<Txn> implements Transaction {
private final TransactionManager<Txn> mTxnMgr;
@@ -393,9 +402,15 @@ public abstract class TransactionManager<Txn> {
if (!txnMgr.commitTxn(mTxn)) {
mTxn = null;
}
+ } catch (PersistException e) {
+ mTxn = null;
+ throw e;
} catch (Throwable e) {
mTxn = null;
- throw txnMgr.mExTransformer.toPersistException(e);
+ if (txnMgr.mExTransformer != null) {
+ throw txnMgr.mExTransformer.toPersistException(e);
+ }
+ throw new PersistException(e);
}
} else {
// Indicate fake nested transaction committed.
@@ -424,8 +439,13 @@ public abstract class TransactionManager<Txn> {
if (mParent == null || mParent.mTxn != mTxn) {
try {
txnMgr.abortTxn(mTxn);
+ } catch (PersistException e) {
+ throw e;
} catch (Throwable e) {
- throw txnMgr.mExTransformer.toPersistException(e);
+ if (txnMgr.mExTransformer != null) {
+ throw txnMgr.mExTransformer.toPersistException(e);
+ }
+ throw new PersistException(e);
}
}
} finally {