[seam-commits] Seam SVN: r10662 - in modules/trunk/transaction: src/main/java/org/jboss/seam/transaction and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Apr 27 21:07:37 EDT 2009
Author: shane.bryzak at jboss.com
Date: 2009-04-27 21:07:37 -0400 (Mon, 27 Apr 2009)
New Revision: 10662
Added:
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/AfterTransactionCompletionEvent.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/BeforeTransactionCompletionEvent.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/TransactionFailedEvent.java
Modified:
modules/trunk/transaction/pom.xml
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/CMTTransaction.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/EntityTransaction.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/FacesTransactionEvents.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/HibernateTransaction.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/NoTransaction.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/RollbackInterceptor.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/Transaction.java
modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/UTTransaction.java
Log:
dependencies, component converstion, introduced event classes
Modified: modules/trunk/transaction/pom.xml
===================================================================
--- modules/trunk/transaction/pom.xml 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/pom.xml 2009-04-28 01:07:37 UTC (rev 10662)
@@ -36,6 +36,10 @@
<artifactId>ejb-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>seam-el</artifactId>
</dependency>
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -6,13 +6,11 @@
import static javax.transaction.Status.STATUS_COMMITTED;
import static javax.transaction.Status.STATUS_NO_TRANSACTION;
+import javax.inject.Current;
import javax.persistence.EntityManager;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-
/**
* Base implementation of UserTransaction
*
@@ -21,6 +19,7 @@
*/
public abstract class AbstractUserTransaction implements UserTransaction
{
+ @Current Synchronizations synchronizations;
public boolean isActive() throws SystemException
{
@@ -73,10 +72,5 @@
entityManager.joinTransaction();
}
}
-
- public static Synchronizations getSynchronizations()
- {
- return (Synchronizations) Component.getInstance("org.jboss.seam.transaction.synchronizations", ScopeType.EVENT);
- }
}
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/CMTTransaction.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/CMTTransaction.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/CMTTransaction.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -1,6 +1,7 @@
package org.jboss.seam.transaction;
import javax.ejb.EJBContext;
+import javax.inject.Current;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
@@ -22,10 +23,9 @@
*
*/
public class CMTTransaction extends AbstractUserTransaction
-{
-
+{
private final EJBContext ejbContext;
-
+
public CMTTransaction(EJBContext ejbContext)
{
this.ejbContext = ejbContext;
@@ -38,7 +38,7 @@
public void begin() throws NotSupportedException, SystemException
{
ejbContext.getUserTransaction().begin();
- getSynchronizations().afterTransactionBegin();
+ synchronizations.afterTransactionBegin();
}
public void commit() throws RollbackException, HeuristicMixedException,
@@ -46,7 +46,6 @@
{
UserTransaction userTransaction = ejbContext.getUserTransaction();
boolean success = false;
- Synchronizations synchronizations = getSynchronizations();
synchronizations.beforeTransactionCommit();
try
{
@@ -68,7 +67,7 @@
}
finally
{
- getSynchronizations().afterTransactionRollback();
+ synchronizations.afterTransactionRollback();
}
}
@@ -112,7 +111,6 @@
@Override
public void registerSynchronization(Synchronization sync)
{
- Synchronizations synchronizations = getSynchronizations();
if ( synchronizations.isAwareOfContainerTransactions() )
{
synchronizations.registerSynchronization(sync);
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/EntityTransaction.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/EntityTransaction.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/EntityTransaction.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -37,7 +37,8 @@
private ValueExpression<EntityManager> entityManager;
private EntityManager currentEntityManager;
- @Current Expressions expressions;
+ @Current Expressions expressions;
+ @Current PersistenceProvider persistenceProvider;
@Initializer
public void validate()
@@ -76,7 +77,7 @@
try
{
getDelegate().begin();
- getSynchronizations().afterTransactionBegin();
+ synchronizations.afterTransactionBegin();
}
catch (RuntimeException re)
{
@@ -102,14 +103,14 @@
}
else
{
- getSynchronizations().beforeTransactionCommit();
+ synchronizations.beforeTransactionCommit();
delegate.commit();
success = true;
}
}
finally
{
- getSynchronizations().afterTransactionCommit(success);
+ synchronizations.afterTransactionCommit(success);
}
}
@@ -126,7 +127,7 @@
}
finally
{
- getSynchronizations().afterTransactionRollback();
+ synchronizations.afterTransactionRollback();
}
}
@@ -191,13 +192,14 @@
{
log.debug("registering synchronization: " + sync);
}
+
assertActive();
//try to register the synchronization directly with the
//persistence provider, but if this fails, just hold
//on to it myself
- if ( !PersistenceProvider.instance().registerSynchronization(sync, currentEntityManager) )
+ if ( !persistenceProvider.registerSynchronization(sync, currentEntityManager) )
{
- getSynchronizations().registerSynchronization(sync);
+ synchronizations.registerSynchronization(sync);
}
}
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/FacesTransactionEvents.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/FacesTransactionEvents.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/FacesTransactionEvents.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -1,16 +1,11 @@
package org.jboss.seam.transaction;
-import static org.jboss.seam.ScopeType.APPLICATION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
+import javax.context.ApplicationScoped;
+import javax.event.Observes;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Startup;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.international.StatusMessage.Severity;
+import org.jboss.seam.transaction.events.TransactionFailedEvent;
/**
* Produces StatusMessages for JSF in response of certain transaction events.
@@ -19,17 +14,12 @@
*
* @author Dan Allen
*/
- at Name("org.jboss.seam.transaction.facesTransactionEvents")
- at Scope(APPLICATION)
- at Install(precedence = BUILT_IN, classDependencies = "javax.faces.context.FacesContext")
- at BypassInterceptors
- at Startup
+ at ApplicationScoped
public class FacesTransactionEvents
{
- private boolean transactionFailedMessageEnabled = true;
+ private boolean transactionFailedMessageEnabled = true;
- @Observer(Transaction.TRANSACTION_FAILED)
- public void addTransactionFailedMessage(int status)
+ public void addTransactionFailedMessage(@Observes TransactionFailedEvent event)
{
if (transactionFailedMessageEnabled) {
StatusMessages.instance().addFromResourceBundleOrDefault(
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/HibernateTransaction.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/HibernateTransaction.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/HibernateTransaction.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -1,7 +1,7 @@
package org.jboss.seam.transaction;
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-
+import javax.context.RequestScoped;
+import javax.inject.Initializer;
import javax.persistence.EntityManager;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
@@ -13,16 +13,10 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
-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;
import org.jboss.seam.core.Expressions;
import org.jboss.seam.core.Expressions.ValueExpression;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
/**
* Support for the Hibernate Transaction API.
@@ -33,10 +27,7 @@
* @author Gavin King
*
*/
- at Name("org.jboss.seam.transaction.transaction")
- at Scope(ScopeType.EVENT)
- at Install(value=false, precedence=FRAMEWORK)
- at BypassInterceptors
+ at RequestScoped
public class HibernateTransaction extends AbstractUserTransaction
{
private static final LogProvider log = Logging.getLogProvider(HibernateTransaction.class);
@@ -45,7 +36,7 @@
private Session currentSession;
private boolean rollbackOnly; //Hibernate Transaction doesn't have a "rollback only" state
- @Create
+ @Initializer
public void validate()
{
if (session==null)
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/NoTransaction.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/NoTransaction.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/NoTransaction.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -1,7 +1,6 @@
package org.jboss.seam.transaction;
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-
+import javax.context.RequestScoped;
import javax.persistence.EntityManager;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
@@ -11,12 +10,6 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-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;
-
/**
* When no kind of transaction management exists.
*
@@ -24,13 +17,9 @@
* @author Gavin King
*
*/
- at Name("org.jboss.seam.transaction.transaction")
- at Scope(ScopeType.EVENT)
- at Install(value = false, precedence = FRAMEWORK)
- at BypassInterceptors
+ at RequestScoped
public class NoTransaction extends AbstractUserTransaction
{
-
public void begin() throws NotSupportedException, SystemException
{
throw new UnsupportedOperationException("no transaction");
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/RollbackInterceptor.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/RollbackInterceptor.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/RollbackInterceptor.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -2,7 +2,6 @@
package org.jboss.seam.transaction;
import static org.jboss.seam.ComponentType.JAVA_BEAN;
-import static org.jboss.seam.util.Work.isRollbackRequired;
import org.jboss.seam.annotations.intercept.AroundInvoke;
import org.jboss.seam.annotations.intercept.Interceptor;
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -1,17 +1,10 @@
package org.jboss.seam.transaction;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
import java.util.Stack;
+import javax.context.RequestScoped;
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
@@ -22,10 +15,7 @@
* @author Gavin King
*
*/
- at Name("org.jboss.seam.transaction.synchronizations")
- at Scope(ScopeType.EVENT)
- at Install(precedence=BUILT_IN)
- at BypassInterceptors
+ at RequestScoped
public class SeSynchronizations implements Synchronizations
{
protected Stack<SynchronizationRegistry> synchronizations = new Stack<SynchronizationRegistry>();
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -3,12 +3,15 @@
import java.util.ArrayList;
import java.util.List;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
import javax.transaction.Status;
import javax.transaction.Synchronization;
-import org.jboss.seam.core.Events;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import org.jboss.seam.transaction.events.AfterTransactionCompletionEvent;
+import org.jboss.seam.transaction.events.BeforeTransactionCompletionEvent;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
/**
* A list of Synchronizations to be invoked before and after transaction
@@ -21,6 +24,8 @@
class SynchronizationRegistry
{
private static final LogProvider log = Logging.getLogProvider(SynchronizationRegistry.class);
+
+ @Current Manager manager;
private List<Synchronization> synchronizations = new ArrayList<Synchronization>();
@@ -31,10 +36,8 @@
void afterTransactionCompletion(boolean success)
{
- if ( Events.exists() )
- {
- Events.instance().raiseEvent("org.jboss.seam.afterTransactionCompletion", success);
- }
+ manager.fireEvent(new AfterTransactionCompletionEvent(success));
+
for (Synchronization sync: synchronizations)
{
try
@@ -50,11 +53,8 @@
}
void beforeTransactionCompletion()
- {
- if ( Events.exists() )
- {
- Events.instance().raiseEvent("org.jboss.seam.beforeTransactionCompletion");
- }
+ {
+ manager.fireEvent(new BeforeTransactionCompletionEvent());
for (Synchronization sync: synchronizations)
{
try
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/Transaction.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/Transaction.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/Transaction.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -1,18 +1,11 @@
package org.jboss.seam.transaction;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
+import javax.context.RequestScoped;
+import javax.inject.Produces;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
-import org.jboss.seam.Component;
-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.Unwrap;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.util.EJB;
import org.jboss.seam.util.Naming;
@@ -25,21 +18,9 @@
* @author Gavin King
*
*/
- at Name("org.jboss.seam.transaction.transaction")
- at Scope(ScopeType.EVENT)
- at Install(precedence=BUILT_IN)
- at BypassInterceptors
public class Transaction
-{
- // Event keys
- public static final String TRANSACTION_FAILED = "org.jboss.seam.transaction.transactionFailed";
-
- public static UserTransaction instance()
- {
- return (UserTransaction) Component.getInstance(Transaction.class, ScopeType.EVENT);
- }
-
- @Unwrap
+{
+ @Produces @RequestScoped
public UserTransaction getTransaction() throws NamingException
{
try
Modified: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/UTTransaction.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/UTTransaction.java 2009-04-27 20:14:56 UTC (rev 10661)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/UTTransaction.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -7,8 +7,8 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
/**
* Wraps JTA transaction management in a Seam UserTransaction
@@ -37,7 +37,7 @@
{
log.debug("beginning JTA transaction");
delegate.begin();
- getSynchronizations().afterTransactionBegin();
+ synchronizations.afterTransactionBegin();
}
public void commit() throws RollbackException, HeuristicMixedException,
@@ -45,7 +45,6 @@
{
log.debug("committing JTA transaction");
boolean success = false;
- Synchronizations synchronizations = getSynchronizations();
synchronizations.beforeTransactionCommit();
try
{
@@ -67,7 +66,7 @@
}
finally
{
- getSynchronizations().afterTransactionRollback();
+ synchronizations.afterTransactionRollback();
}
}
@@ -89,7 +88,6 @@
@Override
public void registerSynchronization(Synchronization sync)
{
- getSynchronizations().registerSynchronization(sync);
+ synchronizations.registerSynchronization(sync);
}
-
}
Added: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/AfterTransactionCompletionEvent.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/AfterTransactionCompletionEvent.java (rev 0)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/AfterTransactionCompletionEvent.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -0,0 +1,22 @@
+package org.jboss.seam.transaction.events;
+
+/**
+ * This event is raised just after transaction completion
+ *
+ * @author Shane Bryzak
+ *
+ */
+public class AfterTransactionCompletionEvent
+{
+ private boolean successful;
+
+ public AfterTransactionCompletionEvent(boolean successful)
+ {
+ this.successful = successful;
+ }
+
+ public boolean isSuccessful()
+ {
+ return successful;
+ }
+}
Added: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/BeforeTransactionCompletionEvent.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/BeforeTransactionCompletionEvent.java (rev 0)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/BeforeTransactionCompletionEvent.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -0,0 +1,11 @@
+package org.jboss.seam.transaction.events;
+
+/**
+ * This event is raised just before transaction completion
+ *
+ * @author Shane Bryzak
+ */
+public class BeforeTransactionCompletionEvent
+{
+
+}
Added: modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/TransactionFailedEvent.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/TransactionFailedEvent.java (rev 0)
+++ modules/trunk/transaction/src/main/java/org/jboss/seam/transaction/events/TransactionFailedEvent.java 2009-04-28 01:07:37 UTC (rev 10662)
@@ -0,0 +1,21 @@
+package org.jboss.seam.transaction.events;
+
+/**
+ * This event is raised when a transaction fails
+ *
+ * @author Shane Bryzak
+ */
+public class TransactionFailedEvent
+{
+ private int status;
+
+ public TransactionFailedEvent(int status)
+ {
+ this.status = status;
+ }
+
+ public int getStatus()
+ {
+ return status;
+ }
+}
More information about the seam-commits
mailing list