[seam-commits] Seam SVN: r11658 - in modules/trunk/transaction/src/main/java/org: seamframework and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Nov 23 21:42:50 EST 2009


Author: sboscarine
Date: 2009-11-23 21:42:50 -0500 (Mon, 23 Nov 2009)
New Revision: 11658

Added:
   modules/trunk/transaction/src/main/java/org/seamframework/
   modules/trunk/transaction/src/main/java/org/seamframework/tx/
   modules/trunk/transaction/src/main/java/org/seamframework/tx/EntityTransactionInterceptor.java
   modules/trunk/transaction/src/main/java/org/seamframework/tx/Transactional.java
Log:
initial commit

Added: modules/trunk/transaction/src/main/java/org/seamframework/tx/EntityTransactionInterceptor.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/seamframework/tx/EntityTransactionInterceptor.java	                        (rev 0)
+++ modules/trunk/transaction/src/main/java/org/seamframework/tx/EntityTransactionInterceptor.java	2009-11-24 02:42:50 UTC (rev 11658)
@@ -0,0 +1,35 @@
+package org.seamframework.tx;
+
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import javax.persistence.EntityManager;
+
+/**
+ * Declarative JPA EntityTransactions
+ * 
+ * @author Gavin King
+ *
+ */
+ at Transactional @Interceptor
+public class EntityTransactionInterceptor {
+   
+   private @Inject @Any EntityManager em;
+   
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ic) throws Exception {
+      boolean act = !em.getTransaction().isActive();
+      if (act) em.getTransaction().begin();
+      try {
+         Object result = ic.proceed();
+         if (act) em.getTransaction().commit();
+         return result;
+      }
+      catch (Exception e) {
+         if (act) em.getTransaction().rollback();
+         throw e;
+      }
+   }
+}
\ No newline at end of file

Added: modules/trunk/transaction/src/main/java/org/seamframework/tx/Transactional.java
===================================================================
--- modules/trunk/transaction/src/main/java/org/seamframework/tx/Transactional.java	                        (rev 0)
+++ modules/trunk/transaction/src/main/java/org/seamframework/tx/Transactional.java	2009-11-24 02:42:50 UTC (rev 11658)
@@ -0,0 +1,17 @@
+package org.seamframework.tx;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+ at Retention(RUNTIME)
+ at Target({METHOD, TYPE})
+ at Documented
+ at InterceptorBinding
+public @interface Transactional {}
\ No newline at end of file



More information about the seam-commits mailing list