aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1692874 - in /aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction: TxInterceptorImpl.java parsing/AnnotationParser.java
Date Mon, 27 Jul 2015 12:50:03 GMT
Author: cschneider
Date: Mon Jul 27 12:50:03 2015
New Revision: 1692874

URL: http://svn.apache.org/r1692874
Log:
[ARIES-1361] Make sure transactional interceptor is called before jpa interceptor

Modified:
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java?rev=1692874&r1=1692873&r2=1692874&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
Mon Jul 27 12:50:03 2015
@@ -39,7 +39,7 @@ public class TxInterceptorImpl implement
 
     public int getRank()
     {
-      return 0;
+      return 1; // Higher rank than jpa interceptor to make sure transaction is started first
     }
 
     public Object preCall(ComponentMetadata cm, Method m,
@@ -53,37 +53,37 @@ public class TxInterceptorImpl implement
       }
       TransactionAttribute txAttribute = TransactionAttribute.fromValue(type);
       
-      if (LOGGER.isDebugEnabled())
-          LOGGER.debug("Method: " + m + ", has transaction strategy: " + txAttribute);
+      if (LOGGER.isDebugEnabled()) {
+          LOGGER.debug("Calling begin for method {} with tx strategy {}.", m, txAttribute);
+      }
       return txAttribute.begin(tm);
     }
     
     public void postCallWithException(ComponentMetadata cm, Method m,
         Throwable ex, Object preCallToken)
      {
-       if (preCallToken instanceof TransactionToken)
+       if (!(preCallToken instanceof TransactionToken))
        {
-         final TransactionToken token = (TransactionToken)preCallToken;
-         try { 
-             Transaction tran = token.getActiveTransaction();
-             if (tran != null) {
-                 if (ex instanceof RuntimeException || ex instanceof Error) {
-                     tran.setRollbackOnly();
-                 } else {
-                     //declared exception, we don't set rollback
-                 }
-             }
-
-             token.getTransactionAttribute().finish(tm, token);
-         }
-         catch (Exception e)
-         {
-           // we do not throw the exception since there already is one, but we need to log
it
-           LOGGER.warn(Constants.MESSAGES.getMessage("exception.during.tx.cleanup"), e);
+           return;
+       }
+       final TransactionToken token = (TransactionToken)preCallToken;
+       try { 
+         Transaction tran = token.getActiveTransaction();
+         if (tran != null && isRollBackException(ex)) {
+             tran.setRollbackOnly();
          }
-       } else {
-         // TODO: what now?
+
+         token.getTransactionAttribute().finish(tm, token);
        }
+       catch (Exception e)
+       {
+         // we do not throw the exception since there already is one, but we need to log
it
+         LOGGER.warn(Constants.MESSAGES.getMessage("exception.during.tx.cleanup"), e);
+       }
+    }
+
+    private boolean isRollBackException(Throwable ex) {
+        return ex instanceof RuntimeException || ex instanceof Error;
     }
 
     public void postCallWithReturn(ComponentMetadata cm, Method m,

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java?rev=1692874&r1=1692873&r2=1692874&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
Mon Jul 27 12:50:03 2015
@@ -30,12 +30,15 @@ import org.apache.aries.transaction.TxCo
 import org.apache.aries.transaction.annotations.Transaction;
 import org.apache.aries.transaction.annotations.TransactionPropagationType;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Adds the transactional interceptor if Transaction annotation is present
  * on bean class or superclasses.
  */
 public class AnnotationParser implements BeanProcessor {
+    private static final Logger LOGGER = LoggerFactory.getLogger(AnnotationParser.class);
 
     private final ComponentDefinitionRegistry cdr;
     private final Interceptor interceptor;
@@ -67,6 +70,7 @@ public class AnnotationParser implements
         }
         
         if (shouldAssignInterceptor && !isInterceptorAssigned(beanData)) {
+            LOGGER.debug("Adding transaction interceptor to {} with class {}.", beanName,
bean.getClass());
             cdr.registerInterceptorWithComponent(beanData, interceptor);
         }
 



Mime
View raw message