aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1738185 - in /aries/trunk/jpa: itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/ itests/jpa-container-testbundle/src/main/resources/META-INF/ jpa-container/src/main/java/org/apache/aries/jpa/container/impl/ jpa...
Date Thu, 07 Apr 2016 20:10:11 GMT
Author: timothyjward
Date: Thu Apr  7 20:10:11 2016
New Revision: 1738185

URL: http://svn.apache.org/viewvc?rev=1738185&view=rev
Log:
[ARIES-1524] Allow the EntityManagerFactoryBuilder to override the persistence unit's transaction
type

Modified:
    aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
    aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java

Modified: aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java?rev=1738185&r1=1738184&r2=1738185&view=diff
==============================================================================
--- aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
(original)
+++ aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
Thu Apr  7 20:10:11 2016
@@ -15,6 +15,8 @@
  */
 package org.apache.aries.jpa.container.itest;
 
+import static javax.persistence.spi.PersistenceUnitTransactionType.JTA;
+import static javax.persistence.spi.PersistenceUnitTransactionType.RESOURCE_LOCAL;
 import static org.junit.Assert.assertEquals;
 import static org.osgi.service.jdbc.DataSourceFactory.OSGI_JDBC_DRIVER_CLASS;
 
@@ -28,6 +30,7 @@ import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Query;
 import javax.persistence.TypedQuery;
+import javax.sql.DataSource;
 
 import org.apache.aries.jpa.container.itest.entities.Car;
 import org.apache.aries.jpa.itest.AbstractCarJPAITest;
@@ -156,8 +159,34 @@ public abstract class JPAContainerTest e
     	
     	Map<String, Object> props = new HashMap<String, Object>();
     	props.put("javax.persistence.nonJtaDataSource", dsf.createDataSource(jdbcProps));
+    	props.put("javax.persistence.transactionType", RESOURCE_LOCAL.name());
     	
     	EntityManagerFactory emf = emfBuilder.createEntityManagerFactory(props);
     	carLifecycleRL(emf.createEntityManager());
     }
+
+    @Test
+    public void testCarEMFBuilderExternalDSXA() throws Exception {
+    	DataSource ds = getService(DataSource.class, 
+    			"(" + OSGI_JDBC_DRIVER_CLASS + "=org.apache.derby.jdbc.EmbeddedDriver-pool-xa)");
+    	
+    	EntityManagerFactoryBuilder emfBuilder = getService(EntityManagerFactoryBuilder.class,
+    			"(osgi.unit.name=" + EXTERNAL_TEST_UNIT + ")");
+    	
+    	
+    	Map<String, Object> props = new HashMap<String, Object>();
+    	props.put("javax.persistence.jtaDataSource", ds);
+    	props.put("javax.persistence.transactionType", JTA.name());
+    	
+    	//EclipseLink also needs a non-jta-datasource
+    	DataSourceFactory dsf = getService(DataSourceFactory.class, 
+    			"(" + OSGI_JDBC_DRIVER_CLASS + "=org.apache.derby.jdbc.EmbeddedDriver)");
+    	Properties jdbcProps = new Properties();
+    	jdbcProps.setProperty("url", "jdbc:derby:memory:TEST1;create=true");
+    	props.put("javax.persistence.nonJtaDataSource", dsf.createDataSource(jdbcProps));
+
+    	
+    	EntityManagerFactory emf = emfBuilder.createEntityManagerFactory(props);
+    	carLifecycleXA(ut, emf.createEntityManager());
+    }
 }

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=1738185&r1=1738184&r2=1738185&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
Thu Apr  7 20:10:11 2016
@@ -87,7 +87,7 @@
     </properties>
   </persistence-unit>
   
-  <persistence-unit name="external-test-unit" transaction-type="RESOURCE_LOCAL">
+  <persistence-unit name="external-test-unit">
     <description>Test persistence unit for the JPA Container External DataSource iTests</description>
     <properties>
         <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java?rev=1738185&r1=1738184&r2=1738185&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java
Thu Apr  7 20:10:11 2016
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitTransactionType;
 import javax.sql.DataSource;
 
 import org.apache.aries.jpa.container.parser.impl.PersistenceUnit;
@@ -37,6 +38,7 @@ public class AriesEntityManagerFactoryBu
     private static final String JAVAX_PERSISTENCE_JDBC_DRIVER = "javax.persistence.jdbc.driver";
     private static final String JAVAX_PERSISTENCE_JTA_DATASOURCE = "javax.persistence.jtaDataSource";
     private static final String JAVAX_PERSISTENCE_NON_JTA_DATASOURCE = "javax.persistence.nonJtaDataSource";
+    private static final String JAVAX_PERSISTENCE_TX_TYPE = "javax.persistence.transactionType";
 
     private PersistenceProvider provider;
     private PersistenceUnit persistenceUnit;
@@ -75,6 +77,14 @@ public class AriesEntityManagerFactoryBu
         	props.remove(JAVAX_PERSISTENCE_NON_JTA_DATASOURCE);
         }
         
+        o = props.get(JAVAX_PERSISTENCE_TX_TYPE);
+        if(o instanceof PersistenceUnitTransactionType) {
+        	persistenceUnit.setTransactionType((PersistenceUnitTransactionType) o);
+        } else if (o instanceof String) {
+        	persistenceUnit.setTransactionType(
+        			PersistenceUnitTransactionType.valueOf((String) o));
+        }
+        
         return provider.createContainerEntityManagerFactory(persistenceUnit, props);
     }
 

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java?rev=1738185&r1=1738184&r2=1738185&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/PersistenceUnit.java
Thu Apr  7 20:10:11 2016
@@ -221,4 +221,8 @@ public class PersistenceUnit implements
             }
         }
     }
+
+	public void setTransactionType(PersistenceUnitTransactionType transactionType) {
+		this.transactionType = transactionType;
+	}
 }



Mime
View raw message