From f73f19bf0661afb489e0c17a2d987257865003dc Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 23 Oct 2009 20:41:25 +0000 Subject: Allow transaction implementation to be notified when update mode is selected. --- src/main/java/com/amazon/carbonado/txn/TransactionManager.java | 10 ++++++++++ src/main/java/com/amazon/carbonado/txn/TransactionScope.java | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/com/amazon/carbonado/txn/TransactionManager.java b/src/main/java/com/amazon/carbonado/txn/TransactionManager.java index 4914be9..528ade5 100644 --- a/src/main/java/com/amazon/carbonado/txn/TransactionManager.java +++ b/src/main/java/com/amazon/carbonado/txn/TransactionManager.java @@ -198,6 +198,16 @@ public abstract class TransactionManager { protected void reuseTxn(Txn txn) throws Exception { } + /** + * Called when the Transaction.setForUpdate method is called. The default + * implementation of this method does nothing. Override if internal + * transaction needs to switch modes. + * + * @since 1.2.1 + */ + protected void setForUpdate(Txn txn, boolean forUpdate) { + } + /** * Commits and closes the given internal transaction. * diff --git a/src/main/java/com/amazon/carbonado/txn/TransactionScope.java b/src/main/java/com/amazon/carbonado/txn/TransactionScope.java index 1e294e4..29c173c 100644 --- a/src/main/java/com/amazon/carbonado/txn/TransactionScope.java +++ b/src/main/java/com/amazon/carbonado/txn/TransactionScope.java @@ -408,7 +408,11 @@ public class TransactionScope { } public void setForUpdate(boolean forUpdate) { - mForUpdate = forUpdate && mScope.mTxnMgr.supportsForUpdate(); + mForUpdate = (forUpdate &= mScope.mTxnMgr.supportsForUpdate()); + Txn txn = mTxn; + if (txn != null) { + mScope.mTxnMgr.setForUpdate(txn, forUpdate); + } } public boolean isForUpdate() { @@ -472,6 +476,9 @@ public class TransactionScope { mDesiredLockTimeout, mTimeoutUnit); } } + if (mForUpdate) { + scope.mTxnMgr.setForUpdate(mTxn, true); + } return mTxn; } -- cgit v1.2.3