aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1724230 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/ main/java/org/apache/aries/blueprint/plugin/model/ test/java/org/apache/aries/blueprint/plugin/ test/java/org/apache/aries/bluepri...
Date Tue, 12 Jan 2016 13:42:29 GMT
Author: cschneider
Date: Tue Jan 12 13:42:29 2016
New Revision: 1724230

URL: http://svn.apache.org/viewvc?rev=1724230&view=rev
Log:
[ARIES-1475] Implement per-method transaction support.

Added:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/AbstractTransactionalFactory.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean3.java
      - copied, changed from r1724229, aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/JavaxTransactionFactory.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/SpringTransactionFactory.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/TransactionalDef.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
Tue Jan 12 13:42:29 2016
@@ -44,7 +44,7 @@ public class Generator implements Proper
     public static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0";
     public static final String NS_TX = "http://aries.apache.org/xmlns/transactions/v1.2.0";
     public static final String NS_TX2 = "http://aries.apache.org/xmlns/transactions/v2.0.0";
-    
+
     private Context context;
     private XMLStreamWriter writer;
     private Set<String> namespaces;
@@ -65,7 +65,7 @@ public class Generator implements Proper
             writer.writeCharacters("\n");
             writeBlueprint();
             writer.writeCharacters("\n");
-            
+
             if (namespaces.contains(NS_JPA2) && isJpaUsed()) {
                 writer.writeEmptyElement(NS_JPA2, "enable");
                 writer.writeCharacters("\n");
@@ -84,10 +84,10 @@ public class Generator implements Proper
                 writer.writeEndElement();
                 writer.writeCharacters("\n");
             }
-            
+
             new OsgiServiceRefWriter(writer).write(context.getServiceRefs());
             new OsgiServiceProviderWriter(writer).write(context.getBeans());
-            
+
             writer.writeEndElement();
             writer.writeCharacters("\n");
             writer.writeEndDocument();
@@ -109,14 +109,12 @@ public class Generator implements Proper
     }
 
     private boolean isJtaUsed() {
-        boolean jtaUsed = false;
         for (Bean bean : context.getBeans()) {
-            if (bean.transactionDef != null) {
-                jtaUsed = true;
+            if (!bean.transactionDefs.isEmpty()) {
+                return true;
             }
-
         }
-        return jtaUsed;
+        return false;
     }
 
     private void writeBlueprint() throws XMLStreamException {
@@ -128,7 +126,7 @@ public class Generator implements Proper
             writer.writeNamespace(prefix, namespace);
         }
     }
-    
+
     private String getPrefixForNamesapace(String namespace) {
         if (namespace.contains("jpa")) {
             return "jpa";
@@ -156,15 +154,17 @@ public class Generator implements Proper
             writer.writeAttribute("destroy-method", bean.destroyMethod);
         }
         writer.writeCharacters("\n");
-        
+
         if (namespaces.contains(NS_TX)) {
-            writeTransactional(bean.transactionDef);
+            for (TransactionalDef transactionalDef : bean.transactionDefs) {
+                writeTransactional(transactionalDef);
+            }
         }
         if (namespaces.contains(NS_JPA)) {
             writePersistenceFields(bean.persistenceFields);
         }
     }
-    
+
     private void writeFactory(ProducedBean bean) throws XMLStreamException {
         writer.writeAttribute("factory-ref", bean.factoryBean.id);
         writer.writeAttribute("factory-method", bean.factoryMethod);
@@ -181,7 +181,7 @@ public class Generator implements Proper
         }
     }
 
-    
+
     private void writePersistenceFields(Field[] fields) throws XMLStreamException {
         for (Field field : fields) {
             writePersistenceField(field);

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/AbstractTransactionalFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/AbstractTransactionalFactory.java?rev=1724230&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/AbstractTransactionalFactory.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/AbstractTransactionalFactory.java
Tue Jan 12 13:42:29 2016
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.plugin.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Abstract factory for creating {@link TransactionalDef} for a given class.
+ *
+ * @param <A> the transactional annotation type.
+ */
+public abstract class AbstractTransactionalFactory<A extends Annotation>
+{
+    /**
+     * Create {@link TransactionalDef} objects for the given class, inspecting
+     * class and methods for transaction annotations.
+     *
+     * @param clazz the class to inspect.
+     * @return a set of {@link TransactionalDef} objects.
+     */
+    public Set<TransactionalDef> create(Class<?> clazz) {
+        Set<TransactionalDef> transactionalDefs = new HashSet<TransactionalDef>();
+        A transactional = clazz.getAnnotation(getTransactionalClass());
+        if (transactional != null) {
+            transactionalDefs.add(new TransactionalDef("*", getTransactionTypeName(transactional)));
+        }
+        for (Method method : clazz.getMethods()) {
+            transactional = method.getAnnotation(getTransactionalClass());
+            if (transactional != null) {
+                transactionalDefs.add(new TransactionalDef(method.getName(), getTransactionTypeName(transactional)));
+            }
+        }
+        return transactionalDefs;
+    }
+
+    /**
+     * @param transactional the transactional annotation.
+     * @return the blueprint-compatible name of the transaction type.
+     */
+    public abstract String getTransactionTypeName(A transactional);
+
+    /**
+     * @return the annotation class to search for.
+     */
+    public abstract Class<A> getTransactionalClass();
+}

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
Tue Jan 12 13:42:29 2016
@@ -22,7 +22,9 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -42,7 +44,7 @@ public class Bean extends BeanRef {
     public String destroyMethod;
     public SortedSet<Property> properties;
     public Field[] persistenceFields;
-    public TransactionalDef transactionDef;
+    public Set<TransactionalDef> transactionDefs = new HashSet<TransactionalDef>();
     public boolean isPrototype;
 
     public Bean(Class<?> clazz) {
@@ -59,12 +61,12 @@ public class Bean extends BeanRef {
         if (destroyMethod != null) {
             this.destroyMethod = destroyMethod.getName();
         }
+
+        // Transactional methods
+        transactionDefs.addAll(new JavaxTransactionFactory().create(clazz));
+        transactionDefs.addAll(new SpringTransactionFactory().create(clazz));
         this.isPrototype = isPrototype(clazz);
         this.persistenceFields = getPersistenceFields();
-        this.transactionDef = new JavaxTransactionFactory().create(clazz);
-        if (this.transactionDef == null) {
-            this.transactionDef = new SpringTransactionFactory().create(clazz);
-        }
         properties = new TreeSet<Property>();
     }
 

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/JavaxTransactionFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/JavaxTransactionFactory.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/JavaxTransactionFactory.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/JavaxTransactionFactory.java
Tue Jan 12 13:42:29 2016
@@ -23,7 +23,9 @@ import java.util.HashMap;
 import javax.transaction.Transactional;
 import javax.transaction.Transactional.TxType;
 
-public class JavaxTransactionFactory {
+import com.google.common.base.CaseFormat;
+
+public class JavaxTransactionFactory extends AbstractTransactionalFactory<Transactional>
{
     private static HashMap<TxType, String> txTypeNames;
 
     static {
@@ -31,10 +33,16 @@ public class JavaxTransactionFactory {
         txTypeNames.put(TxType.REQUIRED, TransactionalDef.TYPE_REQUIRED);
         txTypeNames.put(TxType.REQUIRES_NEW, TransactionalDef.TYPE_REQUIRES_NEW);
     }
-    
-    TransactionalDef create(Class<?> clazz) {
-        Transactional transactional = clazz.getAnnotation(Transactional.class);
-        return transactional != null ? 
-                new TransactionalDef("*", txTypeNames.get(transactional.value())) : null;
+
+    @Override
+    public String getTransactionTypeName(Transactional transactional)
+    {
+        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, transactional.value().name());
+    }
+
+    @Override
+    public Class<Transactional> getTransactionalClass()
+    {
+        return Transactional.class;
     }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/SpringTransactionFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/SpringTransactionFactory.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/SpringTransactionFactory.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/SpringTransactionFactory.java
Tue Jan 12 13:42:29 2016
@@ -18,23 +18,25 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
-import java.util.HashMap;
-
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
-public class SpringTransactionFactory {
-    private static HashMap<Propagation, String> txTypeNames;
+import com.google.common.base.CaseFormat;
 
-    static {
-        txTypeNames = new HashMap<Propagation, String>();
-        txTypeNames.put(Propagation.REQUIRED, TransactionalDef.TYPE_REQUIRED);
-        txTypeNames.put(Propagation.REQUIRES_NEW, TransactionalDef.TYPE_REQUIRES_NEW);
+public class SpringTransactionFactory extends AbstractTransactionalFactory<Transactional>
{
+    @Override
+    public String getTransactionTypeName(Transactional transactional)
+    {
+        Propagation propagation = transactional.propagation();
+        if (propagation == Propagation.NESTED) {
+            throw new UnsupportedOperationException("Nested transactions not supported");
+        }
+        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, propagation.name());
     }
 
-    TransactionalDef create(Class<?> clazz) {
-        Transactional transactional = clazz.getAnnotation(Transactional.class);
-        return transactional != null ? 
-                new TransactionalDef("*", txTypeNames.get(transactional.propagation())) :
null;
+    @Override
+    public Class<Transactional> getTransactionalClass()
+    {
+        return Transactional.class;
     }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/TransactionalDef.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/TransactionalDef.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/TransactionalDef.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/TransactionalDef.java
Tue Jan 12 13:42:29 2016
@@ -18,13 +18,14 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
+import com.google.common.base.Objects;
 
 public class TransactionalDef {
     public static final String TYPE_REQUIRED = "Required";
     public static final String TYPE_REQUIRES_NEW = "RequiresNew";
     private String method;
     private String type;
-    
+
     public TransactionalDef(String method, String type) {
         this.method = method;
         this.type = type;
@@ -33,8 +34,35 @@ public class TransactionalDef {
     public String getMethod() {
         return method;
     }
-    
+
     public String getType() {
         return type;
     }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o)
+        {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass())
+        {
+            return false;
+        }
+        TransactionalDef that = (TransactionalDef) o;
+        return Objects.equal(method, that.method) && Objects.equal(type, that.type);
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return Objects.hashCode(method, type);
+    }
+
+    @Override
+    public String toString()
+    {
+        return Objects.toStringHelper(this).add("method", method).add("type", type).toString();
+    }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
Tue Jan 12 13:42:29 2016
@@ -36,6 +36,7 @@ import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathFactory;
 
 import org.apache.aries.blueprint.plugin.model.Context;
+import org.apache.aries.blueprint.plugin.model.TransactionalDef;
 import org.apache.aries.blueprint.plugin.test.MyBean1;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.xbean.finder.ClassFinder;
@@ -43,8 +44,11 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
+import com.google.common.collect.Sets;
+
 public class GeneratorTest {
 
     private XPath xpath;
@@ -73,19 +77,31 @@ public class GeneratorTest {
         Assert.assertEquals("destroy", xpath.evaluate("@destroy-method", bean1));
         Assert.assertEquals("true", xpath.evaluate("@field-injection", bean1));
         Assert.assertEquals("", xpath.evaluate("@scope", bean1));
-        
+
         // @Transactional
-        Assert.assertEquals("*", xpath.evaluate("transaction/@method", bean1));
-        Assert.assertEquals("Required", xpath.evaluate("transaction/@value", bean1));
+        NodeList txs = (NodeList) xpath.evaluate("transaction", bean1, XPathConstants.NODESET);
+        Set<TransactionalDef> defs = new HashSet<TransactionalDef>();
+        for (int i = 0; i < txs.getLength(); ++i) {
+            Node tx = txs.item(i);
+            defs.add(new TransactionalDef(xpath.evaluate("@method", tx), xpath.evaluate("@value",
tx)));
+        }
+        Set<TransactionalDef> expectedDefs = Sets.newHashSet(new TransactionalDef("*",
"RequiresNew"),
+                                                             new TransactionalDef("txNotSupported",
"NotSupported"),
+                                                             new TransactionalDef("txMandatory",
"Mandatory"),
+                                                             new TransactionalDef("txNever",
"Never"),
+                                                             new TransactionalDef("txRequired",
"Required"),
+                                                             new TransactionalDef("txOverridenWithRequiresNew",
"RequiresNew"),
+                                                             new TransactionalDef("txSupports",
"Supports"));
+        Assert.assertEquals(expectedDefs, defs);
 
         // @PersistenceContext
         Assert.assertEquals("person", xpath.evaluate("context/@unitname", bean1));
         Assert.assertEquals("em", xpath.evaluate("context/@property", bean1));
-        
+
         // @PersistenceUnit
         Assert.assertEquals("person", xpath.evaluate("unit/@unitname", bean1));
         Assert.assertEquals("emf", xpath.evaluate("unit/@property", bean1));
-        
+
         // @Autowired
         Assert.assertEquals("my1", xpath.evaluate("property[@name='bean2']/@ref", bean1));
 

Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean3.java
(from r1724229, aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean3.java?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean3.java&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java&r1=1724229&r2=1724230&rev=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadBean3.java
Tue Jan 12 13:42:29 2016
@@ -16,18 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.blueprint.plugin.test;
+package org.apache.aries.blueprint.plugin.bad;
 
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
-public class ParentBean {
+public class BadBean3
+{
+    @Transactional(propagation = Propagation.NESTED)
+    public void txNestedIsNotSupported() {
 
-    @PostConstruct
-    public void overridenInit() {
-    }
-
-    @PreDestroy
-    public void destroy() {
     }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
Tue Jan 12 13:42:29 2016
@@ -23,10 +23,13 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.Set;
+
 import javax.inject.Named;
 
 import org.apache.aries.blueprint.plugin.bad.BadBean1;
 import org.apache.aries.blueprint.plugin.bad.BadBean2;
+import org.apache.aries.blueprint.plugin.bad.BadBean3;
 import org.apache.aries.blueprint.plugin.test.MyBean1;
 import org.apache.aries.blueprint.plugin.test.MyBean3;
 import org.apache.aries.blueprint.plugin.test.MyBean4;
@@ -34,6 +37,7 @@ import org.apache.aries.blueprint.plugin
 import org.junit.Assert;
 import org.junit.Test;
 
+import com.google.common.collect.Sets;
 
 public class BeanTest {
 
@@ -48,13 +52,20 @@ public class BeanTest {
         Assert.assertEquals(2, bean.persistenceFields.length);
         assertEquals("em", bean.persistenceFields[0].getName());
         assertEquals("emf", bean.persistenceFields[1].getName());
-        assertEquals("*", bean.transactionDef.getMethod());
-        assertEquals("Required", bean.transactionDef.getType());
         assertEquals(1, bean.properties.size());
         assertFalse(bean.isPrototype);
         Property prop = bean.properties.iterator().next();
         assertEquals("bean2", prop.name);
         assertEquals("serviceA", prop.ref);
+
+        Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*",
"RequiresNew"),
+                                                            new TransactionalDef("txNotSupported",
"NotSupported"),
+                                                            new TransactionalDef("txMandatory",
"Mandatory"),
+                                                            new TransactionalDef("txNever",
"Never"),
+                                                            new TransactionalDef("txRequired",
"Required"),
+                                                            new TransactionalDef("txOverridenWithRequiresNew",
"RequiresNew"),
+                                                            new TransactionalDef("txSupports",
"Supports"));
+        assertEquals(expectedTxs, bean.transactionDefs);
     }
 
     @Test
@@ -66,10 +77,17 @@ public class BeanTest {
         assertNull("There should be no initMethod", bean.initMethod);
         assertNull("There should be no destroyMethod", bean.destroyMethod);
         assertEquals("There should be no persistence fields", 0, bean.persistenceFields.length);
-        assertEquals("*", bean.transactionDef.getMethod());
-        assertEquals("RequiresNew", bean.transactionDef.getType());
         assertEquals(5, bean.properties.size());
         assertTrue(bean.isPrototype);
+
+        Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*",
"RequiresNew"),
+                                                            new TransactionalDef("txNotSupported",
"NotSupported"),
+                                                            new TransactionalDef("txMandatory",
"Mandatory"),
+                                                            new TransactionalDef("txNever",
"Never"),
+                                                            new TransactionalDef("txRequired",
"Required"),
+                                                            new TransactionalDef("txRequiresNew",
"RequiresNew"),
+                                                            new TransactionalDef("txSupports",
"Supports"));
+        assertEquals(expectedTxs, bean.transactionDefs);
     }
 
     @Test
@@ -82,7 +100,7 @@ public class BeanTest {
         assertNull("There should be no initMethod", bean.initMethod);
         assertNull("There should be no destroyMethod", bean.destroyMethod);
         assertEquals("There should be no persistence fields", 0, bean.persistenceFields.length);
-        assertNull("There should be no transaction definition", bean.transactionDef);
+        assertTrue("There should be no transaction definition", bean.transactionDefs.isEmpty());
         assertEquals("There should be no properties", 0, bean.properties.size());
         assertTrue(bean.isPrototype);
     }
@@ -95,6 +113,9 @@ public class BeanTest {
         assertEquals("bundleContext", bcProp.name);
         assertEquals("blueprintBundleContext", bcProp.ref);
         assertFalse(bean.isPrototype);
+
+        Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("txWithoutClassAnnotation",
"Supports"));
+        assertEquals(expectedTxs, bean.transactionDefs);
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -106,4 +127,9 @@ public class BeanTest {
     public void testMultipleDestroyMethods() {
         new Bean(BadBean2.class);
     }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testSpringNestedTransactionNotSupported() {
+        new Bean(BadBean3.class);
+    }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
Tue Jan 12 13:42:29 2016
@@ -29,7 +29,7 @@ import javax.transaction.Transactional.T
 import org.springframework.beans.factory.annotation.Autowired;
 
 @Singleton
-@Transactional(value=TxType.REQUIRED)
+@Transactional(value=TxType.REQUIRES_NEW)
 public class MyBean1 extends ParentBean {
 
     @Autowired
@@ -48,9 +48,30 @@ public class MyBean1 extends ParentBean
 
     @PostConstruct
     public void init() {
+
+    }
+
+    @Transactional(TxType.NOT_SUPPORTED)
+    public void txNotSupported() {
+    }
+
+    @Transactional(TxType.MANDATORY)
+    public void txMandatory() {
     }
 
-    public void saveData() {
+    @Transactional(TxType.NEVER)
+    public void txNever() {
+    }
+
+    @Transactional(TxType.REQUIRED)
+    public void txRequired() {
+    }
+
+    @Override
+    public void txOverridenWithoutTransactional() {
+    }
 
+    @Transactional(TxType.REQUIRES_NEW)
+    public void txOverridenWithRequiresNew() {
     }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean3.java
Tue Jan 12 13:42:29 2016
@@ -39,11 +39,35 @@ public class MyBean3 {
 
     @Inject
     ServiceB serviceB;
-    
+
     @Inject
     @Named("serviceB2Id")
     ServiceB serviceB2;
-    
+
     @Inject
     MyProduced myProduced;
+
+    @Transactional(propagation = Propagation.NOT_SUPPORTED)
+    public void txNotSupported() {
+    }
+
+    @Transactional(propagation = Propagation.MANDATORY)
+    public void txMandatory() {
+    }
+
+    @Transactional(propagation = Propagation.NEVER)
+    public void txNever() {
+    }
+
+    @Transactional(propagation = Propagation.REQUIRED)
+    public void txRequired() {
+    }
+
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    public void txRequiresNew() {
+    }
+
+    @Transactional(propagation = Propagation.SUPPORTS)
+    public void txSupports() {
+    }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java
Tue Jan 12 13:42:29 2016
@@ -4,10 +4,17 @@ import javax.inject.Inject;
 
 import org.osgi.framework.BundleContext;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 @Component
 public class MyBean4 {
 
     @Inject
     BundleContext bundleContext;
+
+    @Transactional(propagation = Propagation.SUPPORTS)
+    public void txWithoutClassAnnotation() {
+
+    }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java?rev=1724230&r1=1724229&r2=1724230&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
Tue Jan 12 13:42:29 2016
@@ -20,6 +20,7 @@ package org.apache.aries.blueprint.plugi
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.transaction.Transactional;
 
 public class ParentBean {
 
@@ -30,4 +31,16 @@ public class ParentBean {
     @PreDestroy
     public void destroy() {
     }
+
+    @Transactional(Transactional.TxType.REQUIRES_NEW)
+    public void txOverridenWithoutTransactional() {
+    }
+
+    @Transactional(Transactional.TxType.SUPPORTS)
+    public void txSupports() {
+    }
+
+    @Transactional(Transactional.TxType.NEVER)
+    public void txOverridenWithRequiresNew() {
+    }
 }



Mime
View raw message