aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggrzy...@apache.org
Subject [aries-jpa] 01/01: [ARIES-2050] EMSupplier selectes better TX-related coordination to store EM instance
Date Mon, 14 Jun 2021 07:32:22 GMT
This is an automated email from the ASF dual-hosted git repository.

ggrzybek pushed a commit to branch ARIES-2050
in repository https://gitbox.apache.org/repos/asf/aries-jpa.git

commit cc6409ffefa8e7e0f270c483a4cc1b4d5a518f03
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
AuthorDate: Mon Jun 14 09:31:20 2021 +0200

    [ARIES-2050] EMSupplier selectes better TX-related coordination to store EM instance
---
 .../osgi.bnd                                       | 18 +++++
 .../jpa-container-blueprint-testbundle-dao/pom.xml | 86 ++++++++++++++++++++++
 .../container/itest/bundle/blueprint/CarDao.java   | 31 ++++++++
 .../itest/bundle/blueprint/NewTxTestService.java   | 27 +++++++
 .../itest/bundle/blueprint/TestService.java        | 25 +++++++
 .../itest/bundle/blueprint/dao/CarDaoImpl.java     | 45 +++++++++++
 .../blueprint/impl/NewTxTestServiceImpl.java       | 58 +++++++++++++++
 .../bundle/blueprint/impl/TestServiceImpl.java     | 72 ++++++++++++++++++
 .../main/resources/OSGI-INF/blueprint/config.xml   | 48 ++++++++++++
 itests/jpa-container-itest/pom.xml                 |  6 ++
 .../blueprint/aries/itest/BlueprintDaoTest.java    | 48 ++++++++++++
 .../apache/aries/jpa/itest/AbstractJPAItest.java   |  4 +
 itests/pom.xml                                     |  1 +
 .../aries/jpa/support/impl/EMSupplierImpl.java     | 10 +++
 14 files changed, 479 insertions(+)

diff --git a/itests/jpa-container-blueprint-testbundle-dao/osgi.bnd b/itests/jpa-container-blueprint-testbundle-dao/osgi.bnd
new file mode 100644
index 0000000..13eb520
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/osgi.bnd
@@ -0,0 +1,18 @@
+#    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.
+
+-contract: JavaJPA
\ No newline at end of file
diff --git a/itests/jpa-container-blueprint-testbundle-dao/pom.xml b/itests/jpa-container-blueprint-testbundle-dao/pom.xml
new file mode 100644
index 0000000..d4028d9
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/pom.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.aries.jpa.itest</groupId>
+        <artifactId>org.apache.aries.jpa.itest.parent</artifactId>
+        <version>2.7.3-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.aries.jpa.container.itest.bundle.blueprint.dao</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Aries JPA test bundle blueprint integration 2</name>
+    <description>Testing blueprint integration with EntityManager, EntityManagerFactory
and EmSupplier injection.
+Also testing declarative transactions with REQUIRES_NEW behavior</description>
+
+    <properties>
+        <baseline.skip>true</baseline.skip>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.transaction</groupId>
+            <artifactId>javax.transaction-api</artifactId>
+            <version>1.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.interceptor</groupId>
+            <artifactId>javax.interceptor-api</artifactId>
+            <version>1.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jpa_2.0_spec</artifactId>
+            <version>1.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.jpa.javax.persistence</groupId>
+            <artifactId>javax.persistence_2.0</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.jpa</groupId>
+            <artifactId>org.apache.aries.jpa.api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.jpa</groupId>
+            <artifactId>org.apache.aries.jpa.container.itest.bundle</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/CarDao.java
b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/CarDao.java
new file mode 100644
index 0000000..696a897
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/CarDao.java
@@ -0,0 +1,31 @@
+/*
+ * 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 WARRANTIESOR 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.jpa.container.itest.bundle.blueprint;
+
+import java.util.List;
+
+import org.apache.aries.jpa.container.itest.entities.Car;
+
+public interface CarDao {
+
+    void createNew(Car car);
+
+    List<Car> getAllCars();
+
+}
diff --git a/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/NewTxTestService.java
b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/NewTxTestService.java
new file mode 100644
index 0000000..8711257
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/NewTxTestService.java
@@ -0,0 +1,27 @@
+/*
+ * 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 WARRANTIESOR 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.jpa.container.itest.bundle.blueprint;
+
+import javax.transaction.Transaction;
+
+public interface NewTxTestService {
+
+    void testNewTransaction(Transaction previousTransaction) throws Exception;
+
+}
diff --git a/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/TestService.java
b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/TestService.java
new file mode 100644
index 0000000..4ce7c34
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/TestService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 WARRANTIESOR 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.jpa.container.itest.bundle.blueprint;
+
+public interface TestService {
+
+    void performTest() throws Exception;
+
+}
diff --git a/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/dao/CarDaoImpl.java
b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/dao/CarDaoImpl.java
new file mode 100644
index 0000000..24665c2
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/dao/CarDaoImpl.java
@@ -0,0 +1,45 @@
+/*
+ * 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 WARRANTIESOR 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.jpa.container.itest.bundle.blueprint.dao;
+
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.TypedQuery;
+
+import org.apache.aries.jpa.container.itest.bundle.blueprint.CarDao;
+import org.apache.aries.jpa.container.itest.entities.Car;
+
+public class CarDaoImpl implements CarDao {
+
+    @PersistenceContext(unitName = "xa-test-unit")
+    protected EntityManager em;
+
+    @Override
+    public void createNew(Car car) {
+        em.persist(car);
+    }
+
+    @Override
+    public List<Car> getAllCars() {
+        TypedQuery<Car> query = em.createQuery("select c from Car c", Car.class);
+        return query.getResultList();
+    }
+
+}
diff --git a/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/NewTxTestServiceImpl.java
b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/NewTxTestServiceImpl.java
new file mode 100644
index 0000000..fd8e6f1
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/NewTxTestServiceImpl.java
@@ -0,0 +1,58 @@
+/*
+ * 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 WARRANTIESOR 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.jpa.container.itest.bundle.blueprint.impl;
+
+import java.util.List;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.Transactional;
+import javax.transaction.Transactional.TxType;
+
+import org.apache.aries.jpa.container.itest.bundle.blueprint.CarDao;
+import org.apache.aries.jpa.container.itest.bundle.blueprint.NewTxTestService;
+import org.apache.aries.jpa.container.itest.entities.Car;
+
+public class NewTxTestServiceImpl implements NewTxTestService {
+
+    private CarDao carDao;
+
+    private TransactionManager transactionManager;
+
+    public void setCarDao(CarDao carDao) {
+        this.carDao = carDao;
+    }
+
+    public void setTransactionManager(TransactionManager transactionManager) {
+        this.transactionManager = transactionManager;
+    }
+
+    @Override
+    @Transactional(TxType.REQUIRES_NEW)
+    public void testNewTransaction(Transaction previousTransaction) throws Exception {
+        if (previousTransaction == transactionManager.getTransaction()) {
+            throw new RuntimeException("No new transaction created for TxType.REQUIRES_NEW");
+        }
+
+        List<Car> cars = carDao.getAllCars();
+        if (cars.size() != 0) {
+            throw new RuntimeException("EntityManager query executed in suspended transaction!");
+        }
+    }
+
+}
diff --git a/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/TestServiceImpl.java
b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/TestServiceImpl.java
new file mode 100644
index 0000000..09fea86
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/TestServiceImpl.java
@@ -0,0 +1,72 @@
+/*
+ * 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 WARRANTIESOR 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.jpa.container.itest.bundle.blueprint.impl;
+
+import java.util.List;
+import javax.transaction.TransactionManager;
+import javax.transaction.Transactional;
+import javax.transaction.Transactional.TxType;
+
+import org.apache.aries.jpa.container.itest.bundle.blueprint.CarDao;
+import org.apache.aries.jpa.container.itest.bundle.blueprint.NewTxTestService;
+import org.apache.aries.jpa.container.itest.bundle.blueprint.TestService;
+import org.apache.aries.jpa.container.itest.entities.Car;
+
+public class TestServiceImpl implements TestService {
+
+    private CarDao carDao;
+    private NewTxTestService newTxTestService;
+
+    private TransactionManager transactionManager;
+
+    public void setCarDao(CarDao carDao) {
+        this.carDao = carDao;
+    }
+
+    public void setNewTxTestService(NewTxTestService newTxTestService) {
+        this.newTxTestService = newTxTestService;
+    }
+
+    public void setTransactionManager(TransactionManager transactionManager) {
+        this.transactionManager = transactionManager;
+    }
+
+    @Override
+    @Transactional(TxType.REQUIRED)
+    public void performTest() throws Exception {
+        try {
+            List<Car> cars = carDao.getAllCars();
+            if (cars.size() != 0) {
+                throw new RuntimeException("Database must be cleaned before executing the
test!");
+            }
+
+            Car car = new Car();
+            car.setNumberOfSeats(4);
+            car.setEngineSize(42);
+            car.setNumberPlate("WWW-xxxx");
+            car.setColour("blue");
+            carDao.createNew(car);
+
+            newTxTestService.testNewTransaction(transactionManager.getTransaction());
+        } finally {
+            transactionManager.setRollbackOnly();
+        }
+    }
+
+}
diff --git a/itests/jpa-container-blueprint-testbundle-dao/src/main/resources/OSGI-INF/blueprint/config.xml
b/itests/jpa-container-blueprint-testbundle-dao/src/main/resources/OSGI-INF/blueprint/config.xml
new file mode 100644
index 0000000..f0e31cc
--- /dev/null
+++ b/itests/jpa-container-blueprint-testbundle-dao/src/main/resources/OSGI-INF/blueprint/config.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+        xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0"
+        xmlns:tx="http://aries.apache.org/xmlns/transactions/v2.0.0"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+    <jpa:enable />
+    <tx:enable />
+
+    <reference id="transactionManager" interface="javax.transaction.TransactionManager"
/>
+
+    <bean id="carDao" class="org.apache.aries.jpa.container.itest.bundle.blueprint.dao.CarDaoImpl"
/>
+
+    <bean id="testService" class="org.apache.aries.jpa.container.itest.bundle.blueprint.impl.TestServiceImpl">
+        <property name="carDao" ref="carDao" />
+        <property name="transactionManager" ref="transactionManager" />
+        <property name="newTxTestService" ref="newTxTestService" />
+    </bean>
+
+    <bean id="newTxTestService" class="org.apache.aries.jpa.container.itest.bundle.blueprint.impl.NewTxTestServiceImpl">
+        <property name="carDao" ref="carDao" />
+        <property name="transactionManager" ref="transactionManager" />
+    </bean>
+
+    <service ref="testService" interface="org.apache.aries.jpa.container.itest.bundle.blueprint.TestService"
/>
+
+    <service ref="newTxTestService" interface="org.apache.aries.jpa.container.itest.bundle.blueprint.NewTxTestService"
/>
+
+</blueprint>
diff --git a/itests/jpa-container-itest/pom.xml b/itests/jpa-container-itest/pom.xml
index 095956d..3601be3 100644
--- a/itests/jpa-container-itest/pom.xml
+++ b/itests/jpa-container-itest/pom.xml
@@ -283,6 +283,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.jpa.itest</groupId>
+            <artifactId>org.apache.aries.jpa.container.itest.bundle.blueprint.dao</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.aries.jpa</groupId>
             <artifactId>org.apache.aries.jpa.container.itest.bundle.eclipselink</artifactId>
             <version>${project.version}</version>
diff --git a/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintDaoTest.java
b/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintDaoTest.java
new file mode 100644
index 0000000..680ab6c
--- /dev/null
+++ b/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintDaoTest.java
@@ -0,0 +1,48 @@
+/*  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.jpa.blueprint.aries.itest;
+
+import org.apache.aries.jpa.container.itest.bundle.blueprint.TestService;
+import org.apache.aries.jpa.itest.AbstractJPAItest;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+
+public class BlueprintDaoTest extends AbstractJPAItest {
+
+    @Test
+    public void testNestedTransactionsWithIsolatedEntityManagers() throws Exception {
+        TestService testService = getService(TestService.class, null);
+        testService.performTest();
+    }
+
+    @Configuration
+    public Option[] configuration() {
+        return new Option[] {
+                baseOptions(), //
+                jta12Bundles(), //
+                ariesJpa20(), //
+                hibernate(), //
+                derbyDSF(), //
+                testBundle(), //
+                testBundleBlueprintDao(),
+                mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.blueprint",
"2.2.0"),
+//                 debug()
+        };
+    }
+}
diff --git a/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
b/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
index c0a2692..8d636a6 100644
--- a/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
+++ b/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
@@ -327,6 +327,10 @@ public abstract class AbstractJPAItest {
         return mvnBundle("org.apache.aries.jpa.itest", "org.apache.aries.jpa.container.itest.bundle.blueprint");
     }
 
+    protected Option testBundleBlueprintDao() {
+        return mvnBundle("org.apache.aries.jpa.itest", "org.apache.aries.jpa.container.itest.bundle.blueprint.dao");
+    }
+
     protected MavenArtifactProvisionOption testBundleEclipseLink() {
         return mvnBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container.itest.bundle.eclipselink");
     }
diff --git a/itests/pom.xml b/itests/pom.xml
index b1ea0f7..ca76042 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -50,6 +50,7 @@
 
     <modules>
         <module>jpa-container-blueprint-testbundle</module>
+        <module>jpa-container-blueprint-testbundle-dao</module>
         <module>jpa-container-itest</module>
         <module>jpa-container-itest-karaf</module>
         <module>jpa-container-testbundle</module>
diff --git a/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java
b/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java
index e338659..199de93 100644
--- a/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java
+++ b/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java
@@ -128,9 +128,19 @@ public class EMSupplierImpl implements EmSupplier {
     }
 
     Coordination getTopCoordination() {
+        // In normal situation, There should be TxInterceptor and JpaInterceptor
         Coordination coordination = coordinator.peek();
         while (coordination != null && coordination.getEnclosingCoordination() !=
null) {
             coordination = coordination.getEnclosingCoordination();
+            if (coordination != null) {
+                String transaction = (String) coordination.getVariables().get(Transaction.class);
+                if (transaction != null) {
+                    // ARIES-2050: transaction-blueprint doesn't always create new coordination
(for example
+                    // when calling REQUIRED -> REQUIRED annotated methods. And we can
assume the "new" behavior
+                    // when the Transaction.class attribute is not null (it matches one of
the 6 TX behaviors)
+                    return coordination;
+                }
+            }
         }
         return coordination;
     }

Mime
View raw message