deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-780 allow fine-grained customizations
Date Sat, 15 Nov 2014 20:10:57 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 1a4d94523 -> e3ce1da69


DELTASPIKE-780 allow fine-grained customizations


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/e3ce1da6
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/e3ce1da6
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/e3ce1da6

Branch: refs/heads/master
Commit: e3ce1da6945f6336efca40b11cc14ae18ebfe117
Parents: 1a4d945
Author: gpetracek <gpetracek@apache.org>
Authored: Sat Nov 15 20:49:13 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Sat Nov 15 21:10:41 2014 +0100

----------------------------------------------------------------------
 .../BeanManagedUserTransactionStrategy.java     |  8 ++-
 .../EnvironmentAwareTransactionStrategy.java    |  7 ++-
 .../ResourceLocalTransactionStrategy.java       | 63 +++++++++++++++++---
 3 files changed, 66 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e3ce1da6/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
index 700b224..35e0ad3 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
@@ -27,6 +27,7 @@ import org.apache.deltaspike.jpa.impl.transaction.context.EntityManagerEntry;
 import javax.annotation.Resource;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Alternative;
+import javax.interceptor.InvocationContext;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
 import javax.transaction.Status;
@@ -156,11 +157,14 @@ public class BeanManagedUserTransactionStrategy extends ResourceLocalTransaction
      * {@link BeanManagedUserTransactionStrategy.UserTransactionAdapter#begin()}
      * will only executed once, but {@link javax.persistence.EntityManager#joinTransaction()}
      * needs to be called for every {@link EntityManager}.
-     *
+     * @param invocationContext current invocation-context
      * @param entityManagerEntry entry of the current entity-manager
+     * @param transaction current JTA transaction wrapped in an EntityTransaction adapter
      */
     @Override
-    protected void beforeProceed(EntityManagerEntry entityManagerEntry)
+    protected void beforeProceed(InvocationContext invocationContext,
+                                 EntityManagerEntry entityManagerEntry,
+                                 EntityTransaction transaction)
     {
         entityManagerEntry.getEntityManager().joinTransaction();
     }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e3ce1da6/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
index fcdc15d..deebb26 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
@@ -22,6 +22,7 @@ import org.apache.deltaspike.jpa.impl.transaction.context.EntityManagerEntry;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Alternative;
+import javax.interceptor.InvocationContext;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
 import java.lang.annotation.Annotation;
@@ -99,11 +100,13 @@ public class EnvironmentAwareTransactionStrategy extends BeanManagedUserTransact
     }
 
     @Override
-    protected void beforeProceed(EntityManagerEntry entityManagerEntry)
+    protected void beforeProceed(InvocationContext invocationContext,
+                                 EntityManagerEntry entityManagerEntry,
+                                 EntityTransaction transaction)
     {
         if (isInJtaTransaction())
         {
-            super.beforeProceed(entityManagerEntry);
+            super.beforeProceed(invocationContext, entityManagerEntry, transaction);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e3ce1da6/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalTransactionStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalTransactionStrategy.java
b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalTransactionStrategy.java
index a844642..9e810a8 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalTransactionStrategy.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalTransactionStrategy.java
@@ -118,6 +118,7 @@ public class ResourceLocalTransactionStrategy implements TransactionStrategy
 
                 if (!transaction.isActive())
                 {
+                    beforeBegin(invocationContext, entityManagerEntry, transaction);
                     transaction.begin();
                 }
                 else if (isOutermostInterceptor)
@@ -126,7 +127,7 @@ public class ResourceLocalTransactionStrategy implements TransactionStrategy
                 }
 
                 //don't move it before EntityTransaction#begin() and invoke it in any case
-                beforeProceed(entityManagerEntry);
+                beforeProceed(invocationContext, entityManagerEntry, transaction);
             }
 
             return invocationContext.proceed();
@@ -240,10 +241,12 @@ public class ResourceLocalTransactionStrategy implements TransactionStrategy
                                     // last chance to check it (again)
                                     if (commitFailed || transaction.getRollbackOnly())
                                     {
+                                        beforeRollback(invocationContext, currentEntityManagerEntry,
transaction);
                                         transaction.rollback();
                                     }
                                     else
                                     {
+                                        beforeCommit(invocationContext, currentEntityManagerEntry,
transaction);
                                         transaction.commit();
                                     }
                                 }
@@ -252,6 +255,10 @@ public class ResourceLocalTransactionStrategy implements TransactionStrategy
                                     firstException = e;
                                     commitFailed = true;
                                 }
+                                finally
+                                {
+                                    afterProceed(invocationContext,currentEntityManagerEntry,
firstException);
+                                }
                             }
                         }
                     }
@@ -265,12 +272,57 @@ public class ResourceLocalTransactionStrategy implements TransactionStrategy
 
             if (commitFailed && firstException != null /*null if just #getRollbackOnly
is true*/)
             {
-                //noinspection ThrowFromFinallyBlock
-                throw firstException;
+                throwException(firstException);
             }
         }
     }
 
+    protected void beforeBegin(InvocationContext invocationContext,
+                               EntityManagerEntry entityManagerEntry,
+                               EntityTransaction transaction)
+    {
+        //override if needed
+    }
+
+    protected void beforeProceed(InvocationContext invocationContext,
+                                 EntityManagerEntry entityManagerEntry,
+                                 EntityTransaction transaction)
+    {
+        //override if needed
+    }
+
+    protected void beforeCommit(InvocationContext invocationContext,
+                                EntityManagerEntry entityManagerEntry,
+                                EntityTransaction transaction)
+    {
+        //override if needed
+    }
+
+    protected void beforeRollback(InvocationContext invocationContext,
+                                  EntityManagerEntry entityManagerEntry,
+                                  EntityTransaction transaction)
+    {
+        //override if needed
+    }
+
+    /**
+     * @param invocationContext current invocation-context
+     * @param entityManagerEntry current entity-manager entry
+     * @param exception the exception which occurred or null if everything went fine
+     */
+    protected void afterProceed(InvocationContext invocationContext,
+                                EntityManagerEntry entityManagerEntry,
+                                Exception exception)
+    {
+        //override if needed
+    }
+
+    protected void throwException(Exception exception) throws Exception
+    {
+        //override if needed
+        throw exception;
+    }
+
     //allows to use a custom tx-controller in a custom strategy
     protected boolean isRollbackOnly(Transactional transactionalAnnotation)
     {
@@ -318,11 +370,6 @@ public class ResourceLocalTransactionStrategy implements TransactionStrategy
         return entityManagerEntry.getEntityManager().getTransaction();
     }
 
-    protected void beforeProceed(EntityManagerEntry entityManagerEntry)
-    {
-        //override if needed
-    }
-
     private EntityManager resolveEntityManagerForQualifier(Class<? extends Annotation>
emQualifier)
     {
         if (emHolder.isSet())


Mime
View raw message