[jboss-cvs] jboss-seam/src/main/org/jboss/seam/transaction ...
Gavin King
gavin.king at jboss.com
Thu Jul 19 06:45:44 EDT 2007
User: gavin
Date: 07/07/19 06:45:44
Modified: src/main/org/jboss/seam/transaction
AbstractUserTransaction.java CMTTransaction.java
EjbTransaction.java EntityTransaction.java
Transaction.java UTTransaction.java
Added: src/main/org/jboss/seam/transaction
EjbSynchronizations.java
LocalEjbSychronizations.java
SeSynchronizations.java Synchronizations.java
Log:
fix JBSEAM-1688
Revision Changes Path
1.3 +8 -0 jboss-seam/src/main/org/jboss/seam/transaction/AbstractUserTransaction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbstractUserTransaction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/transaction/AbstractUserTransaction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- AbstractUserTransaction.java 6 Jul 2007 19:42:56 -0000 1.2
+++ AbstractUserTransaction.java 19 Jul 2007 10:45:44 -0000 1.3
@@ -10,6 +10,9 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+
/**
* Base implementation of UserTransaction
*
@@ -71,4 +74,9 @@
}
}
+ public static Synchronizations getSynchronizations()
+ {
+ return (Synchronizations) Component.getInstance("org.jboss.seam.transaction.synchronizations", ScopeType.EVENT);
+ }
+
}
1.5 +9 -9 jboss-seam/src/main/org/jboss/seam/transaction/CMTTransaction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CMTTransaction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/transaction/CMTTransaction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- CMTTransaction.java 17 Jul 2007 22:34:42 -0000 1.4
+++ CMTTransaction.java 19 Jul 2007 10:45:44 -0000 1.5
@@ -25,11 +25,9 @@
{
private final EJBContext ejbContext;
- private final Transaction parent;
- public CMTTransaction(EJBContext ejbContext, Transaction parent)
+ public CMTTransaction(EJBContext ejbContext)
{
- this.parent = parent;
this.ejbContext = ejbContext;
if (ejbContext==null)
{
@@ -40,7 +38,7 @@
public void begin() throws NotSupportedException, SystemException
{
ejbContext.getUserTransaction().begin();
- parent.afterBegin();
+ getSynchronizations().afterBegin();
}
public void commit() throws RollbackException, HeuristicMixedException,
@@ -48,7 +46,8 @@
{
UserTransaction userTransaction = ejbContext.getUserTransaction();
boolean success = false;
- parent.beforeCommit();
+ Synchronizations synchronizations = getSynchronizations();
+ synchronizations.beforeCommit();
try
{
userTransaction.commit();
@@ -56,7 +55,7 @@
}
finally
{
- parent.afterCommit(success);
+ synchronizations.afterCommit(success);
}
}
@@ -69,7 +68,7 @@
}
finally
{
- parent.afterRollback();
+ getSynchronizations().afterRollback();
}
}
@@ -113,9 +112,10 @@
@Override
public void registerSynchronization(Synchronization sync)
{
- if ( parent.isAwareOfContainerTransactions() )
+ Synchronizations synchronizations = getSynchronizations();
+ if ( synchronizations.isAwareOfContainerTransactions() )
{
- parent.registerSynchronization(sync);
+ synchronizations.registerSynchronization(sync);
}
else
{
1.4 +11 -65 jboss-seam/src/main/org/jboss/seam/transaction/EjbTransaction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EjbTransaction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/transaction/EjbTransaction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- EjbTransaction.java 26 Jun 2007 03:26:37 -0000 1.3
+++ EjbTransaction.java 19 Jul 2007 10:45:44 -0000 1.4
@@ -1,15 +1,6 @@
package org.jboss.seam.transaction;
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-
-import java.rmi.RemoteException;
-
-import javax.ejb.EJBException;
-import javax.ejb.Remove;
-import javax.ejb.SessionSynchronization;
-import javax.ejb.Stateful;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
@@ -18,61 +9,16 @@
import org.jboss.seam.annotations.intercept.BypassInterceptors;
/**
- * Receives JTA transaction completion notifications from
- * the EJB container, and passes them on to the registered
- * Synchronizations. Unlike its superclass, this implementation
- * is fully aware of container managed transactions and is
- * able to register Synchronizations for the container
- * transaction.
+ * Dummy component that lets us install the
+ * EjbSynchronizations via the tag
+ * transaction:ejb-transaction
*
+ * @see EjbSynchronizations
* @author Gavin King
*
*/
- at Stateful
- at Name("org.jboss.seam.transaction.transaction")
- at Scope(ScopeType.EVENT)
- at Install(precedence=FRAMEWORK, value=false)
+ at Name("org.jboss.seam.transaction.ejbTransaction")
+ at Scope(ScopeType.STATELESS)
+ at Install(precedence=BUILT_IN, value=false)
@BypassInterceptors
- at TransactionAttribute(TransactionAttributeType.SUPPORTS)
-public class EjbTransaction extends Transaction
- implements LocalEjbTransaction, SessionSynchronization
-{
-
- public void beforeCompletion() throws EJBException, RemoteException
- {
- synchronizations.peek().beforeTransactionCompletion();
- }
-
- public void afterCompletion(boolean success) throws EJBException, RemoteException
- {
- synchronizations.pop().afterTransactionCompletion(success);
- }
-
- @Override
- protected boolean isAwareOfContainerTransactions()
- {
- return true;
- }
-
- @Override
- protected void afterCommit(boolean success)
- {
- //noop, let JTA notify us
- }
-
- @Override
- protected void afterRollback()
- {
- //noop, let JTA notify us
- }
-
- @Override
- protected void beforeCommit()
- {
- //noop, let JTA notify us
- }
-
- @Remove
- public void destroy() {}
-
-}
+public class EjbTransaction {}
1.8 +5 -5 jboss-seam/src/main/org/jboss/seam/transaction/EntityTransaction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EntityTransaction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/transaction/EntityTransaction.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- EntityTransaction.java 6 Jul 2007 19:42:56 -0000 1.7
+++ EntityTransaction.java 19 Jul 2007 10:45:44 -0000 1.8
@@ -39,7 +39,6 @@
{
private static final LogProvider log = Logging.getLogProvider(EntityTransaction.class);
- private SynchronizationRegistry synchronizations = new SynchronizationRegistry();
private ValueExpression<EntityManager> entityManager;
private EntityManager currentEntityManager;
@@ -80,6 +79,7 @@
try
{
getDelegate().begin();
+ getSynchronizations().afterBegin();
}
catch (RuntimeException re)
{
@@ -105,14 +105,14 @@
}
else
{
- synchronizations.beforeTransactionCompletion();
+ getSynchronizations().beforeCommit();
delegate.commit();
success = true;
}
}
finally
{
- synchronizations.afterTransactionCompletion(success);
+ getSynchronizations().afterCommit(success);
}
}
@@ -129,7 +129,7 @@
}
finally
{
- synchronizations.afterTransactionCompletion(false);
+ getSynchronizations().afterRollback();
}
}
@@ -200,7 +200,7 @@
//on to it myself
if ( !PersistenceProvider.instance().registerSynchronization(sync, currentEntityManager) )
{
- synchronizations.registerSynchronization(sync);
+ getSynchronizations().registerSynchronization(sync);
}
}
1.15 +2 -49 jboss-seam/src/main/org/jboss/seam/transaction/Transaction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Transaction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/transaction/Transaction.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- Transaction.java 18 Jul 2007 09:53:19 -0000 1.14
+++ Transaction.java 19 Jul 2007 10:45:44 -0000 1.15
@@ -2,11 +2,8 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
-import java.util.Stack;
-
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
-import javax.transaction.Synchronization;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
@@ -21,10 +18,6 @@
/**
* Supports injection of a Seam UserTransaction object that
* wraps the current JTA transaction or EJB container managed
- * transaction. This base implementation does not have access
- * to the JTA TransactionManager, so it is not fully aware
- * of container managed transaction lifecycle, and is not
- * able to register Synchronizations with a container managed
* transaction.
*
* @author Mike Youngstrom
@@ -37,50 +30,10 @@
@BypassInterceptors
public class Transaction
{
-
private static final String STANDARD_USER_TRANSACTION_NAME = "java:comp/UserTransaction";
private static String userTransactionName = "UserTransaction";
- protected Stack<SynchronizationRegistry> synchronizations = new Stack<SynchronizationRegistry>();
-
- public void afterBegin()
- {
- synchronizations.push( new SynchronizationRegistry() );
- }
-
- protected void afterCommit(boolean success)
- {
- synchronizations.pop().afterTransactionCompletion(success);
- }
-
- protected void afterRollback()
- {
- synchronizations.pop().afterTransactionCompletion(false);
- }
-
- protected void beforeCommit()
- {
- synchronizations.peek().beforeTransactionCompletion();
- }
-
- protected void registerSynchronization(Synchronization sync)
- {
- if (synchronizations==null)
- {
- throw new IllegalStateException("no transaction active, or the transaction is a CMT (try installing <transaction:ejb-transaction/>)");
- }
- else
- {
- synchronizations.peek().registerSynchronization(sync);
- }
- }
-
- protected boolean isAwareOfContainerTransactions()
- {
- return false;
- }
-
public static void setUserTransactionName(String name)
{
userTransactionName = name;
@@ -123,12 +76,12 @@
protected UserTransaction createCMTTransaction() throws NamingException
{
- return new CMTTransaction( EJB.getEJBContext(), this );
+ return new CMTTransaction( EJB.getEJBContext() );
}
protected UserTransaction createUTTransaction() throws NamingException
{
- return new UTTransaction( getUserTransaction(), this );
+ return new UTTransaction( getUserTransaction() );
}
protected javax.transaction.UserTransaction getUserTransaction() throws NamingException
1.7 +9 -10 jboss-seam/src/main/org/jboss/seam/transaction/UTTransaction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UTTransaction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/transaction/UTTransaction.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- UTTransaction.java 24 Jun 2007 23:57:18 -0000 1.6
+++ UTTransaction.java 19 Jul 2007 10:45:44 -0000 1.7
@@ -19,11 +19,9 @@
{
private final javax.transaction.UserTransaction delegate;
- private final Transaction parent;
- UTTransaction(javax.transaction.UserTransaction delegate, Transaction parent)
+ UTTransaction(javax.transaction.UserTransaction delegate)
{
- this.parent = parent;
this.delegate = delegate;
if (delegate==null)
{
@@ -34,14 +32,15 @@
public void begin() throws NotSupportedException, SystemException
{
delegate.begin();
- parent.afterBegin();
+ getSynchronizations().afterBegin();
}
public void commit() throws RollbackException, HeuristicMixedException,
HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
{
boolean success = false;
- parent.beforeCommit();
+ Synchronizations synchronizations = getSynchronizations();
+ synchronizations.beforeCommit();
try
{
delegate.commit();
@@ -49,7 +48,7 @@
}
finally
{
- parent.afterCommit(success);
+ synchronizations.afterCommit(success);
}
}
@@ -61,7 +60,7 @@
}
finally
{
- parent.afterRollback();
+ getSynchronizations().afterRollback();
}
}
@@ -83,7 +82,7 @@
@Override
public void registerSynchronization(Synchronization sync)
{
- parent.registerSynchronization(sync);
+ getSynchronizations().registerSynchronization(sync);
}
}
1.1 date: 2007/07/19 10:45:44; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/transaction/EjbSynchronizations.java
Index: EjbSynchronizations.java
===================================================================
package org.jboss.seam.transaction;
import static org.jboss.seam.annotations.Install.FRAMEWORK;
import java.rmi.RemoteException;
import java.util.LinkedList;
import javax.ejb.EJBException;
import javax.ejb.Remove;
import javax.ejb.SessionSynchronization;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.transaction.Synchronization;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
/**
* Receives JTA transaction completion notifications from
* the EJB container, and passes them on to the registered
* Synchronizations. This implementation
* is fully aware of container managed transactions and is
* able to register Synchronizations for the container
* transaction.
*
* @author Gavin King
*
*/
@Stateful
@Name("org.jboss.seam.transaction.synchronizations")
@Scope(ScopeType.EVENT)
@Install(precedence=FRAMEWORK, dependencies="org.jboss.seam.transaction.ejbTransaction")
@BypassInterceptors
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class EjbSynchronizations implements LocalEjbSychronizations, SessionSynchronization
{
//maintain two lists to work around a bug in JBoss EJB3 where a new SessionSynchronization
//gets registered each time the bean is called
protected LinkedList<SynchronizationRegistry> synchronizations = new LinkedList<SynchronizationRegistry>();
protected LinkedList<SynchronizationRegistry> committing = new LinkedList<SynchronizationRegistry>();
public void afterBegin()
{
synchronizations.addLast( new SynchronizationRegistry() );
}
public void beforeCompletion() throws EJBException, RemoteException
{
SynchronizationRegistry sync = synchronizations.removeLast();
sync.beforeTransactionCompletion();
committing.addLast(sync);
}
public void afterCompletion(boolean success) throws EJBException, RemoteException
{
committing.removeFirst().afterTransactionCompletion(success);
}
public boolean isAwareOfContainerTransactions()
{
return true;
}
public void afterCommit(boolean success)
{
//noop, let JTA notify us
}
public void afterRollback()
{
//noop, let JTA notify us
}
public void beforeCommit()
{
//noop, let JTA notify us
}
public void registerSynchronization(Synchronization sync)
{
synchronizations.getLast().registerSynchronization(sync);
}
@Remove
public void destroy() {}
}
1.1 date: 2007/07/19 10:45:44; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/transaction/LocalEjbSychronizations.java
Index: LocalEjbSychronizations.java
===================================================================
package org.jboss.seam.transaction;
import javax.ejb.Local;
/**
* Local interface for EjbTransaction
*
* @author Gavin King
*
*/
@Local
public interface LocalEjbSychronizations extends Synchronizations
{
public void destroy();
}
1.1 date: 2007/07/19 10:45:44; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/transaction/SeSynchronizations.java
Index: SeSynchronizations.java
===================================================================
package org.jboss.seam.transaction;
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.util.Stack;
import javax.transaction.Synchronization;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
/**
* This implementation does not have access
* to the JTA TransactionManager, so it is not fully aware
* of container managed transaction lifecycle, and is not
* able to register Synchronizations with a container managed
* transaction.
*
* @author Gavin King
*
*/
@Name("org.jboss.seam.transaction.synchronizations")
@Scope(ScopeType.EVENT)
@Install(precedence=BUILT_IN)
@BypassInterceptors
public class SeSynchronizations implements Synchronizations
{
protected Stack<SynchronizationRegistry> synchronizations = new Stack<SynchronizationRegistry>();
public void afterBegin()
{
synchronizations.push( new SynchronizationRegistry() );
}
public void afterCommit(boolean success)
{
synchronizations.pop().afterTransactionCompletion(success);
}
public void afterRollback()
{
synchronizations.pop().afterTransactionCompletion(false);
}
public void beforeCommit()
{
synchronizations.peek().beforeTransactionCompletion();
}
public void registerSynchronization(Synchronization sync)
{
synchronizations.peek().registerSynchronization(sync);
}
public boolean isAwareOfContainerTransactions()
{
return false;
}
}
1.1 date: 2007/07/19 10:45:44; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/transaction/Synchronizations.java
Index: Synchronizations.java
===================================================================
package org.jboss.seam.transaction;
import javax.transaction.Synchronization;
/**
* Interface for registering transaction synchronizations
*
* @author Gavin King
*
*/
public interface Synchronizations
{
public void afterBegin();
public void afterCommit(boolean success);
public void afterRollback();
public void beforeCommit();
public void registerSynchronization(Synchronization sync);
public boolean isAwareOfContainerTransactions();
}
More information about the jboss-cvs-commits
mailing list