aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1689592 - in /aries/trunk/transaction: transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/ transaction-blueprint/src/test/java/org/apache/aries/transaction/ transaction-itests/src/test/java/org/apache/aries/transactio...
Date Tue, 07 Jul 2015 08:02:09 GMT
Author: cschneider
Date: Tue Jul  7 08:02:09 2015
New Revision: 1689592

URL: http://svn.apache.org/r1689592
Log:
ARIES-628

Added:
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
    aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/AnnotatedTestBeanImpl.java
Modified:
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
    aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java
    aries/trunk/transaction/transaction-testbundle/pom.xml
    aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml

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=1689592&r1=1689591&r2=1689592&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
Tue Jul  7 08:02:09 2015
@@ -48,7 +48,7 @@ public class AnnotationParser implements
     }
 
     public Object afterInit(Object arg0, String arg1, BeanCreator arg2, BeanMetadata arg3)
{
-        return null;
+        return arg0;
     }
 
     public void beforeDestroy(Object arg0, String arg1) {

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java?rev=1689592&r1=1689591&r2=1689592&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
Tue Jul  7 08:02:09 2015
@@ -36,6 +36,7 @@ import org.apache.aries.blueprint.Interc
 import org.apache.aries.blueprint.NamespaceHandler;
 import org.apache.aries.blueprint.ParserContext;
 import org.apache.aries.blueprint.PassThroughMetadata;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
 import org.apache.aries.blueprint.mutable.MutablePassThroughMetadata;
 import org.apache.aries.transaction.BundleWideTxData;
 import org.apache.aries.transaction.Constants;
@@ -114,12 +115,25 @@ public class TxNamespaceHandler implemen
             Node n = elt.getChildNodes().item(0);
             if(n == null || Boolean.parseBoolean(n.getNodeValue())) {
                 //We need to register a bean processor to add annotation-based config
-                if(!!!cdr.containsComponentDefinition(ANNOTATION_PARSER_BEAN_NAME)) {
-                	
-                	MutablePassThroughMetadata mptmd = pc.createMetadata(MutablePassThroughMetadata.class);
-                	mptmd.setId(ANNOTATION_PARSER_BEAN_NAME);
-                	mptmd.setObject(new AnnotationParser(cdr, interceptor, metaDataHelper));
-                    cdr.registerComponentDefinition(mptmd);
+                if (!cdr.containsComponentDefinition(ANNOTATION_PARSER_BEAN_NAME)) {
+                    MutableBeanMetadata meta = pc.createMetadata(MutableBeanMetadata.class);
+                    meta.setId(ANNOTATION_PARSER_BEAN_NAME);
+                    meta.setRuntimeClass(AnnotationParser.class);
+                    meta.setProcessor(true);
+
+                	MutablePassThroughMetadata cdrMeta = pc.createMetadata(MutablePassThroughMetadata.class);
+                    cdrMeta.setObject(cdr);
+                    meta.addArgument(cdrMeta, ComponentDefinitionRegistry.class.getName(),
0);
+
+                    MutablePassThroughMetadata interceptorMeta = pc.createMetadata(MutablePassThroughMetadata.class);
+                    interceptorMeta.setObject(interceptor);
+                    meta.addArgument(interceptorMeta, Interceptor.class.getName(), 1);
+
+                    MutablePassThroughMetadata helperMeta = pc.createMetadata(MutablePassThroughMetadata.class);
+                    helperMeta.setObject(metaDataHelper);
+                    meta.addArgument(helperMeta, TxComponentMetaDataHelper.class.getName(),
2);
+
+                    cdr.registerComponentDefinition(meta);
                 }
             }
         }

Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java?rev=1689592&r1=1689591&r2=1689592&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/AnnotationEnablingNameSpaceHandlerTest.java
Tue Jul  7 08:02:09 2015
@@ -24,12 +24,15 @@ import static org.junit.Assert.assertNul
 
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.apache.aries.blueprint.PassThroughMetadata;
+import org.apache.aries.blueprint.container.BeanRecipe;
+import org.apache.aries.blueprint.container.BlueprintContainerImpl;
 import org.apache.aries.transaction.annotations.TransactionPropagationType;
 import org.apache.aries.transaction.parsing.AnnotationParser;
 import org.apache.aries.transaction.parsing.TxNamespaceHandler;
 import org.apache.aries.transaction.pojo.AnnotatedPojo;
 import org.junit.Test;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
 
 public class AnnotationEnablingNameSpaceHandlerTest extends BaseNameSpaceHandlerSetup {
     
@@ -43,16 +46,13 @@ public class AnnotationEnablingNameSpace
       assertNotNull(compTop);
       assertEquals(0, cdr.getInterceptors(compTop).size());
       assertNull(txenhancer.getComponentMethodTxAttribute(compTop, "increment"));
-      
-      
-      PassThroughMetadata pmd = (PassThroughMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
+
+      BeanMetadata pmd = (BeanMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
       assertNotNull(pmd);
-      
-      AnnotationParser parser  = (AnnotationParser) pmd.getObject();
-      parser.beforeInit(new AnnotatedPojo(), "top", null, compTop);
-      
-      assertEquals(TransactionPropagationType.Required, txenhancer.getComponentMethodTxAttribute(compTop,
"increment"));
-      assertEquals(1, cdr.getInterceptors(compTop).size());
+
+      assertEquals(3, pmd.getArguments().size());
+      assertEquals(cdr, ((PassThroughMetadata)pmd.getArguments().get(0).getValue()).getObject());
+      assertEquals(txenhancer, ((PassThroughMetadata) pmd.getArguments().get(2).getValue()).getObject());
     }
     
     @Test
@@ -65,9 +65,9 @@ public class AnnotationEnablingNameSpace
         assertNotNull(compTop);
         assertEquals(0, cdr.getInterceptors(compTop).size());
         assertNull(txenhancer.getComponentMethodTxAttribute(compTop, "increment"));
-        
-        
-        PassThroughMetadata pmd = (PassThroughMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
+
+
+        BeanMetadata pmd = (BeanMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
         assertNull(pmd);
     }
 }

Added: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java?rev=1689592&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
(added)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
Tue Jul  7 08:02:09 2015
@@ -0,0 +1,94 @@
+/*  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.transaction.itests;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.UserTransaction;
+import java.sql.SQLException;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class MandatoryAnnotatedTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testMandatory() throws Exception {
+	  String prefix = "MTAT";
+      TestBean bean = context().getService(TestBean.class, "(tranAttribute=MandatoryAnnotated)");
+      UserTransaction tran = context().getService(UserTransaction.class);
+      
+      //Test with client transaction - the user transaction is used to insert a row
+      int initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow(prefix + "testWithClientTran", 1);
+      tran.commit();
+      
+      int finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+  
+      //Test with client transaction and application exception - the user transaction is
not rolled back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow(prefix + "testWithClientTranAndWithAppException", 1);
+      
+      try {
+          bean.insertRow(prefix + "testWithClientTranAndWithAppException", 2, new SQLException("Dummy
exception"));
+      } catch (SQLException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 2);
+      
+      //Test with client transaction and runtime exception - the user transaction is rolled
back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow(prefix + "testWithClientTranAndWithRuntimeException", 1);
+      
+      try {
+          bean.insertRow(prefix + "testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy
exception"));
+      } catch (RuntimeException e) {
+          e.printStackTrace();
+      }
+      
+      try {
+          tran.commit();
+          fail("RollbackException not thrown");
+      } catch (RollbackException e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+      
+      //Test without client transaction - an exception is thrown because a transaction is
mandatory
+      try {
+          bean.insertRow(prefix + "testWithoutClientTran", 1);
+          fail("IllegalStateException not thrown");
+      } catch (IllegalStateException e) {
+          e.printStackTrace();
+      }
+  }
+}

Modified: aries/trunk/transaction/transaction-testbundle/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-testbundle/pom.xml?rev=1689592&r1=1689591&r2=1689592&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-testbundle/pom.xml (original)
+++ aries/trunk/transaction/transaction-testbundle/pom.xml Tue Jul  7 08:02:09 2015
@@ -51,4 +51,13 @@
         </aries.osgi.private.pkg>
     </properties>
 
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.aries.transaction</groupId>
+            <artifactId>org.apache.aries.transaction.blueprint</artifactId>
+            <scope>provided</scope>
+            <version>1.0.3-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
 </project>

Added: aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/AnnotatedTestBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/AnnotatedTestBeanImpl.java?rev=1689592&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/AnnotatedTestBeanImpl.java
(added)
+++ aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/AnnotatedTestBeanImpl.java
Tue Jul  7 08:02:09 2015
@@ -0,0 +1,36 @@
+package org.apache.aries.transaction.test.impl;
+
+import org.apache.aries.transaction.annotations.Transaction;
+import org.apache.aries.transaction.annotations.TransactionPropagationType;
+
+import java.sql.SQLException;
+
+/**
+ * Created by Maxim Becker on 31.05.15.
+ */
+public class AnnotatedTestBeanImpl extends TestBeanImpl {
+
+    @Override
+    @Transaction(TransactionPropagationType.Mandatory)
+    public void insertRow(String name, int value) throws SQLException {
+        super.insertRow(name, value);
+    }
+
+    @Override
+    @Transaction(TransactionPropagationType.Mandatory)
+    public void insertRow(String name, int value, Exception e) throws SQLException {
+        super.insertRow(name, value, e);
+    }
+
+    @Override
+    @Transaction(TransactionPropagationType.Mandatory)
+    public void insertRow(String name, int value, boolean delegate) throws SQLException {
+        super.insertRow(name, value, delegate);
+    }
+
+    @Override
+    @Transaction(TransactionPropagationType.NotSupported)
+    public int countRows() throws SQLException {
+        return super.countRows();
+    }
+}

Modified: aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1689592&r1=1689591&r2=1689592&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
Tue Jul  7 08:02:09 2015
@@ -20,9 +20,11 @@
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
+           xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.2.0"
            default-activation="lazy">
 
+   <tx:enable-annotations/>
+
    <bean id="notSupportedBeanImpl" class="org.apache.aries.transaction.test.impl.TestBeanImpl"
init-method="initialize">
        <tx:transaction method="*" value="NotSupported"/>
        <property name="enlistingDataSource" ref="enlistingDataSource"/>
@@ -122,7 +124,20 @@
        <property name="user" value="user"/>
        <property name="password" value="password"/>
    </bean>
-   
+
+   <bean id="mandatoryAnnotatedBeanImpl" class="org.apache.aries.transaction.test.impl.AnnotatedTestBeanImpl"
init-method="initialize">
+       <property name="enlistingDataSource" ref="enlistingDataSource"/>
+       <property name="dataSource" ref="dataSource"/>
+       <property name="user" value="user"/>
+       <property name="password" value="password"/>
+   </bean>
+
+   <service id="mandatoryAnnotatedBean" ref="mandatoryAnnotatedBeanImpl" interface="org.apache.aries.transaction.test.TestBean">
+       <service-properties>
+           <entry key="tranAttribute" value="MandatoryAnnotated"/>
+       </service-properties>
+   </service>
+
    <service id="invalidBean" ref="invalidBeanImpl" interface="org.apache.aries.transaction.test.TestBean">
        <service-properties>
            <entry key="tranAttribute" value="Invalid"/>



Mime
View raw message