Author: ozeigermann Date: Sat Aug 18 15:20:30 2007 New Revision: 567333 URL: http://svn.apache.org/viewvc?view=rev&rev=567333 Log: Fixed broken complex transaction
Modified: commons/proper/transaction/branches/TRANSACTION_2/RELEASE-NOTES.txt commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/DefaultTransaction.java commons/proper/transaction/branches/TRANSACTION_2/src/test/org/apache/commons/transaction/DefaultTransactionTest.java Modified: commons/proper/transaction/branches/TRANSACTION_2/RELEASE-NOTES.txt URL: http://svn.apache.org/viewvc/commons/proper/transaction/branches/TRANSACTION_2/RELEASE-NOTES.txt?view=diff&rev=567333&r1=567332&r2=567333 ============================================================================== --- commons/proper/transaction/branches/TRANSACTION_2/RELEASE-NOTES.txt (original) +++ commons/proper/transaction/branches/TRANSACTION_2/RELEASE-NOTES.txt Sat Aug 18 15:20:30 2007 @@ -1,7 +1,7 @@ -Commons Transaction Release 2.0 ---------------------------------------- +Commons Transaction Release 2.0 beta1 +------------------------------------- -RELEASE NUMBER: 2.0 +RELEASE NUMBER: 2.0b1 RELEASE TAG / BRANCH: none yet / TRANSACTION_2 DESCRIPTION @@ -22,7 +22,7 @@ JDK COMPATIBILITIES ------------------- -Commons Transaction 2 requires JDK 1.5 or up +Commons Transaction 2 requires JDK 1.6 or up KNOWN ISSUES ------------ Modified: commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java URL: http://svn.apache.org/viewvc/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java?view=diff&rev=567333&r1=567332&r2=567333 ============================================================================== --- commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java (original) +++ commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java Sat Aug 18 15:20:30 2007 @@ -42,6 +42,8 @@ private String name; + private boolean partofComplexTransaction = false; + protected abstract T createContext(); public AbstractTransactionalResourceManager(String name) { @@ -88,6 +90,7 @@ txContext.dispose(); setActiveTx(null); + partofComplexTransaction = false; } @Override @@ -164,7 +167,8 @@ } public void dispose() { - getLm().endWork(); + if (!isPartofComplexTransaction()) + getLm().endWork(); } public void commit() { @@ -176,7 +180,7 @@ } public boolean prepare() { - return isMarkedForRollback(); + return !isMarkedForRollback(); } } @@ -209,7 +213,7 @@ T txContext = createContext(); txContext.join(); setActiveTx(txContext); - + partofComplexTransaction = true; } @Override @@ -217,6 +221,10 @@ T txContext = getCheckedActiveTx(); return txContext.prepare(); + } + + public boolean isPartofComplexTransaction() { + return partofComplexTransaction; } } Modified: commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/DefaultTransaction.java URL: http://svn.apache.org/viewvc/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/DefaultTransaction.java?view=diff&rev=567333&r1=567332&r2=567333 ============================================================================== --- commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/DefaultTransaction.java (original) +++ commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/DefaultTransaction.java Sat Aug 18 15:20:30 2007 @@ -20,7 +20,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; -import org.apache.commons.transaction.locking.SimpleLockManager; +import org.apache.commons.transaction.locking.RWLockManager; import org.apache.commons.transaction.locking.LockManager; /** @@ -76,37 +76,34 @@ * */ public DefaultTransaction() { - this(new SimpleLockManager<Object, Object>()); + this(new RWLockManager<Object, Object>()); } public synchronized void commit() throws TransactionException { - try { - lm.endWork(); - if (isRollbackOnly()) { - throw new TransactionException(TransactionException.Code.ROLLBACK_ONLY); - } - if (!prepare()) { - throw new TransactionException(TransactionException.Code.PREPARE_FAILED); - } + if (isRollbackOnly()) { + throw new TransactionException(TransactionException.Code.ROLLBACK_ONLY); + } + if (!prepare()) { + throw new TransactionException(TransactionException.Code.PREPARE_FAILED); + } - for (ManageableResourceManager manager : rms) { - if (!manager.isReadOnly()) { - try { - if (!manager.commitTransaction()) { - throw new TransactionException(TransactionException.Code.COMMIT_FAILED); - } - } catch (Exception e) { - throw new TransactionException(e, TransactionException.Code.COMMIT_FAILED); - } catch (Error e) { - // XXX is this really a good idea? - rollback(); - throw e; + for (ManageableResourceManager manager : rms) { + if (!manager.isReadOnly()) { + try { + if (!manager.commitTransaction()) { + throw new TransactionException(TransactionException.Code.COMMIT_FAILED); } + } catch (Exception e) { + throw new TransactionException(e, TransactionException.Code.COMMIT_FAILED); + } catch (Error e) { + // XXX is this really a good idea? + rollback(); + throw e; } } - } finally { - started = false; } + lm.endWork(); + started = false; } public synchronized void enlistResourceManager(ManageableResourceManager resourceManager) { @@ -130,16 +127,13 @@ } public synchronized void rollback() { - try { - lm.endWork(); - for (ManageableResourceManager manager : rms) { - if (!manager.isReadOnly()) { - manager.rollbackTransaction(); - } + for (ManageableResourceManager manager : rms) { + if (!manager.isReadOnly()) { + manager.rollbackTransaction(); } - } finally { - started = false; } + lm.endWork(); + started = false; } public synchronized void start(long timeout, TimeUnit unit) { Modified: commons/proper/transaction/branches/TRANSACTION_2/src/test/org/apache/commons/transaction/DefaultTransactionTest.java URL: http://svn.apache.org/viewvc/commons/proper/transaction/branches/TRANSACTION_2/src/test/org/apache/commons/transaction/DefaultTransactionTest.java?view=diff&rev=567333&r1=567332&r2=567333 ============================================================================== --- commons/proper/transaction/branches/TRANSACTION_2/src/test/org/apache/commons/transaction/DefaultTransactionTest.java (original) +++ commons/proper/transaction/branches/TRANSACTION_2/src/test/org/apache/commons/transaction/DefaultTransactionTest.java Sat Aug 18 15:20:30 2007 @@ -16,6 +16,8 @@ */ package org.apache.commons.transaction; +import static junit.framework.Assert.fail; + import java.util.concurrent.TimeUnit; import junit.framework.JUnit4TestAdapter; @@ -44,10 +46,11 @@ t.commit(); } catch (Throwable throwable) { t.rollback(); + fail("Unexpected roll back: " + throwable); } } - + public static void main(String[] args) { new DefaultTransactionTest().basic(); }