[webbeans-commits] Webbeans SVN: r1819 - in ri/trunk/impl/src/main/java/org/jboss/webbeans: mock and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Sun Mar 8 17:41:56 EDT 2009
Author: dallen6
Date: 2009-03-08 17:41:55 -0400 (Sun, 08 Mar 2009)
New Revision: 1819
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionSynchronizedRunnable.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockTransactionServices.java
Log:
Changes for the corresponding changes to the SPI with TransactionServices.
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionSynchronizedRunnable.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionSynchronizedRunnable.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionSynchronizedRunnable.java 2009-03-08 21:41:55 UTC (rev 1819)
@@ -0,0 +1,63 @@
+package org.jboss.webbeans.event;
+
+import static javax.transaction.Status.STATUS_COMMITTED;
+
+import javax.transaction.Synchronization;
+
+import org.jboss.webbeans.transaction.spi.TransactionServices;
+
+/**
+ * A JTA transaction sychronization which wraps a Runnable.
+ *
+ * @author David Allen
+ *
+ */
+public class TransactionSynchronizedRunnable implements Synchronization
+{
+ private final TransactionServices.Status desiredStatus;
+ private final Runnable task;
+ private final boolean before;
+
+ public TransactionSynchronizedRunnable(Runnable task, boolean before)
+ {
+ this(task, TransactionServices.Status.ALL, before);
+ }
+
+ public TransactionSynchronizedRunnable(Runnable task, TransactionServices.Status desiredStatus)
+ {
+ this(task, desiredStatus, false); // Status is only applicable after the transaction
+ }
+
+ private TransactionSynchronizedRunnable(Runnable task, TransactionServices.Status desiredStatus, boolean before)
+ {
+ this.task = task;
+ this.desiredStatus = desiredStatus;
+ this.before = before;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.transaction.Synchronization#afterCompletion(int)
+ */
+ public void afterCompletion(int status)
+ {
+ if ((desiredStatus == TransactionServices.Status.SUCCESS && status == STATUS_COMMITTED) || (desiredStatus == TransactionServices.Status.FAILURE && status != STATUS_COMMITTED) || (desiredStatus == TransactionServices.Status.ALL))
+ {
+ task.run();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.transaction.Synchronization#beforeCompletion()
+ */
+ public void beforeCompletion()
+ {
+ if (before)
+ {
+ task.run();
+ }
+ }
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionSynchronizedRunnable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-03-08 21:02:09 UTC (rev 1818)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-03-08 21:41:55 UTC (rev 1819)
@@ -27,6 +27,7 @@
import javax.event.BeforeTransactionCompletion;
import javax.inject.DefinitionException;
import javax.inject.manager.Bean;
+import javax.transaction.Synchronization;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -36,7 +37,7 @@
* @author David Allen
*
*/
-public class TransactionalObserverImpl<T> extends ObserverImpl<T>
+class TransactionalObserverImpl<T> extends ObserverImpl<T>
{
/**
* The known transactional phases a transactional event observer can be
@@ -44,36 +45,7 @@
*/
protected enum TransactionObservationPhase
{
- BEFORE_COMPLETION
- {
- void registerTask(TransactionServices transactionServices, Runnable task)
- {
- transactionServices.executeBeforeTransactionCompletion(task);
- }
- },
- AFTER_COMPLETION
- {
- void registerTask(TransactionServices transactionServices, Runnable task)
- {
- transactionServices.executeAfterTransactionCompletion(task);
- }
- },
- AFTER_FAILURE
- {
- void registerTask(TransactionServices transactionServices, Runnable task)
- {
- transactionServices.executeAfterTransactionCompletion(task, TransactionServices.Status.SUCCESS);
- }
- },
- AFTER_SUCCESS
- {
- void registerTask(TransactionServices transactionServices, Runnable task)
- {
- transactionServices.executeAfterTransactionCompletion(task, TransactionServices.Status.FAILURE);
- }
- };
-
- abstract void registerTask(TransactionServices transactionServices, Runnable task);
+ BEFORE_COMPLETION, AFTER_COMPLETION, AFTER_FAILURE, AFTER_SUCCESS
}
private TransactionObservationPhase transactionObservationPhase;
@@ -87,7 +59,7 @@
public static boolean isObserverMethodTransactional(AnnotatedMethod<?> observer)
{
boolean transactional = true;
- if ((observer.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty()) || (observer.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty()) || (observer.getAnnotatedParameters(AfterTransactionSuccess.class).isEmpty()) || (observer.getAnnotatedParameters(AfterTransactionFailure.class).isEmpty()))
+ if ((observer.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty()) && (observer.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty()) && (observer.getAnnotatedParameters(AfterTransactionSuccess.class).isEmpty()) && (observer.getAnnotatedParameters(AfterTransactionFailure.class).isEmpty()))
{
transactional = false;
}
@@ -175,7 +147,24 @@
{
deferredEvent = new AsynchronousTransactionalEventNotification<T>(event, this);
}
- transactionObservationPhase.registerTask(manager.getTransactionServices(), deferredEvent);
+ Synchronization synchronization = null;
+ if (transactionObservationPhase.equals(TransactionObservationPhase.BEFORE_COMPLETION))
+ {
+ synchronization = new TransactionSynchronizedRunnable(deferredEvent, true);
+ }
+ else if (transactionObservationPhase.equals(TransactionObservationPhase.AFTER_COMPLETION))
+ {
+ synchronization = new TransactionSynchronizedRunnable(deferredEvent, false);
+ }
+ else if (transactionObservationPhase.equals(TransactionObservationPhase.AFTER_SUCCESS))
+ {
+ synchronization = new TransactionSynchronizedRunnable(deferredEvent, TransactionServices.Status.SUCCESS);
+ }
+ else if (transactionObservationPhase.equals(TransactionObservationPhase.AFTER_FAILURE))
+ {
+ synchronization = new TransactionSynchronizedRunnable(deferredEvent, TransactionServices.Status.FAILURE);
+ }
+ manager.getTransactionServices().registerSynchronization(synchronization);
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockTransactionServices.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockTransactionServices.java 2009-03-08 21:02:09 UTC (rev 1818)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockTransactionServices.java 2009-03-08 21:41:55 UTC (rev 1819)
@@ -17,6 +17,8 @@
package org.jboss.webbeans.mock;
+import javax.transaction.Synchronization;
+
import org.jboss.webbeans.transaction.spi.TransactionServices;
/**
@@ -31,27 +33,6 @@
{
/* (non-Javadoc)
- * @see org.jboss.webbeans.transaction.spi.TransactionServices#executeAfterTransactionCompletion(java.lang.Runnable)
- */
- public void executeAfterTransactionCompletion(Runnable task)
- {
- }
-
- /* (non-Javadoc)
- * @see org.jboss.webbeans.transaction.spi.TransactionServices#executeAfterTransactionCompletion(java.lang.Runnable, org.jboss.webbeans.transaction.spi.TransactionServices.Status)
- */
- public void executeAfterTransactionCompletion(Runnable task, Status desiredStatus)
- {
- }
-
- /* (non-Javadoc)
- * @see org.jboss.webbeans.transaction.spi.TransactionServices#executeBeforeTransactionCompletion(java.lang.Runnable)
- */
- public void executeBeforeTransactionCompletion(Runnable task)
- {
- }
-
- /* (non-Javadoc)
* @see org.jboss.webbeans.transaction.spi.TransactionServices#isTransactionActive()
*/
public boolean isTransactionActive()
@@ -59,4 +40,11 @@
return false;
}
+ @Override
+ public void registerSynchronization(Synchronization synchronizedObserver)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
}
More information about the weld-commits
mailing list