diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2007-11-04 00:36:29 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2007-11-04 00:36:29 +0000 |
commit | 67ae8e7430ed8222ba7582fcf3dfd8ce62b62c5d (patch) | |
tree | 3c29b77d1ac7f120a4294c203f086995452933d2 /src/main/java/com/amazon/carbonado/spi | |
parent | 4063328f97c0180ceab565cc3f411e3dcc07bca8 (diff) |
Reduce creation of unnecessary nested transactions. Added feature to JDBCRepository to suppress Storable reloading after insert or update.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/spi')
-rw-r--r-- | src/main/java/com/amazon/carbonado/spi/TransactionManager.java | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java index f16f548..fe08a01 100644 --- a/src/main/java/com/amazon/carbonado/spi/TransactionManager.java +++ b/src/main/java/com/amazon/carbonado/spi/TransactionManager.java @@ -249,7 +249,7 @@ public abstract class TransactionManager<Txn> { /**
* Returns null if no transaction is in progress.
*
- * @throws Exception thrown by createTxn
+ * @throws Exception thrown by createTxn or reuseTxn
*/
public Txn getTxn() throws Exception {
mLock.lock();
@@ -342,6 +342,17 @@ public abstract class TransactionManager<Txn> { }
/**
+ * Called when a transaction is about to be reused. The default
+ * implementation of this method does nothing. Override if any preparation
+ * is required to ready a transaction for reuse.
+ *
+ * @param txn transaction to reuse, never null
+ * @since 1.1.3
+ */
+ protected void reuseTxn(Txn txn) throws Exception {
+ }
+
+ /**
* Commits and closes the given internal transaction.
*
* @return true if transaction object is still valid
@@ -502,13 +513,28 @@ public abstract class TransactionManager<Txn> { // Caller must hold mLock.
Txn getTxn() throws Exception {
- if (mTxn == null) {
- TransactionManager<Txn> txnMgr = mTxnMgr;
- Txn parent = (mParent == null || mTop) ? null : mParent.getTxn();
+ TransactionManager<Txn> txnMgr = mTxnMgr;
+ if (mTxn != null) {
+ txnMgr.reuseTxn(mTxn);
+ } else {
+ Txn parentTxn;
+ if (mParent == null || mTop) {
+ parentTxn = null;
+ } else if ((parentTxn = mParent.mTxn) == null) {
+ // No point in creating nested transaction if parent
+ // has never been used. Create parent transaction
+ // and use it in child transaction, just like a fake
+ // nested transaction.
+ if ((parentTxn = mParent.getTxn()) != null) {
+ return mTxn = parentTxn;
+ }
+ // Isolation level of parent is none, so proceed to create
+ // a real transaction.
+ }
if (mTimeoutUnit == null) {
- mTxn = txnMgr.createTxn(parent, mLevel);
+ mTxn = txnMgr.createTxn(parentTxn, mLevel);
} else {
- mTxn = txnMgr.createTxn(parent, mLevel, mDesiredLockTimeout, mTimeoutUnit);
+ mTxn = txnMgr.createTxn(parentTxn, mLevel, mDesiredLockTimeout, mTimeoutUnit);
}
}
return mTxn;
|