You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/04/22 15:01:31 UTC

tomee git commit: caching exception handling by method

Repository: tomee
Updated Branches:
  refs/heads/master 2b685fcda -> 4e4342a0d


caching exception handling by method


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

Branch: refs/heads/master
Commit: 4e4342a0d6960208d0d9b3f2ae1c5830ce9a6bc7
Parents: 2b685fc
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed Apr 22 15:01:18 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed Apr 22 15:01:18 2015 +0200

----------------------------------------------------------------------
 .../openejb/cdi/transactional/InterceptorBase.java  | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/4e4342a0/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/InterceptorBase.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/InterceptorBase.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/InterceptorBase.java
index 063635c..03b794b 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/InterceptorBase.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/InterceptorBase.java
@@ -41,7 +41,7 @@ public abstract class InterceptorBase implements Serializable {
     private static final IllegalStateException ILLEGAL_STATE_EXCEPTION = new IllegalStateException("Can't use UserTransaction from @Transaction call");
     private static final boolean HANDLE_EXCEPTION_ONLY_FOR_CLIENT = SystemInstance.get().getOptions().get("openejb.cdi.jta.exception.client-only", false);
 
-    private transient ConcurrentMap<Class<?>, Boolean> rollback = new ConcurrentHashMap<>();
+    private transient volatile ConcurrentMap<Method, Boolean> rollback = new ConcurrentHashMap<>();
 
     protected Object intercept(final InvocationContext ic) throws Exception {
         Exception error = null;
@@ -74,15 +74,21 @@ public abstract class InterceptorBase implements Serializable {
 
             if (policy != null) {
                 if (error != null && (!HANDLE_EXCEPTION_ONLY_FOR_CLIENT || policy.isNewTransaction())) {
-                    final Class<?> errorClass = error.getClass();
-                    Boolean doRollback = rollback.get(errorClass);
+                    final Method method = ic.getMethod();
+                    if (rollback == null) {
+                        synchronized (this) {
+                            if (rollback == null) {
+                                rollback = new ConcurrentHashMap<>();
+                            }
+                        }
+                    }
+                    Boolean doRollback = rollback.get(method);
                     if (doRollback != null) {
                         if (doRollback) {
                             policy.setRollbackOnly();
                         }
                     } else {
                         // computed lazily but we could cache it later for sure if that's really a normal case
-                        final Method method = ic.getMethod();
                         final AnnotatedType<?> annotatedType = CDI.current().getBeanManager().createAnnotatedType(method.getDeclaringClass());
                         Transactional tx = null;
                         for (final AnnotatedMethod<?> m : annotatedType.getMethods()) {
@@ -96,7 +102,7 @@ public abstract class InterceptorBase implements Serializable {
                         }
                         if (tx != null) {
                             doRollback = new ExceptionPriotiryRules(tx.rollbackOn(), tx.dontRollbackOn()).accept(error, method.getExceptionTypes());
-                            rollback.putIfAbsent(errorClass, doRollback);
+                            rollback.putIfAbsent(method, doRollback);
                             if (doRollback) {
                                 policy.setRollbackOnly();
                             }