geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r153879 - in geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction: InstanceContext.java context/BeanTransactionContext.java context/ContainerTransactionContext.java context/InheritableTransactionContext.java context/TransactionContext.java context/UnspecifiedTransactionContext.java
Date Tue, 15 Feb 2005 02:15:20 GMT
Author: dain
Date: Mon Feb 14 18:15:17 2005
New Revision: 153879

URL: http://svn.apache.org/viewcvs?view=rev&rev=153879
Log:
Fixed bugs with BMT transactions not correctly driving the SessionSynchronization methods.
Moved most of the code from BeanTransactionContext and ContaienrTransactionContext into InheritableTransactionContext.

Modified:
    geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/InstanceContext.java
    geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/BeanTransactionContext.java
    geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/ContainerTransactionContext.java
    geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/InheritableTransactionContext.java
    geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContext.java
    geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/UnspecifiedTransactionContext.java

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/InstanceContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/InstanceContext.java?view=diff&r1=153878&r2=153879
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/InstanceContext.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/InstanceContext.java
Mon Feb 14 18:15:17 2005
@@ -37,9 +37,9 @@
 
     void flush() throws Throwable;
 
-    void beforeCommit() throws Exception;
+    void beforeCommit() throws Throwable;
 
-    void afterCommit(boolean status) throws Exception;
+    void afterCommit(boolean status) throws Throwable;
 
     /**
      * IMPORTANT INVARIANT: this should always return a map, never null.

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/BeanTransactionContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/BeanTransactionContext.java?view=diff&r1=153878&r2=153879
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/BeanTransactionContext.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/BeanTransactionContext.java
Mon Feb 14 18:15:17 2005
@@ -17,30 +17,16 @@
 
 package org.apache.geronimo.transaction.context;
 
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.InvalidTransactionException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-
 import org.apache.geronimo.transaction.ExtendedTransactionManager;
 
 /**
- *
- *
  * @version $Rev$ $Date$
  */
 public class BeanTransactionContext extends InheritableTransactionContext {
-    private final ExtendedTransactionManager txnManager;
-    private final UnspecifiedTransactionContext oldContext;
-    private Transaction transaction;
-
+    private UnspecifiedTransactionContext oldContext;
 
     public BeanTransactionContext(ExtendedTransactionManager txnManager, UnspecifiedTransactionContext
oldContext) {
-        this.txnManager = txnManager;
+        super(txnManager);
         this.oldContext = oldContext;
     }
 
@@ -48,58 +34,7 @@
         return oldContext;
     }
 
-    public void begin(long transactionTimeoutMilliseconds) throws SystemException, NotSupportedException
{
-        transaction = txnManager.begin(transactionTimeoutMilliseconds);
-    }
-
-    public void suspend() throws SystemException {
-        Transaction suspendedTransaction = txnManager.suspend();
-        assert (transaction == suspendedTransaction) : "suspend did not return our transaction";
-    }
-
-    public void resume() throws SystemException, InvalidTransactionException {
-        txnManager.resume(transaction);
-    }
-
-    public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException,
SystemException {
-        try {
-            try {
-                flushState();
-            } catch (Throwable t) {
-                try {
-                    txnManager.rollback();
-                } catch (Throwable t1) {
-                    log.error("Unable to roll back transaction", t1);
-                }
-                throw (RollbackException) new RollbackException("Could not flush state before
commit").initCause(t);
-            }
-            txnManager.commit();
-        } finally {
-            connectorAfterCommit();
-            transaction = null;
-        }
-    }
-
-    public void rollback() throws SystemException {
-        try {
-            txnManager.rollback();
-        } finally {
-            connectorAfterCommit();
-            transaction = null;
-        }
-    }
-
-    //Geronimo connector framework support
-
-    public boolean isActive() {
-        try {
-            return txnManager.getStatus() == Status.STATUS_ACTIVE;
-        } catch (SystemException e) {
-            return false;
-        }
-    }
-
-    public Transaction getTransaction() {
-        return transaction;
+    public void setOldContext(UnspecifiedTransactionContext oldContext) {
+        this.oldContext = oldContext;
     }
 }

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/ContainerTransactionContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/ContainerTransactionContext.java?view=diff&r1=153878&r2=153879
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/ContainerTransactionContext.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/ContainerTransactionContext.java
Mon Feb 14 18:15:17 2005
@@ -17,199 +17,22 @@
 
 package org.apache.geronimo.transaction.context;
 
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.InvalidTransactionException;
 import javax.transaction.NotSupportedException;
-import javax.transaction.Status;
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.RollbackException;
+
+import org.apache.geronimo.transaction.ExtendedTransactionManager;
 
 /**
  * @version $Rev$ $Date$
  */
 public class ContainerTransactionContext extends InheritableTransactionContext {
-    private final TransactionManager txnManager;
-    private Transaction transaction;
-
-    private boolean threadAssociated = false;
-
-    public ContainerTransactionContext(TransactionManager txnManager) throws SystemException,
NotSupportedException {
-        this.txnManager = txnManager;
-        txnManager.begin();
-        transaction = txnManager.getTransaction();
-        threadAssociated = true;
-    }
-
-    public ContainerTransactionContext(TransactionManager txnManager, Transaction transaction)
{
-        this.txnManager = txnManager;
-        this.transaction = transaction;
-    }
-
-    public void suspend() throws SystemException {
-        Transaction suspendedTransaction = txnManager.suspend();
-        assert (transaction == suspendedTransaction) : "suspend did not return our transaction.
ours: " + transaction + ", suspended returned: " + suspendedTransaction;
-        threadAssociated = false;
-    }
-
-    public void resume() throws SystemException, InvalidTransactionException {
-        txnManager.resume(transaction);
-        threadAssociated = true;
-    }
-
-    public void commit() throws HeuristicMixedException, HeuristicRollbackException, SystemException,
RollbackException {
-        boolean wasCommitted = false;
-        try {
-            if (checkRolledback()) {
-                return;
-            }
-
-            flushState();
-
-            if (checkRolledback()) {
-                return;
-            }
-
-            // todo we need to flush anyone enrolled during before and then call before on
any flushed...
-            beforeCommit();
-
-            if (checkRolledback()) {
-                return;
-            }
-
-            txnManager.commit();
-            wasCommitted = true;
-        } catch (Throwable t) {
-            rollbackAndThrow("Unable to commit container transaction", t);
-        } finally {
-            try {
-                afterCommit(wasCommitted);
-            } catch (Exception e) {
-                rollbackAndThrow("After commit of container transaction failed", e);
-            } finally {
-                connectorAfterCommit();
-                transaction = null;
-            }
-        }
-    }
-
-    private boolean checkRolledback() throws SystemException {
-        int status;
-        try {
-            status = transaction.getStatus();
-        } catch (SystemException e) {
-            txnManager.rollback();
-            throw e;
-        }
-
-        if (status == Status.STATUS_MARKED_ROLLBACK) {
-            // we need to rollback
-            txnManager.rollback();
-            return true;
-        } else if (status == Status.STATUS_ROLLEDBACK ||
-                status == Status.STATUS_ROLLING_BACK) {
-            // already rolled back
-            return true;
-        }
-        return false;
-    }
-
-    private void rollbackAndThrow(String message, Throwable throwable) throws HeuristicMixedException,
HeuristicRollbackException, SystemException, RollbackException {
-        try {
-            // just incase there is a junk transaction on the thread
-            if (txnManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
-                txnManager.rollback();
-            }
-        } catch (Throwable t) {
-            log.error("Unable to roll back transaction", t);
-        }
-
-        if (throwable instanceof HeuristicMixedException) {
-            throw (HeuristicMixedException) throwable;
-        } else if (throwable instanceof HeuristicRollbackException) {
-            throw (HeuristicRollbackException) throwable;
-        } else if (throwable instanceof RollbackException) {
-            throw (RollbackException) throwable;
-        } else if (throwable instanceof SystemException) {
-            throw (SystemException) throwable;
-        } else if (throwable instanceof Error) {
-            throw (Error) throwable;
-        } else if (throwable instanceof RuntimeException) {
-            throw (RuntimeException) throwable;
-        } else {
-            throw (SystemException) new SystemException(message).initCause(throwable);
-        }
+    public ContainerTransactionContext(ExtendedTransactionManager txnManager) throws SystemException,
NotSupportedException {
+        super(txnManager);
+        begin(0);
     }
 
-    public void rollback() throws SystemException {
-        try {
-            try {
-                if (txnManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
-                    txnManager.rollback();
-                }
-            } finally {
-                try {
-                    afterCommit(false);
-                } catch (Throwable e) {
-                    try {
-                        // just incase there is a junk transaction on the thread
-                        if (txnManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
-                            txnManager.rollback();
-                        }
-                    } catch (Throwable t1) {
-                        log.error("Unable to roll back transaction", t1);
-                    }
-
-                    if (e instanceof SystemException) {
-                        throw (SystemException) e;
-                    } else if (e instanceof Error) {
-                        throw (Error) e;
-                    } else if (e instanceof RuntimeException) {
-                        throw (RuntimeException) e;
-                    }
-                    throw (SystemException) new SystemException("After commit of container
transaction failed").initCause(e);
-                }
-            }
-        } finally {
-            connectorAfterCommit();
-            transaction = null;
-        }
-    }
-
-    public boolean isThreadAssociated() {
-        return threadAssociated;
-    }
-
-    //Geronimo connector framework support
-    public boolean isActive() {
-        try {
-            return txnManager.getStatus() == Status.STATUS_ACTIVE;
-        } catch (SystemException e) {
-            return false;
-        }
-    }
-
-    public Transaction getTransaction() {
-        return transaction;
-    }
-
-    public void setRollbackOnly() throws IllegalStateException, SystemException {
-        if (transaction == null) {
-            throw new IllegalStateException("There is no transaction in progress.");
-        }
-        transaction.setRollbackOnly();
-    }
-
-    public boolean getRollbackOnly() throws SystemException {
-        if (transaction == null) {
-            throw new IllegalStateException("There is no transaction in progress.");
-        }
-
-        int status = transaction.getStatus();
-        return (status == Status.STATUS_MARKED_ROLLBACK ||
-                status == Status.STATUS_ROLLEDBACK ||
-                status == Status.STATUS_ROLLING_BACK);
+    public ContainerTransactionContext(ExtendedTransactionManager txnManager, Transaction
transaction) {
+        super(txnManager, transaction);
     }
 }

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/InheritableTransactionContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/InheritableTransactionContext.java?view=diff&r1=153878&r2=153879
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/InheritableTransactionContext.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/InheritableTransactionContext.java
Mon Feb 14 18:15:17 2005
@@ -17,7 +17,16 @@
 
 package org.apache.geronimo.transaction.context;
 
-import org.apache.geronimo.transaction.context.TransactionContext;
+import javax.transaction.SystemException;
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+
+import org.apache.geronimo.transaction.ExtendedTransactionManager;
 
 /**
  *
@@ -25,4 +34,180 @@
  * @version $Rev$ $Date$
  */
 public abstract class InheritableTransactionContext extends TransactionContext {
+    private final ExtendedTransactionManager txnManager;
+    private Transaction transaction;
+    private boolean threadAssociated = false;
+
+    protected InheritableTransactionContext(ExtendedTransactionManager txnManager) {
+        this.txnManager = txnManager;
+    }
+
+    protected InheritableTransactionContext(ExtendedTransactionManager txnManager, Transaction
transaction) {
+        this.txnManager = txnManager;
+        this.transaction = transaction;
+    }
+
+    public boolean isThreadAssociated() {
+        return threadAssociated;
+    }
+
+    public Transaction getTransaction() {
+        return transaction;
+    }
+
+    public boolean isActive() {
+        try {
+            return txnManager.getStatus() == Status.STATUS_ACTIVE;
+        } catch (SystemException e) {
+            return false;
+        }
+    }
+
+    public boolean getRollbackOnly() throws SystemException {
+        Transaction transaction = getTransaction();
+        if (transaction == null) {
+            throw new IllegalStateException("There is no transaction in progress.");
+        }
+
+        int status = transaction.getStatus();
+        return (status == Status.STATUS_MARKED_ROLLBACK ||
+                status == Status.STATUS_ROLLEDBACK ||
+                status == Status.STATUS_ROLLING_BACK);
+    }
+
+    public void setRollbackOnly() throws IllegalStateException, SystemException {
+        Transaction transaction = getTransaction();
+        if (transaction == null) {
+            throw new IllegalStateException("There is no transaction in progress.");
+        }
+        transaction.setRollbackOnly();
+    }
+
+    public void begin(long transactionTimeoutMilliseconds) throws SystemException, NotSupportedException
{
+        transaction = txnManager.begin(transactionTimeoutMilliseconds);
+        threadAssociated = true;
+    }
+
+    public void suspend() throws SystemException {
+        Transaction suspendedTransaction = txnManager.suspend();
+        assert (transaction == suspendedTransaction) : "suspend did not return our transaction.
ours: " + transaction + ", suspended returned: " + suspendedTransaction;
+        threadAssociated = false;
+    }
+
+    public void resume() throws SystemException, InvalidTransactionException {
+        txnManager.resume(transaction);
+        threadAssociated = true;
+    }
+
+    public void commit() throws HeuristicMixedException, HeuristicRollbackException, SystemException,
RollbackException {
+        boolean wasCommitted = false;
+        try {
+            checkRolledback();
+
+            flushState();
+
+            checkRolledback();
+
+            // todo we need to flush anyone enrolled during before and then call before on
any flushed...
+            beforeCommit();
+
+            checkRolledback();
+
+            txnManager.commit();
+            wasCommitted = true;
+        } catch (Throwable t) {
+            rollbackAndThrow("Unable to commit container transaction", t);
+        } finally {
+            try {
+                afterCommit(wasCommitted);
+            } catch (Throwable e) {
+                rollbackAndThrow("After commit of container transaction failed", e);
+            } finally {
+                connectorAfterCommit();
+                transaction = null;
+            }
+        }
+    }
+
+    private void checkRolledback() throws SystemException, RollbackException {
+        int status;
+        try {
+            status = transaction.getStatus();
+        } catch (SystemException e) {
+            txnManager.rollback();
+            throw e;
+        }
+
+        if (status == Status.STATUS_MARKED_ROLLBACK) {
+            // we need to rollback
+            txnManager.rollback();
+            throw new RollbackException();
+        } else if (status == Status.STATUS_ROLLEDBACK ||
+                status == Status.STATUS_ROLLING_BACK) {
+            // already rolled back
+            throw new RollbackException();
+        }
+    }
+
+    private void rollbackAndThrow(String message, Throwable throwable) throws HeuristicMixedException,
HeuristicRollbackException, SystemException, RollbackException {
+        try {
+            // just incase there is a junk transaction on the thread
+            if (txnManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
+                txnManager.rollback();
+            }
+        } catch (Throwable t) {
+            log.error("Unable to roll back transaction", t);
+        }
+
+        if (throwable instanceof HeuristicMixedException) {
+            throw (HeuristicMixedException) throwable;
+        } else if (throwable instanceof HeuristicRollbackException) {
+            throw (HeuristicRollbackException) throwable;
+        } else if (throwable instanceof RollbackException) {
+            throw (RollbackException) throwable;
+        } else if (throwable instanceof SystemException) {
+            throw (SystemException) throwable;
+        } else if (throwable instanceof Error) {
+            throw (Error) throwable;
+        } else if (throwable instanceof RuntimeException) {
+            throw (RuntimeException) throwable;
+        } else {
+            throw (SystemException) new SystemException(message).initCause(throwable);
+        }
+    }
+
+    public void rollback() throws SystemException {
+        try {
+            try {
+                if (txnManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
+                    txnManager.rollback();
+                }
+            } finally {
+                try {
+                    afterCommit(false);
+                } catch (Throwable e) {
+                    try {
+                        // just incase there is a junk transaction on the thread
+                        if (txnManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
+                            txnManager.rollback();
+                        }
+                    } catch (Throwable t1) {
+                        log.error("Unable to roll back transaction", t1);
+                    }
+
+                    if (e instanceof SystemException) {
+                        throw (SystemException) e;
+                    } else if (e instanceof Error) {
+                        throw (Error) e;
+                    } else if (e instanceof RuntimeException) {
+                        throw (RuntimeException) e;
+                    }
+                    throw (SystemException) new SystemException("After commit of container
transaction failed").initCause(e);
+                }
+            }
+        } finally {
+            connectorAfterCommit();
+            transaction = null;
+        }
+    }
 }

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContext.java?view=diff&r1=153878&r2=153879
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContext.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContext.java
Mon Feb 14 18:15:17 2005
@@ -110,7 +110,7 @@
         }
     }
 
-    protected void beforeCommit() throws Exception {
+    protected void beforeCommit() throws Throwable {
         // @todo allow for enrollment during pre-commit
         ArrayList toFlush = new ArrayList(associatedContexts.values());
         for (Iterator i = toFlush.iterator(); i.hasNext();) {
@@ -119,7 +119,7 @@
         }
     }
 
-    protected void afterCommit(boolean status) throws Exception {
+    protected void afterCommit(boolean status) throws Throwable {
         Throwable firstThrowable = null;
         ArrayList toFlush = new ArrayList(associatedContexts.values());
         for (Iterator i = toFlush.iterator(); i.hasNext();) {

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/UnspecifiedTransactionContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/UnspecifiedTransactionContext.java?view=diff&r1=153878&r2=153879
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/UnspecifiedTransactionContext.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/UnspecifiedTransactionContext.java
Mon Feb 14 18:15:17 2005
@@ -18,14 +18,12 @@
 package org.apache.geronimo.transaction.context;
 
 import javax.transaction.Transaction;
+import javax.transaction.SystemException;
 
 import org.apache.geronimo.transaction.ConnectionReleaser;
-import org.apache.geronimo.transaction.context.TransactionContext;
 
 
 /**
- *
- *
  * @version $Rev$ $Date$
  */
 public class UnspecifiedTransactionContext extends TransactionContext {
@@ -53,7 +51,6 @@
     public void rollback() {
     }
 
-    //Geronimo connector framework support
     public void setManagedConnectionInfo(ConnectionReleaser key, Object info) {
     }
 



Mime
View raw message