aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1796656 - in /aries/trunk/transaction/transaction-blueprint/src: main/java/org/apache/aries/transaction/ test/java/org/apache/aries/transaction/
Date Mon, 29 May 2017 15:59:28 GMT
Author: cschneider
Date: Mon May 29 15:59:28 2017
New Revision: 1796656

URL: http://svn.apache.org/viewvc?rev=1796656&view=rev
Log:
ARIES-1690: improved isRollBackException lookup, since annotation attributes are not accessible
in postcall

Added:
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionalAnnotationAttributes.java
Modified:
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/ComponentTxData.java
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
    aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/ComponentTxDataTest.java

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/ComponentTxData.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/ComponentTxData.java?rev=1796656&r1=1796655&r2=1796656&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/ComponentTxData.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/ComponentTxData.java
Mon May 29 15:59:28 2017
@@ -15,7 +15,7 @@ public class ComponentTxData {
     private static final Logger LOG = LoggerFactory.getLogger(ComponentTxData.class);
     private static final int BANNED_MODIFIERS = Modifier.PRIVATE | Modifier.STATIC;
     
-    Map<Method, TxType> txMap = new HashMap<Method, Transactional.TxType>();
+    private Map<Method, TransactionalAnnotationAttributes> txMap = new HashMap<Method,
TransactionalAnnotationAttributes>();
     private boolean isTransactional;
     private Class<?> beanClass;
     
@@ -32,16 +32,16 @@ public class ComponentTxData {
             current = current.getSuperclass();
         }
     }
-    
-    TxType getEffectiveType(Method m) {
+
+    TransactionalAnnotationAttributes getEffectiveType(Method m) {
         if (txMap.containsKey(m)) {
                 return txMap.get(m);
         }
         try {
             Method effectiveMethod = beanClass.getDeclaredMethod(m.getName(), m.getParameterTypes());
-            TxType txType = txMap.get(effectiveMethod);
-            txMap.put(m, txType);
-            return txType;
+            TransactionalAnnotationAttributes txData = txMap.get(effectiveMethod);
+            txMap.put(m, txData);
+            return txData;
         } catch (NoSuchMethodException e) { // NOSONAR
             return getFromMethod(m);
         } catch (SecurityException e) {
@@ -49,12 +49,12 @@ public class ComponentTxData {
         }
     }
 
-    private TxType getFromMethod(Method m) {
+    private TransactionalAnnotationAttributes getFromMethod(Method m) {
         try {
             Method effectiveMethod = beanClass.getMethod(m.getName(), m.getParameterTypes());
-            TxType txType = txMap.get(effectiveMethod);
-            txMap.put(m, txType);
-            return txType;
+            TransactionalAnnotationAttributes txData = txMap.get(effectiveMethod);
+            txMap.put(m, txData);
+            return txData;
         } catch (NoSuchMethodException e1) {
             LOG.debug("No method found when scanning for transactions", e1);
             return null;
@@ -71,13 +71,15 @@ public class ComponentTxData {
         }
         for (Method m : c.getDeclaredMethods()) {
             try {
-                TxType t = getType(m.getAnnotation(Transactional.class));
+                Transactional annotation = m.getAnnotation(Transactional.class);
+                TxType t = getType(annotation);
                 if (t != null) {
-                   assertAllowedModifier(m);
-                   txMap.put(m, t);
+                    TransactionalAnnotationAttributes txData = new TransactionalAnnotationAttributes(t,
annotation.dontRollbackOn(), annotation.rollbackOn());
+                    assertAllowedModifier(m);
+                   txMap.put(m, txData);
                    shouldAssignInterceptor = true;
                 } else if (defaultType != null){
-                   txMap.put(m, defaultType);
+                    txMap.put(m, new TransactionalAnnotationAttributes(defaultType));
                 }
             } catch(IllegalStateException e) {
                 LOG.warn("Invalid transaction annoation found", e);

Added: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionalAnnotationAttributes.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionalAnnotationAttributes.java?rev=1796656&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionalAnnotationAttributes.java
(added)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionalAnnotationAttributes.java
Mon May 29 15:59:28 2017
@@ -0,0 +1,51 @@
+package org.apache.aries.transaction;
+
+import javax.transaction.Transactional.TxType;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class TransactionalAnnotationAttributes {
+
+	private TxType txType;
+	private List<Class> rollbackOn = new ArrayList<Class>();
+	private List<Class> dontRollbackOn = new ArrayList<Class>();
+
+	public TransactionalAnnotationAttributes(TxType defaultType) {
+		this.txType = defaultType;
+	}
+
+	public TransactionalAnnotationAttributes(TxType txType, Class[] dontRollbackOn, Class[]
rollbackOn) {
+		this.txType = txType;
+		if (dontRollbackOn != null) {
+			this.dontRollbackOn = Arrays.asList(dontRollbackOn);
+		}
+		if (rollbackOn != null) {
+			this.rollbackOn = Arrays.asList(rollbackOn);
+		}
+	}
+
+	public TxType getTxType() {
+		return txType;
+	}
+
+	public void setTxType(TxType txType) {
+		this.txType = txType;
+	}
+
+	public List<Class> getRollbackOn() {
+		return rollbackOn;
+	}
+
+	public void setRollbackOn(List<Class> rollbackOn) {
+		this.rollbackOn = rollbackOn;
+	}
+
+	public List<Class> getDontRollbackOn() {
+		return dontRollbackOn;
+	}
+
+	public void setDontRollbackOn(List<Class> dontRollbackOn) {
+		this.dontRollbackOn = dontRollbackOn;
+	}
+}

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=1796656&r1=1796655&r2=1796656&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 May 29 15:59:28 2017
@@ -23,8 +23,6 @@ import java.lang.reflect.Method;
 import javax.transaction.RollbackException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
-import javax.transaction.Transactional;
-import javax.transaction.Transactional.TxType;
 
 import org.apache.aries.blueprint.Interceptor;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -53,12 +51,12 @@ public class TxInterceptorImpl implement
 
     @Override
     public Object preCall(ComponentMetadata cm, Method m, Object... parameters) throws Throwable
{
-        final TxType type = txData.getEffectiveType(m);
+        final TransactionalAnnotationAttributes type = txData.getEffectiveType(m);
         if (type == null) {
             // No transaction
             return null;
         }
-        TransactionAttribute txAttribute = TransactionAttribute.fromValue(type);
+        TransactionAttribute txAttribute = TransactionAttribute.fromValue(type.getTxType());
 
         LOGGER.debug("PreCall for bean {}, method {} with tx strategy {}.", getCmId(cm),
m.getName(), txAttribute);
         TransactionToken token = txAttribute.begin(tm);
@@ -129,13 +127,12 @@ public class TxInterceptorImpl implement
 
     private boolean isRollBackException(Throwable ex, Method m) {
         if (m != null) {
-            Transactional annotation = m.getAnnotation(Transactional.class);
-            if (annotation == null) {
+            TransactionalAnnotationAttributes effectiveType = txData.getEffectiveType(m);
+            if (effectiveType == null) {
                 return isUncheckedException(ex);
             } else {
                 //check dontRollbackOn first, since according to spec it has precedence
-                Class[] dontRollbackOn = annotation.dontRollbackOn();
-                for (Class dontRollbackClass : dontRollbackOn) {
+                for (Class dontRollbackClass : effectiveType.getDontRollbackOn()) {
                     if (dontRollbackClass.isInstance(ex)) {
                         LOGGER.debug("Current exception {} found in element dontRollbackOn.",
ex.getClass());
                         return false;
@@ -145,8 +142,7 @@ public class TxInterceptorImpl implement
                 if (isUncheckedException(ex)) {
                     return true;
                 }
-                Class[] rollbackOn = annotation.rollbackOn();
-                for (Class rollbackExceptionClass : rollbackOn) {
+                for (Class rollbackExceptionClass : effectiveType.getRollbackOn()) {
                     if (rollbackExceptionClass.isInstance(ex)) {
                         LOGGER.debug("Current exception {} found in element rollbackOn.",
ex.getClass());
                         return true;

Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/ComponentTxDataTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/ComponentTxDataTest.java?rev=1796656&r1=1796655&r2=1796656&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/ComponentTxDataTest.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/ComponentTxDataTest.java
Mon May 29 15:59:28 2017
@@ -87,7 +87,7 @@ public class ComponentTxDataTest {
                 throw new IllegalArgumentException(e1);
             }
         }
-        return txData.getEffectiveType(m);
+        return txData.getEffectiveType(m).getTxType();
     }
 
 }



Mime
View raw message