Author: nickarls
Date: 2008-11-21 15:22:22 -0500 (Fri, 21 Nov 2008)
New Revision: 350
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java
Log:
Ported over EJBSynchronizations and related classes for transactional events. Need to
check what is needed and what is not...
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java 2008-11-21
20:22:22 UTC (rev 350)
@@ -0,0 +1,89 @@
+package org.jboss.webbeans.transaction;
+
+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 javax.webbeans.RequestScoped;
+
+@Stateful
+@RequestScoped
+(a)TransactionAttribute(TransactionAttributeType.SUPPORTS)
+public class EjbSynchronizations implements LocalEjbSynchronizations,
SessionSynchronization
+{
+ 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 synchronization = synchronizations.removeLast();
+ synchronization.beforeTransactionCompletion();
+ committing.addLast(synchronization);
+ }
+
+ public void afterCompletion(boolean success) throws EJBException, RemoteException
+ {
+ if (committing.isEmpty())
+ {
+ if (success)
+ {
+ throw new IllegalStateException("beforeCompletion was never
called");
+ }
+ else
+ {
+ synchronizations.removeLast().afterTransactionCompletion(false);
+ }
+ }
+ else
+ {
+ committing.removeFirst().afterTransactionCompletion(success);
+ }
+ }
+
+ public boolean isAwareOfContainerTransactions()
+ {
+ return true;
+ }
+
+ public void afterTransactionBegin()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void afterTransactionCommit(boolean success)
+ {
+ // noop, let JTA notify us
+ }
+
+ public void afterTransactionRollback()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void beforeTransactionCommit()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void registerSynchronization(Synchronization synchronization)
+ {
+ synchronizations.getLast().registerSynchronization(synchronization);
+ }
+
+ @Remove
+ public void destroy()
+ {
+ }
+
+}
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java 2008-11-21
20:22:22 UTC (rev 350)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.transaction;
+
+import javax.ejb.Local;
+
+@Local
+public interface LocalEjbSynchronizations extends Synchronizations
+{
+ public void destroy();
+}
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java 2008-11-21
20:22:22 UTC (rev 350)
@@ -0,0 +1,49 @@
+package org.jboss.webbeans.transaction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+class SynchronizationRegistry
+{
+ private List<Synchronization> synchronizations = new
ArrayList<Synchronization>();
+
+ void registerSynchronization(Synchronization sync)
+ {
+ synchronizations.add(sync);
+ }
+
+ void afterTransactionCompletion(boolean success)
+ {
+ for (Synchronization synchronization : synchronizations)
+ {
+ try
+ {
+ synchronization.afterCompletion(success ? Status.STATUS_COMMITTED :
Status.STATUS_ROLLEDBACK);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ synchronizations.clear();
+ }
+
+ void beforeTransactionCompletion()
+ {
+ for (Synchronization synchronization : synchronizations)
+ {
+ try
+ {
+ synchronization.beforeCompletion();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java 2008-11-21
20:22:22 UTC (rev 350)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.transaction;
+
+import javax.transaction.Synchronization;
+
+public interface Synchronizations
+{
+ public void afterTransactionBegin();
+ public void afterTransactionCommit(boolean success);
+ public void afterTransactionRollback();
+ public void beforeTransactionCommit();
+ public void registerSynchronization(Synchronization sync);
+ public boolean isAwareOfContainerTransactions();
+}
\ No newline at end of file