Copied: 
aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/CarService.java
 (from r1691025, 
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/itest/testbundle/service/CarService.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/CarService.java?p2=aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/CarService.java&p1=aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/itest/testbundle/service/CarService.java&r1=1691025&r2=1691026&rev=1691026&view=diff
==============================================================================
--- 
aries/trunk/jpa/itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/itest/testbundle/service/CarService.java
 (original)
+++ 
aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/CarService.java
 Tue Jul 14 16:20:10 2015
@@ -16,12 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.jpa.itest.testbundle.service;
+package org.apache.aries.jpa.container.itest.entities;
 
 import java.util.Collection;
 
-import org.apache.aries.jpa.itest.testbundle.entities.Car;
-
 public interface CarService {
     Car getCar(String id);
 

Modified: 
aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml?rev=1691026&r1=1691025&r2=1691026&view=diff
==============================================================================
--- 
aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
 (original)
+++ 
aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
 Tue Jul 14 16:20:10 2015
@@ -39,6 +39,27 @@
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
     </properties>
   </persistence-unit>
+  
+   <persistence-unit name="xa-test-unit" transaction-type="JTA">
+        <description>Test persistence unit for the JPA Container advanced 
iTests</description>
+        <properties>
+            <property name="javax.persistence.jdbc.driver"
+                value="org.apache.derby.jdbc.EmbeddedDriver-pool-xa" />
+            <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:memory:TEST;create=true" />
+
+            <!-- These properties are creating the database on the fly. We 
+                are using them to avoid the tests having to create a database 
-->
+
+            <property name="openjpa.jdbc.SynchronizeMappings"
+                value="buildSchema(ForeignKeys=true)" />
+            <property name="openjpa.jdbc.DBDictionary" value="derby" />
+
+            <property name="eclipselink.ddl-generation" 
value="drop-and-create-tables"/>
+            <property name="hibernate.dialect"
+                value="org.hibernate.dialect.DerbyTenSevenDialect" />
+    <!--         <property name="hibernate.hbm2ddl.auto" value="create-drop" 
/> -->
+        </properties>
+    </persistence-unit>
 
   <persistence-unit name="dsf-test-unit" transaction-type="RESOURCE_LOCAL">
     <description>Test persistence unit for the JPA Container DataSourceFactory 
iTests</description>
@@ -46,7 +67,7 @@
         <!-- These properties are creating the database on the fly. We are 
using them to avoid the tests having
           to create a database  -->
         <property name="javax.persistence.jdbc.driver" 
value="org.apache.derby.jdbc.EmbeddedDriver"/>
-        <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:memory:TEST;create=true"/>
+        <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:memory:TEST2;create=true"/>
         <property name="openjpa.jdbc.SynchronizeMappings" 
value="buildSchema(ForeignKeys=true)"/>
         <property name="openjpa.jdbc.DBDictionary" value="derby"/>
         <property name="hibernate.dialect" 
value="org.hibernate.dialect.DerbyTenSevenDialect"/>
@@ -60,11 +81,33 @@
      <!-- These properties are creating the database on the fly. We are using 
them to avoid the tests having
           to create a database  -->
         <property name="javax.persistence.jdbc.driver" 
value="org.apache.derby.jdbc.EmbeddedDriver-pool-xa"/>
-        <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:memory:TEST;create=true"/>
+        <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:memory:TEST3;create=true"/>
         <property name="openjpa.jdbc.SynchronizeMappings" 
value="buildSchema(ForeignKeys=true)"/>
         <property name="openjpa.jdbc.DBDictionary" value="derby"/>
         <property name="hibernate.dialect" 
value="org.hibernate.dialect.DerbyTenSevenDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
     </properties>
   </persistence-unit>
+  
+    <persistence-unit name="test_unit_blueprint" transaction-type="JTA">
+        <description>Test persistence unit for the Blueprint test</description>
+
+        <properties>
+            <property name="javax.persistence.jdbc.driver"
+                value="org.apache.derby.jdbc.EmbeddedDriver-pool-xa" />
+            <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:memory:TESTBLUEPRINT;create=true" />
+
+            <!-- These properties are creating the database on the fly. We 
+                are using them to avoid the tests having to create a database 
-->
+
+            <property name="openjpa.jdbc.SynchronizeMappings"
+                value="buildSchema(ForeignKeys=true)" />
+            <property name="openjpa.jdbc.DBDictionary" value="derby" />
+
+            <property name="eclipselink.ddl-generation" 
value="drop-and-create-tables"/>
+            <property name="hibernate.dialect"
+                value="org.hibernate.dialect.DerbyTenSevenDialect" />
+            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
+        </properties>
+    </persistence-unit>
 </persistence>

Modified: 
aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java?rev=1691026&r1=1691025&r2=1691026&view=diff
==============================================================================
--- 
aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java
 (original)
+++ 
aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java
 Tue Jul 14 16:20:10 2015
@@ -26,8 +26,11 @@ import javax.persistence.spi.Persistence
 import org.apache.aries.blueprint.Interceptor;
 import org.apache.aries.jpa.supplier.EmSupplier;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class JpaInterceptor implements Interceptor {
+    private static Logger LOG = LoggerFactory.getLogger(JpaInterceptor.class);
     private EmSupplier emSupplier;
     private Boolean cachedIsResourceLocal;
 
@@ -50,21 +53,25 @@ public class JpaInterceptor implements I
             return weControlTx;
         } catch (Exception e) {
             e.printStackTrace();
-            return false;
+            throw new RuntimeException(e);
         }
     }
 
     public void postCallWithException(ComponentMetadata cm, Method m, 
Throwable ex, Object preCallToken) {
-        boolean weControlTx = (Boolean)preCallToken;
+        boolean weControlTx = preCallToken == null ? false : 
(Boolean)preCallToken;
         if (weControlTx) {
             safeRollback(emSupplier.get(), ex);
         }
-        emSupplier.postCall();
+        try {
+            emSupplier.postCall();
+        } catch (Exception e) {
+            LOG.warn("Exception from EmSupplier.postCall", e);
+        }
     }
 
     public void postCallWithReturn(ComponentMetadata cm, Method m, Object 
returnType, Object preCallToken)
         throws Exception {
-        boolean weControlTx = (Boolean)preCallToken;
+        boolean weControlTx = preCallToken == null ? false : 
(Boolean)preCallToken;
         if (weControlTx) {
             emSupplier.get().getTransaction().commit();
         }

Modified: 
aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java?rev=1691026&r1=1691025&r2=1691026&view=diff
==============================================================================
--- 
aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java
 (original)
+++ 
aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java
 Tue Jul 14 16:20:10 2015
@@ -42,6 +42,8 @@ import org.slf4j.LoggerFactory;
  * sure all EMs are closed.
  */
 public class EMSupplierImpl implements EmSupplier {
+
+
     private static final long DEFAULT_SHUTDOWN_WAIT_SECS = 10;
     private static Logger LOG = LoggerFactory.getLogger(EMSupplierImpl.class);
     private EntityManagerFactory emf;
@@ -74,28 +76,15 @@ public class EMSupplierImpl implements E
     @Override
     public EntityManager get() {
         Coordination coordination = getTopCoordination();
+        if (coordination == null) {
+            throw new IllegalStateException("Need active coordination");
+        }
         EntityManager em = getEm(coordination);
-        if (coordination != null && em == null) {
+        if (em == null) {
             em = createEm(emf);
             emSet.add(em);
             coordination.getVariables().put(EntityManager.class, em);
-            coordination.addParticipant(new Participant() {
-                
-                @Override
-                public void failed(Coordination coordination) throws Exception 
{
-                    ended(coordination);
-                }
-                
-                @Override
-                public void ended(Coordination coordination) throws Exception {
-                    EntityManager em = getEm(coordination);
-                    em.close();
-                    emSet.remove(em);
-                    if (shutdown.get()) {
-                        emsToShutDown.countDown();
-                    }
-                }
-            });
+            coordination.addParticipant(new EmShutDownParticipant());
         }
         return em;
     }
@@ -114,21 +103,20 @@ public class EMSupplierImpl implements E
      * @return
      */
     private EntityManager getEm(Coordination coordination) {
-        if (coordination == null) {
-            return null;
-        } else {
-            return 
(EntityManager)coordination.getVariables().get(EntityManager.class);
-        }
+        return 
(EntityManager)coordination.getVariables().get(EntityManager.class);
     }
 
     @Override
     public void preCall() {
+        LOG.info("preCall");
         coordinator.begin("jpa", 0);
     }
 
     @Override
     public void postCall() {
-        coordinator.pop().end();
+        LOG.info("postCall");
+        Coordination coord = coordinator.pop();
+        coord.end();
     }
 
     /**
@@ -176,4 +164,20 @@ public class EMSupplierImpl implements E
         this.shutdownWaitTimeUnit = shutdownWaitTimeUnit;
     }
 
+    private final class EmShutDownParticipant implements Participant {
+        @Override
+        public void failed(Coordination coordination) throws Exception {
+            ended(coordination);
+        }
+
+        @Override
+        public void ended(Coordination coordination) throws Exception {
+            EntityManager em = getEm(coordination);
+            emSet.remove(em);
+            em.close();
+            if (shutdown.get()) {
+                emsToShutDown.countDown();
+            }
+        }
+    }
 }

Modified: 
aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/impl/EmSupplierTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/impl/EmSupplierTest.java?rev=1691026&r1=1691025&r2=1691026&view=diff
==============================================================================
--- 
aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/impl/EmSupplierTest.java
 (original)
+++ 
aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/impl/EmSupplierTest.java
 Tue Jul 14 16:20:10 2015
@@ -40,8 +40,7 @@ public class EmSupplierTest {
         EntityManagerFactory emf = mockEmf();
         Coordinator coordinator = new DummyCoordinator();
         EMSupplierImpl emSupplier = new EMSupplierImpl(emf, coordinator );
-        
-        Assert.assertNull("No EM may be present at start", emSupplier.get());
+        assertIllegalState(emSupplier);
 
         emSupplier.preCall();
         EntityManager em = emSupplier.get();
@@ -53,12 +52,22 @@ public class EmSupplierTest {
         Assert.assertSame("EM must still be the same after inner postCall", 
em, emSupplier.get());
         
         emSupplier.postCall();
-        Assert.assertNull("EM must be null after outer postCall", 
emSupplier.get());
+        assertIllegalState(emSupplier);
         
         boolean clean = emSupplier.close();
         Assert.assertTrue("Shutdown should be clean", clean);
     }
 
+
+    private void assertIllegalState(EMSupplierImpl emSupplier) {
+        try {
+            emSupplier.get();
+            Assert.fail(IllegalStateException.class + " expected");
+        } catch (IllegalStateException e) {
+            // Expected
+        }
+    }
+
     
     @Test
     public void uncleanLifeCycleTest() {


Reply via email to