Author: timothyjward
Date: Mon Apr 11 19:36:03 2016
New Revision: 1738630

URL: http://svn.apache.org/viewvc?rev=1738630&view=rev
Log:
[tx-control] Add XA support for JPA using Hibernate

Added:
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XAConnectionWrapper.java
      - copied, changed from r1738126, 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAConnectionWrapper.java
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XADataSourceMapper.java
      - copied, changed from r1738126, 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XADataSourceMapper.java
    aries/trunk/tx-control/tx-control-provider-jpa-xa/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/.gitignore
    aries/trunk/tx-control/tx-control-provider-jpa-xa/LICENSE
    aries/trunk/tx-control/tx-control-provider-jpa-xa/NOTICE
    aries/trunk/tx-control/tx-control-provider-jpa-xa/README.md
    aries/trunk/tx-control/tx-control-provider-jpa-xa/pom.xml
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/EntityManagerWrapper.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ScopedEntityManagerWrapper.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/TxEntityManagerWrapper.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/eclipse/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/eclipse/impl/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/eclipse/impl/EclipseTxControlPlatform.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/hibernate/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/hibernate/impl/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/hibernate/impl/HibernateTxControlPlatform.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/Activator.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/DelayedJPAEntityManagerProvider.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderImpl.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/LifecycleAware.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/ManagedJPADataSourceSetup.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/ManagedJPAEMFLocator.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/ManagedServiceFactoryImpl.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/XAEnabledTxContextBindingConnection.java
      - copied, changed from r1738126, 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnection.java
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManager.java
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/impl/
    
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManagerTest.java
Removed:
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAConnectionWrapper.java
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XADataSourceMapper.java
Modified:
    
aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jpa/JPAEntityManagerProviderFactory.java
    aries/trunk/tx-control/tx-control-jpa-itests/pom.xml
    
aries/trunk/tx-control/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractJPATransactionTest.java
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderFactoryImpl.java
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnection.java
    
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/test/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnectionTest.java
    
aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderFactoryImpl.java

Modified: 
aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jpa/JPAEntityManagerProviderFactory.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jpa/JPAEntityManagerProviderFactory.java?rev=1738630&r1=1738629&r2=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jpa/JPAEntityManagerProviderFactory.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jpa/JPAEntityManagerProviderFactory.java
 Mon Apr 11 19:36:03 2016
@@ -50,6 +50,12 @@ public interface JPAEntityManagerProvide
         * javax.persistence.jtaDataSource property
         */
        public static final String      TRANSACTIONAL_DB_CONNECTION     = 
"osgi.jdbc.provider";
+       
+       /**
+        * The property used to indicate that database connections will be 
automatically
+        * enlisted in ongoing transactions without intervention from the JPA 
provider
+        */
+       public static final String  PRE_ENLISTED_DB_CONNECTION = 
"osgi.jdbc.enlisted";
 
        /**
         * Create a private {@link JPAEntityManagerProvider} using an
@@ -74,16 +80,12 @@ public interface JPAEntityManagerProvide
         * {@link EntityManagerFactory}.
         * 
         * @param emf
-        * @param jpaProperties The properties to pass to the
-        *            {@link EntityManagerFactory} in order to create the 
underlying
-        *            {@link EntityManager} instances
         * @param resourceProviderProperties Configuration properties to pass 
to the
         *            JDBC Resource Provider runtime
         * @return A {@link JPAEntityManagerProvider} that can be used in
         *         transactions
         */
        JPAEntityManagerProvider getProviderFor(EntityManagerFactory emf,
-                       Map<String,Object> jpaProperties,
                        Map<String,Object> resourceProviderProperties);
 
 }

Modified: aries/trunk/tx-control/tx-control-jpa-itests/pom.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-jpa-itests/pom.xml?rev=1738630&r1=1738629&r2=1738630&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-jpa-itests/pom.xml (original)
+++ aries/trunk/tx-control/tx-control-jpa-itests/pom.xml Mon Apr 11 19:36:03 
2016
@@ -53,6 +53,12 @@
                        <version>0.0.1-SNAPSHOT</version>
                </dependency>
                <dependency>
+                       <groupId>org.apache.aries.tx-control</groupId>
+                       <artifactId>tx-control-service-xa</artifactId>
+                       <scope>test</scope>
+                       <version>0.0.1-SNAPSHOT</version>
+               </dependency>
+               <dependency>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>org.apache.felix.coordinator</artifactId>
                        <scope>test</scope>
@@ -70,6 +76,12 @@
                        <scope>test</scope>
                        <version>0.0.1-SNAPSHOT</version>
                </dependency>
+               <dependency>
+                       <groupId>org.apache.aries.tx-control</groupId>
+                       <artifactId>tx-control-provider-jpa-xa</artifactId>
+                       <scope>test</scope>
+                       <version>0.0.1-SNAPSHOT</version>
+               </dependency>
                <dependency>
             <groupId>org.eclipse.persistence</groupId>
             <artifactId>javax.persistence</artifactId>

Modified: 
aries/trunk/tx-control/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractJPATransactionTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractJPATransactionTest.java?rev=1738630&r1=1738629&r2=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractJPATransactionTest.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractJPATransactionTest.java
 Mon Apr 11 19:36:03 2016
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.tx.control.itests;
 
+import static java.lang.Boolean.getBoolean;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
@@ -54,7 +55,9 @@ import org.osgi.service.transaction.cont
 @ExamReactorStrategy(PerClass.class)
 public abstract class AbstractJPATransactionTest extends 
AbstractIntegrationTest {
 
+       protected static final String TX_CONTROL_FILTER = "tx.control.filter";
        protected static final String ARIES_EMF_BUILDER_TARGET_FILTER = 
"aries.emf.builder.target.filter";
+       protected static final String IS_XA = "aries.test.is.xa";
 
        protected TransactionControl txControl;
 
@@ -65,7 +68,7 @@ public abstract class AbstractJPATransac
        @Before
        public void setUp() throws Exception {
                
-               txControl = context().getService(TransactionControl.class, 
5000);
+               txControl = context().getService(TransactionControl.class, 
System.getProperty(TX_CONTROL_FILTER), 5000);
                
                server = Server.createTcpServer("-tcpPort", "0");
                server.start();
@@ -102,7 +105,8 @@ public abstract class AbstractJPATransac
                
                ConfigurationAdmin cm = 
context().getService(ConfigurationAdmin.class, 5000);
                
-               String pid = "org.apache.aries.tx.control.jpa.local"; 
+               String pid = getBoolean(IS_XA) ? 
"org.apache.aries.tx.control.jpa.xa" :
+                               "org.apache.aries.tx.control.jpa.local"; 
                
                System.out.println("Configuring connection provider with pid " 
+ pid);
                
@@ -180,22 +184,60 @@ public abstract class AbstractJPATransac
                                mavenBundle("org.ops4j.pax.logging", 
"pax-logging-api").versionAsInProject(),
                                mavenBundle("org.ops4j.pax.logging", 
"pax-logging-service").versionAsInProject()
                                
-                               
,CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
+//                             
,CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
+                               );
+       }
+
+       @Configuration
+       public Option[] xaTxConfiguration() {
+               String localRepo = System.getProperty("maven.repo.local");
+               if (localRepo == null) {
+                       localRepo = 
System.getProperty("org.ops4j.pax.url.mvn.localRepository");
+               }
+               
+               return options(junitBundles(), 
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+                               when(localRepo != null)
+                               
.useOptions(CoreOptions.vmOption("-Dorg.ops4j.pax.url.mvn.localRepository=" + 
localRepo)),
+                               mavenBundle("org.apache.aries.testsupport", 
"org.apache.aries.testsupport.unit").versionAsInProject(),
+                               
systemProperty(IS_XA).value(Boolean.TRUE.toString()),
+                               xaTxControlService(),
+                               xaJpaResourceProviderWithH2(),
+                               jpaProvider(),
+                               ariesJPA(),
+                               mavenBundle("org.apache.felix", 
"org.apache.felix.configadmin").versionAsInProject(),
+                               mavenBundle("org.ops4j.pax.logging", 
"pax-logging-api").versionAsInProject(),
+                               mavenBundle("org.ops4j.pax.logging", 
"pax-logging-service").versionAsInProject()
+                               
+//                             
,CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
                                );
        }
 
        public Option localTxControlService() {
                return CoreOptions.composite(
+                               
systemProperty(TX_CONTROL_FILTER).value("(osgi.local.enabled=true)"),
                                mavenBundle("org.apache.felix", 
"org.apache.felix.coordinator").versionAsInProject(),
                                mavenBundle("org.apache.aries.tx-control", 
"tx-control-service-local").versionAsInProject());
        }
 
+       public Option xaTxControlService() {
+               return CoreOptions.composite(
+                               
systemProperty(TX_CONTROL_FILTER).value("(osgi.xa.enabled=true)"),
+                               mavenBundle("org.apache.felix", 
"org.apache.felix.coordinator").versionAsInProject(),
+                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-service-xa").versionAsInProject());
+       }
+
        public Option localJpaResourceProviderWithH2() {
                return CoreOptions.composite(
                                mavenBundle("com.h2database", 
"h2").versionAsInProject(),
                                mavenBundle("org.apache.aries.tx-control", 
"tx-control-provider-jpa-local").versionAsInProject());
        }
        
+       public Option xaJpaResourceProviderWithH2() {
+               return CoreOptions.composite(
+                               mavenBundle("com.h2database", 
"h2").versionAsInProject(),
+                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-provider-jpa-xa").versionAsInProject());
+       }
+       
        public Option ariesJPA() {
                return mavenBundle("org.apache.aries.jpa", 
"org.apache.aries.jpa.container", ariesJPAVersion());
        }

Copied: 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XAConnectionWrapper.java
 (from r1738126, 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAConnectionWrapper.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XAConnectionWrapper.java?p2=aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XAConnectionWrapper.java&p1=aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAConnectionWrapper.java&r1=1738126&r2=1738630&rev=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAConnectionWrapper.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XAConnectionWrapper.java
 Mon Apr 11 19:36:03 2016
@@ -1,4 +1,4 @@
-package org.apache.aries.tx.control.jdbc.xa.impl;
+package org.apache.aries.tx.control.jdbc.xa.connection.impl;
 
 import java.sql.Connection;
 import java.sql.SQLException;

Copied: 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XADataSourceMapper.java
 (from r1738126, 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XADataSourceMapper.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XADataSourceMapper.java?p2=aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XADataSourceMapper.java&p1=aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XADataSourceMapper.java&r1=1738126&r2=1738630&rev=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XADataSourceMapper.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/connection/impl/XADataSourceMapper.java
 Mon Apr 11 19:36:03 2016
@@ -1,4 +1,4 @@
-package org.apache.aries.tx.control.jdbc.xa.impl;
+package org.apache.aries.tx.control.jdbc.xa.connection.impl;
 
 import java.io.PrintWriter;
 import java.sql.Connection;

Modified: 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderFactoryImpl.java?rev=1738630&r1=1738629&r2=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderFactoryImpl.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderFactoryImpl.java
 Mon Apr 11 19:36:03 2016
@@ -15,6 +15,7 @@ import javax.sql.DataSource;
 import javax.sql.XADataSource;
 
 import org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource;
+import org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper;
 import org.osgi.service.jdbc.DataSourceFactory;
 import org.osgi.service.transaction.control.TransactionException;
 import org.osgi.service.transaction.control.jdbc.JDBCConnectionProvider;

Modified: 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnection.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnection.java?rev=1738630&r1=1738629&r2=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnection.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnection.java
 Mon Apr 11 19:36:03 2016
@@ -12,6 +12,7 @@ import javax.transaction.xa.XAResource;
 import org.apache.aries.tx.control.jdbc.common.impl.ConnectionWrapper;
 import org.apache.aries.tx.control.jdbc.common.impl.ScopedConnectionWrapper;
 import org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper;
+import org.apache.aries.tx.control.jdbc.xa.connection.impl.XAConnectionWrapper;
 import org.osgi.service.transaction.control.LocalResource;
 import org.osgi.service.transaction.control.TransactionContext;
 import org.osgi.service.transaction.control.TransactionControl;

Modified: 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/test/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnectionTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/test/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnectionTest.java?rev=1738630&r1=1738629&r2=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/test/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnectionTest.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/test/java/org/apache/aries/tx/control/jdbc/xa/impl/XAEnabledTxContextBindingConnectionTest.java
 Mon Apr 11 19:36:03 2016
@@ -15,6 +15,7 @@ import javax.sql.XAConnection;
 import javax.sql.XADataSource;
 import javax.transaction.xa.XAResource;
 
+import org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;

Modified: 
aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderFactoryImpl.java?rev=1738630&r1=1738629&r2=1738630&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderFactoryImpl.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderFactoryImpl.java
 Mon Apr 11 19:36:03 2016
@@ -46,7 +46,7 @@ public class JPAEntityManagerProviderFac
        }
 
        @Override
-       public JPAEntityManagerProvider getProviderFor(EntityManagerFactory 
emf, Map<String, Object> jpaProperties,
+       public JPAEntityManagerProvider getProviderFor(EntityManagerFactory emf,
                        Map<String, Object> resourceProviderProperties) {
                checkEnlistment(resourceProviderProperties);
                validateEMF(emf);

Added: aries/trunk/tx-control/tx-control-provider-jpa-xa/.gitignore
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/.gitignore?rev=1738630&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/.gitignore (added)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/.gitignore Mon Apr 11 
19:36:03 2016
@@ -0,0 +1 @@
+/target/

Added: aries/trunk/tx-control/tx-control-provider-jpa-xa/LICENSE
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/LICENSE?rev=1738630&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/LICENSE (added)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/LICENSE Mon Apr 11 
19:36:03 2016
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Added: aries/trunk/tx-control/tx-control-provider-jpa-xa/NOTICE
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/NOTICE?rev=1738630&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/NOTICE (added)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/NOTICE Mon Apr 11 
19:36:03 2016
@@ -0,0 +1,8 @@
+
+Apache Aries
+Copyright 2009-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+

Added: aries/trunk/tx-control/tx-control-provider-jpa-xa/README.md
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/README.md?rev=1738630&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/README.md (added)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/README.md Mon Apr 11 
19:36:03 2016
@@ -0,0 +1,174 @@
+Sample OSGi Transaction Control JPA Provider (XA)
+-------------------------------------------------
+
+This module is a prototype implementation of the OSGi Transaction Control JPA 
resource provider. It supports JPA 2.1 using XA transactions, and is tested 
against Hibernate 5.0.9, EclipseLink 2.6.0 and OpenJPA 2.4.1.
+
+The Transaction Control Service (RFC-221) is an in-progress RFC publicly 
available from the OSGi Alliance: 
https://github.com/osgi/design/blob/master/rfcs/rfc0221/rfc-0221-TransactionControl.pdf
+
+Given that the RFC is non-final the OSGi API declared in this project is 
subject to change at any time up to its official release. Also the behaviour of 
this implementation may not always be up-to-date with the latest wording in the 
RFC. The project maintainers will, however try to keep pace with the RFC, and 
to ensure that the implementations are compliant with any OSGi specifications 
that result from the RFC.
+
+# When should I use this module?
+
+If two-phase commit is needed across multiple resources then it is best to 
pair this module with the tx-control-service-xa bundle.
+
+If you wish to use entirely lightweight, resource-local transactions then then 
the tx-control-service-local and tx-control-provider-jpa-local bundles should 
be used instead of this bundle
+
+# Using the JPA Provider bundle
+
+This Resource Provider is used in conjunction with a TransactionControl 
service to provide scoped access to a JPA EntityManager.
+
+## Prerequisites
+
+In order to use scoped JPA access the runtime must contain a JPA provider (for 
example Hibernate), an implementation of the OSGi JPA service (e.g. Aries JPA), 
and a persistence bundle.
+
+### Suitable Persistence bundles
+
+OSGi Persistence bundles contain the persistence descriptor (typically an XML 
file called META-INF/persistence.xml), all of the JPA Entities, and a 
Meta-Persistence header pointing at the persistence descriptor. (See the JPA 
service specification for more details).
+
+Unlike "normal" JPA it is usually best not to fully declare the persistence 
unit in the persistence descriptor. In particular it is a good idea to avoid 
putting any database configuration in the persistence unit. By not configuring 
the database inside the bundle the persistence unit remains decoupled, and can 
be reconfigured for any database at runtime.
+
+For example the following persistence unit:
+
+    <persistence-unit name="test-unit"/>
+
+can be reconfigured to use any database and create/drop tables as appropriate. 
Configuration for the persistence unit can be provided using Configuration 
Admin and the EntityManagerFactory Builder.
+
+
+## Creating a resource programmatically
+
+Preparing a resource for use is very simple. Create a JPAEntityManagerProvider 
using the the JPAEntityManagerProviderFactory, then connect the provider to a 
TransactionControl service. This will return a thread-safe JPA EntityManager 
that can then be used in any ongoing scoped work.
+
+The normal inputs to a JPAEntityManagerProviderFactory are an 
EntityManagerFactoryBuilder, some JPA properties to connect to the database 
with, and some properties to control the resource provider.
+
+    @Reference
+    TransactionControl txControl;
+
+    @Reference
+    DataSourceFactory dsf;
+
+    @Reference
+    EntityManagerFactoryBuilder emfb;
+
+    @Reference
+    JPAEntityManagerProviderFactory providerFactory;
+
+    EntityManager em;
+
+    @Activate
+    void start(Config config) {
+
+        Properties jdbcProps = new Properties();
+        jdbcProps.put(JDBC_URL, config.url());
+        jdbcProps.put(JDBC_USER, config.user());
+        jdbcProps.put(JDBC_PASSWORD, config._password());
+
+        Map<String, Object> jpaProps = new HashMap<>();
+        jpaProps.put("javax.persistence.nonJtaDataSource", 
+                    dsf.createDataSource(jdbcProps));
+
+        em = providerFactory.getProviderFor(emfb, jpaProps,
+                    null).getResource(txControl);
+    }
+
+    public void findUserName(String id) {
+        txControl.required(() -> {
+                // Use the EntityManager in here
+            });
+    } 
+
+If the JPA EntityManagerFactory is already configured then it can be passed 
into the JPAEntityManagerProviderFactory instead of an 
EntityManagerFactoryBuilder and JPA configuration.
+
+
+## Creating a resource using a factory configuration
+
+Whilst it is simple to use a EntityManagerFactoryBuilder it does require some 
lifecycle code to be written. It is therefore possible to directly create JPA 
resources using factory configurations. When created, the factory service will 
listen for an applicable EntityManagerFactoryBuilder and potentially also a 
DataSourceFactory. Once suitable services are available then a 
JPAEntityManagerProvider service will be published. 
+
+Configuration properties (except the JPA/JDBC password) are set as service 
properties for the registered JPAEntityManagerProvider. These properties may 
therefore be used in filters to select a particular provider.
+
+    @Reference
+    TransactionControl txControl;
+
+    @Reference(target="(osgi.unit.name=test-unit)")
+    JPAEntityManagerProvider provider;
+
+    EntityManager em;
+
+    @Activate
+    void start(Config config) {
+        em = provider.getResource(txControl);
+    }
+
+    public void findUserName(String id) {
+        txControl.required(() -> {
+                // Use the connection in here
+            });
+    } 
+
+
+
+The factory pid is _org.apache.aries.tx.control.jpa.local_ and it may use the 
following properties (all optional aside from *osgi.unit.name*):
+
+### Resource Provider properties
+
+* *osgi.unit.name* : The name of the persistence unit that this configuration 
relates to.
+
+* *aries.emf.builder.target.filter* : The target filter to use when searching 
for an EntityManagerFactoryBuilder. If not specified then any builder for the 
named persistence unit will be used.
+
+* *aries.jpa.property.names* : The names of the properties to pass to the 
EntityManagerFactoryBuilder when creating the EntityManagerFactory. By default 
all properties are copied.
+
+* *aries.dsf.target.filter* : The target filter to use when searching for a 
DataSourceFactory. If not specified then *osgi.jdbc.driver.class* must be 
specified.
+
+* *aries.jdbc.property.names* : The names of the properties to pass to the 
DataSourceFactory when creating the JDBC resources.
+
+* *osgi.jdbc.driver.class* : Used to locate the DataSourceFactory service if 
the *aries.dsf.target.filter* is not set.
+
+* *osgi.local.enabled* : Defaults to false. If true then resource creation 
will fail
+
+* *osgi.xa.enabled* : Defaults to true. If false then resource creation will 
fail
+
+* *osgi.connection.pooling.enabled* : Defaults to true. If true then the 
Database connections will be pooled.
+
+* *osgi.connection.max* : Defaults to 10. The maximum number of connections 
that should be kept in the pool
+
+* *osgi.connection.min* : Defaults to 10. The minimum number of connections 
that should be kept in the pool
+
+* *osgi.connection.timeout* : Defaults to 30,000 (30 seconds). The maximum 
time in milliseconds to block when waiting for a database connection
+
+* *osgi.idle.timeout* : Defaults to 180,000 (3 minutes). The time in 
milliseconds before an idle connection is eligible to be closed.
+
+* *osgi.connection.timeout* : Defaults to 10,800,000 (3 hours). The maximum 
time in milliseconds that a connection may remain open before being closed.
+
+
+### JDBC properties
+
+The following properties will automatically be passed to the DataSourceFactory 
if they are present. The list of properties may be overridden using the 
*aries.jdbc.property.names* property if necessary.
+
+* *databaseName* : The name of the database
+
+* *dataSourceName* : The name of the dataSource that will be created
+
+* *description* : A description of the dataSource being created
+
+* *networkProtocol* : The network protocol to use.
+
+* *portNumber* : The port number to use
+
+* *roleName* : The name of the JDBC role
+
+* *serverName* : The name of the database server
+
+* *url* : The JDBC url to use (often used instead of other properties such as 
*serverName*, *portNumber* and *databaseName*).
+
+* *user* : The JDBC user
+
+* *password* : The JDBC password
+
+
+### JPA properties
+
+The following properties are potentially useful when configuring JPA:
+
+*javax.persistence.schema-generation.database.action* : May be used to 
automatically create the database tables (see the OSGi spec)
+
+* Other provider specific properties, for example configuring second-level 
caching.
+

Added: aries/trunk/tx-control/tx-control-provider-jpa-xa/pom.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/pom.xml?rev=1738630&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/pom.xml (added)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/pom.xml Mon Apr 11 
19:36:03 2016
@@ -0,0 +1,209 @@
+<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/xsd/maven-4.0.0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.apache.aries</groupId>
+               <artifactId>parent</artifactId>
+               <version>2.0.1</version>
+               <relativePath>../../parent/pom.xml</relativePath>
+       </parent>
+       <groupId>org.apache.aries.tx-control</groupId>
+       <artifactId>tx-control-provider-jpa-xa</artifactId>
+       <packaging>bundle</packaging>
+       <name>OSGi Transaction Control JPA Resource Provider - XA 
Transactions</name>
+       <version>0.0.1-SNAPSHOT</version>
+
+       <description>
+        This bundle contains a JPA resource provider for use with the OSGi 
Transaction Control Service that supports XA transactions.
+    </description>
+
+       <scm>
+               <connection>
+            
scm:svn:http://svn.apache.org/repos/asf/aries/trunk/tx-control/tx-control-provider-jpa-xa
+        </connection>
+               <developerConnection>
+            
scm:svn:https://svn.apache.org/repos/asf/aries/trunk/tx-control/tx-control-provider-jpa-xa
+        </developerConnection>
+               <url>
+            
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa
+        </url>
+       </scm>
+
+       <properties>
+               <aries.osgi.activator>
+                       org.apache.aries.tx.control.jpa.xa.impl.Activator
+               </aries.osgi.activator>
+               <!-- We keep the versioning from Geronimo as it makes most 
things work, 
+                    even though everything should use the JavaJPA contract -->
+               <aries.osgi.export.pkg>
+                       org.osgi.service.transaction.control.jpa,
+                       org.osgi.service.cm,
+                       org.osgi.service.jdbc,
+                       org.osgi.service.jpa,
+                       javax.persistence;version=1.2;jpa=2.1, 
+                       javax.persistence.criteria;version=1.2;jpa=2.1, 
+                       javax.persistence.metamodel;version=1.2;jpa=2.1, 
+                       javax.persistence.spi;version=1.2;jpa=2.1, 
+                       javax.persistence;version=2.1, 
+                       javax.persistence.criteria;version=2.1, 
+                       javax.persistence.metamodel;version=2.1, 
+                       javax.persistence.spi;version=2.1
+               </aries.osgi.export.pkg>
+               <aries.osgi.private.pkg>
+                       org.apache.aries.tx.control.jdbc.common.impl,
+                       org.apache.aries.tx.control.jdbc.xa.connection.impl,
+                       org.apache.aries.tx.control.jpa.*,
+                       org.apache.geronimo.osgi.locator,
+                       org.apache.geronimo.specs.jpa,
+                       com.zaxxer.hikari,
+                       com.zaxxer.hikari.metrics,
+                       com.zaxxer.hikari.pool,
+                       com.zaxxer.hikari.util
+               </aries.osgi.private.pkg>
+               <aries.osgi.import.pkg>
+                       !com.codahale.*,
+                       !com.zaxxer.hikari.metrics.dropwizard,
+                       !javassist.*,
+                       !javax.transaction,
+                       !org.apache.geronimo.osgi.registry.api,
+                       !org.hibernate.*,
+                       javax.persistence;version="0.0.0",
+                       javax.persistence.criteria;version="0.0.0",
+                       javax.persistence.metamodel;version="0.0.0",
+                       javax.persistence.spi;version="0.0.0",
+                       
org.osgi.service.transaction.control;version="[0.0.1,0.0.2)",
+                       
org.osgi.service.transaction.control.jpa;version="[0.0.1,0.0.2)",
+                       org.osgi.service.cm,
+                       org.osgi.service.jdbc,
+                       org.osgi.service.jpa,
+                       *
+               </aries.osgi.import.pkg>
+               <lastReleaseVersion>0.0.1-SNAPSHOT</lastReleaseVersion>
+       </properties>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.aries.tx-control</groupId>
+                       <artifactId>tx-control-api</artifactId>
+                       <version>0.0.1-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.eclipse.persistence</groupId>
+                       <artifactId>org.eclipse.persistence.core</artifactId>
+                       <version>2.0.0</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-core</artifactId>
+                       <version>5.0.0.Final</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.aries.tx-control</groupId>
+                       <artifactId>tx-control-provider-jdbc-common</artifactId>
+                       <version>0.0.1-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.aries.tx-control</groupId>
+                       <artifactId>tx-control-provider-jdbc-xa</artifactId>
+                       <version>0.0.1-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.service.jdbc</artifactId>
+                       <version>1.0.0</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.geronimo.specs</groupId>
+                       <artifactId>geronimo-jpa_2.1_spec</artifactId>
+                       <version>1.0-alpha-1</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.service.jpa</artifactId>
+                       <version>1.0.0</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.service.cm</artifactId>
+                       <version>1.5.0</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.util.tracker</artifactId>
+                       <version>1.5.1</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.core</artifactId>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>com.zaxxer</groupId>
+                       <artifactId>HikariCP</artifactId>
+                       <version>2.4.3</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.mockito</groupId>
+                       <artifactId>mockito-all</artifactId>
+                       <version>1.9.5</version>
+                       <scope>test</scope>
+               </dependency>
+       </dependencies>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                               <configuration>
+                                       <source>1.8</source>
+                                       <target>1.8</target>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.aries.versioning</groupId>
+                               
<artifactId>org.apache.aries.versioning.plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <id>default-verify</id>
+                                               <phase>verify</phase>
+                                               <goals>
+                                                       
<goal>version-check</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <!-- We have to use a newer bnd due to a bug in 
its handling of
+                                    provided contract version lists -->
+                               <version>3.0.1</version>
+                               <configuration>
+                                       <instructions>
+                                               
<Provide-Capability>osgi.contract;osgi.contract="JavaJPA";version:List&lt;Version&gt;="1.0,2.0,2.1";uses:="javax.persistence,javax.persistence.criteria,javax.persistence.metamodel,javax.persistence.spi"</Provide-Capability>
+                                               
<Require-Capability>osgi.contract;filter:="(&amp;(osgi.contract=JavaJPA)(version=2.1))"</Require-Capability>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
\ No newline at end of file

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/EntityManagerWrapper.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/EntityManagerWrapper.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/EntityManagerWrapper.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/EntityManagerWrapper.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,229 @@
+package org.apache.aries.tx.control.jpa.common.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityGraph;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+import javax.persistence.StoredProcedureQuery;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaDelete;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.CriteriaUpdate;
+import javax.persistence.metamodel.Metamodel;
+
+public abstract class EntityManagerWrapper implements EntityManager {
+
+       public void persist(Object entity) {
+               getRealEntityManager().persist(entity);
+       }
+
+       public <T> T merge(T entity) {
+               return getRealEntityManager().merge(entity);
+       }
+
+       public void remove(Object entity) {
+               getRealEntityManager().remove(entity);
+       }
+
+       public <T> T find(Class<T> entityClass, Object primaryKey) {
+               return getRealEntityManager().find(entityClass, primaryKey);
+       }
+
+       public <T> T find(Class<T> entityClass, Object primaryKey, Map<String, 
Object> properties) {
+               return getRealEntityManager().find(entityClass, primaryKey, 
properties);
+       }
+
+       public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType 
lockMode) {
+               return getRealEntityManager().find(entityClass, primaryKey, 
lockMode);
+       }
+
+       public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType 
lockMode, Map<String, Object> properties) {
+               return getRealEntityManager().find(entityClass, primaryKey, 
lockMode, properties);
+       }
+
+       public <T> T getReference(Class<T> entityClass, Object primaryKey) {
+               return getRealEntityManager().getReference(entityClass, 
primaryKey);
+       }
+
+       public void flush() {
+               getRealEntityManager().flush();
+       }
+
+       public void setFlushMode(FlushModeType flushMode) {
+               getRealEntityManager().setFlushMode(flushMode);
+       }
+
+       public FlushModeType getFlushMode() {
+               return getRealEntityManager().getFlushMode();
+       }
+
+       public void lock(Object entity, LockModeType lockMode) {
+               getRealEntityManager().lock(entity, lockMode);
+       }
+
+       public void lock(Object entity, LockModeType lockMode, Map<String, 
Object> properties) {
+               getRealEntityManager().lock(entity, lockMode, properties);
+       }
+
+       public void refresh(Object entity) {
+               getRealEntityManager().refresh(entity);
+       }
+
+       public void refresh(Object entity, Map<String, Object> properties) {
+               getRealEntityManager().refresh(entity, properties);
+       }
+
+       public void refresh(Object entity, LockModeType lockMode) {
+               getRealEntityManager().refresh(entity, lockMode);
+       }
+
+       public void refresh(Object entity, LockModeType lockMode, Map<String, 
Object> properties) {
+               getRealEntityManager().refresh(entity, lockMode, properties);
+       }
+
+       public void clear() {
+               getRealEntityManager().clear();
+       }
+
+       public void detach(Object entity) {
+               getRealEntityManager().detach(entity);
+       }
+
+       public boolean contains(Object entity) {
+               return getRealEntityManager().contains(entity);
+       }
+
+       public LockModeType getLockMode(Object entity) {
+               return getRealEntityManager().getLockMode(entity);
+       }
+
+       public void setProperty(String propertyName, Object value) {
+               getRealEntityManager().setProperty(propertyName, value);
+       }
+
+       public Map<String, Object> getProperties() {
+               return getRealEntityManager().getProperties();
+       }
+
+       public Query createQuery(String qlString) {
+               return getRealEntityManager().createQuery(qlString);
+       }
+
+       public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) {
+               return getRealEntityManager().createQuery(criteriaQuery);
+       }
+
+       public Query createQuery(@SuppressWarnings("rawtypes") CriteriaUpdate 
updateQuery) {
+               return getRealEntityManager().createQuery(updateQuery);
+       }
+
+       public Query createQuery(@SuppressWarnings("rawtypes") CriteriaDelete 
deleteQuery) {
+               return getRealEntityManager().createQuery(deleteQuery);
+       }
+
+       public <T> TypedQuery<T> createQuery(String qlString, Class<T> 
resultClass) {
+               return getRealEntityManager().createQuery(qlString, 
resultClass);
+       }
+
+       public Query createNamedQuery(String name) {
+               return getRealEntityManager().createNamedQuery(name);
+       }
+
+       public <T> TypedQuery<T> createNamedQuery(String name, Class<T> 
resultClass) {
+               return getRealEntityManager().createNamedQuery(name, 
resultClass);
+       }
+
+       public Query createNativeQuery(String sqlString) {
+               return getRealEntityManager().createNativeQuery(sqlString);
+       }
+
+       public Query createNativeQuery(String sqlString, 
@SuppressWarnings("rawtypes") Class resultClass) {
+               return getRealEntityManager().createNativeQuery(sqlString, 
resultClass);
+       }
+
+       public Query createNativeQuery(String sqlString, String 
resultSetMapping) {
+               return getRealEntityManager().createNativeQuery(sqlString, 
resultSetMapping);
+       }
+
+       public StoredProcedureQuery createNamedStoredProcedureQuery(String 
name) {
+               return 
getRealEntityManager().createNamedStoredProcedureQuery(name);
+       }
+
+       public StoredProcedureQuery createStoredProcedureQuery(String 
procedureName) {
+               return 
getRealEntityManager().createStoredProcedureQuery(procedureName);
+       }
+
+       public StoredProcedureQuery createStoredProcedureQuery(String 
procedureName, @SuppressWarnings("rawtypes") Class... resultClasses) {
+               return 
getRealEntityManager().createStoredProcedureQuery(procedureName, resultClasses);
+       }
+
+       public StoredProcedureQuery createStoredProcedureQuery(String 
procedureName, String... resultSetMappings) {
+               return 
getRealEntityManager().createStoredProcedureQuery(procedureName, 
resultSetMappings);
+       }
+
+       public void joinTransaction() {
+               getRealEntityManager().joinTransaction();
+       }
+
+       public boolean isJoinedToTransaction() {
+               return getRealEntityManager().isJoinedToTransaction();
+       }
+
+       public <T> T unwrap(Class<T> cls) {
+               return getRealEntityManager().unwrap(cls);
+       }
+
+       public Object getDelegate() {
+               return getRealEntityManager().getDelegate();
+       }
+
+       public void close() {
+               getRealEntityManager().close();
+       }
+
+       public boolean isOpen() {
+               return getRealEntityManager().isOpen();
+       }
+
+       public EntityTransaction getTransaction() {
+               return getRealEntityManager().getTransaction();
+       }
+
+       public EntityManagerFactory getEntityManagerFactory() {
+               return getRealEntityManager().getEntityManagerFactory();
+       }
+
+       public CriteriaBuilder getCriteriaBuilder() {
+               return getRealEntityManager().getCriteriaBuilder();
+       }
+
+       public Metamodel getMetamodel() {
+               return getRealEntityManager().getMetamodel();
+       }
+
+       public <T> EntityGraph<T> createEntityGraph(Class<T> rootType) {
+               return getRealEntityManager().createEntityGraph(rootType);
+       }
+
+       public EntityGraph<?> createEntityGraph(String graphName) {
+               return getRealEntityManager().createEntityGraph(graphName);
+       }
+
+       public EntityGraph<?> getEntityGraph(String graphName) {
+               return getRealEntityManager().getEntityGraph(graphName);
+       }
+
+       public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> 
entityClass) {
+               return getRealEntityManager().getEntityGraphs(entityClass);
+       }
+
+       protected abstract EntityManager getRealEntityManager();
+
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ScopedEntityManagerWrapper.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ScopedEntityManagerWrapper.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ScopedEntityManagerWrapper.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ScopedEntityManagerWrapper.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,33 @@
+package org.apache.aries.tx.control.jpa.common.impl;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TransactionRequiredException;
+
+public class ScopedEntityManagerWrapper extends EntityManagerWrapper {
+
+       private final EntityManager entityManager;
+       
+       public ScopedEntityManagerWrapper(EntityManager entityManager) {
+               this.entityManager = entityManager;
+       }
+
+       @Override
+       protected EntityManager getRealEntityManager() {
+               return entityManager;
+       }
+
+       @Override
+       public void close() {
+               // A no op
+       }
+
+       @Override
+       public void joinTransaction() {
+               throw new TransactionRequiredException("This EntityManager is 
being used in the No Transaction scope. There is no transaction to join.");
+       }
+
+       @Override
+       public boolean isJoinedToTransaction() {
+               return false;
+       }
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/TxEntityManagerWrapper.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/TxEntityManagerWrapper.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/TxEntityManagerWrapper.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/common/impl/TxEntityManagerWrapper.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,40 @@
+package org.apache.aries.tx.control.jpa.common.impl;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import org.osgi.service.transaction.control.TransactionException;
+
+public class TxEntityManagerWrapper extends EntityManagerWrapper {
+
+       private final EntityManager entityManager;
+       
+       public TxEntityManagerWrapper(EntityManager entityManager) {
+               this.entityManager = entityManager;
+       }
+
+       @Override
+       protected EntityManager getRealEntityManager() {
+               return entityManager;
+       }
+
+       @Override
+       public void close() {
+               // A no-op
+       }
+
+       @Override
+       public void joinTransaction() {
+               // A no-op
+       }
+
+       @Override
+       public boolean isJoinedToTransaction() {
+               return true;
+       }
+
+       @Override
+       public EntityTransaction getTransaction() {
+               throw new TransactionException("Programmatic transaction 
management is not supported for a Transactional EntityManager");
+       }
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/eclipse/impl/EclipseTxControlPlatform.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/eclipse/impl/EclipseTxControlPlatform.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/eclipse/impl/EclipseTxControlPlatform.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/eclipse/impl/EclipseTxControlPlatform.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,13 @@
+//package org.apache.aries.tx.control.jpa.xa.eclipse.impl;
+//
+//import org.eclipse.persistence.platform.server.ServerPlatformBase;
+//
+//public class EclipseTxControlPlatform extends ServerPlatformBase {
+//
+//     @Override
+//     public Class getExternalTransactionControllerClass() {
+//             // TODO Auto-generated method stub
+//             return null;
+//     }
+//
+//}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/hibernate/impl/HibernateTxControlPlatform.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/hibernate/impl/HibernateTxControlPlatform.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/hibernate/impl/HibernateTxControlPlatform.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/hibernate/impl/HibernateTxControlPlatform.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,275 @@
+package org.apache.aries.tx.control.jpa.xa.hibernate.impl;
+
+import static javax.transaction.Status.STATUS_COMMITTED;
+import static javax.transaction.Status.STATUS_ROLLEDBACK;
+import static javax.transaction.Status.STATUS_UNKNOWN;
+import static org.hibernate.ConnectionAcquisitionMode.AS_NEEDED;
+import static org.hibernate.ConnectionReleaseMode.AFTER_STATEMENT;
+import static org.osgi.service.transaction.control.TransactionStatus.COMMITTED;
+
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.persistence.TransactionRequiredException;
+import javax.transaction.Synchronization;
+
+import org.hibernate.ConnectionAcquisitionMode;
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.HibernateException;
+import org.hibernate.engine.transaction.spi.IsolationDelegate;
+import org.hibernate.engine.transaction.spi.TransactionObserver;
+import org.hibernate.jdbc.WorkExecutor;
+import org.hibernate.jdbc.WorkExecutorVisitable;
+import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
+import org.hibernate.resource.transaction.SynchronizationRegistry;
+import org.hibernate.resource.transaction.TransactionCoordinator;
+import 
org.hibernate.resource.transaction.TransactionCoordinator.TransactionDriver;
+import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
+import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
+import org.osgi.service.transaction.control.TransactionContext;
+import org.osgi.service.transaction.control.TransactionControl;
+import org.osgi.service.transaction.control.TransactionStatus;
+
+public class HibernateTxControlPlatform implements 
TransactionCoordinatorBuilder {
+       
+       private static final long serialVersionUID = 1L;
+
+       private final TransactionControl control;
+       
+       
+       public HibernateTxControlPlatform(TransactionControl control) {
+               this.control = control;
+       }
+
+       @Override
+       public TransactionCoordinator 
buildTransactionCoordinator(TransactionCoordinatorOwner owner, 
TransactionCoordinatorOptions options) {
+               return new HibernateTxControlCoordinator(owner, 
options.shouldAutoJoinTransaction());
+       }
+
+       @Override
+       public boolean isJta() {
+               return true;
+       }
+
+       @Override
+       public ConnectionReleaseMode getDefaultConnectionReleaseMode() {
+               return AFTER_STATEMENT;
+       }
+
+       @Override
+       public ConnectionAcquisitionMode getDefaultConnectionAcquisitionMode() {
+               return AS_NEEDED;
+       }
+
+       public class HibernateTxControlCoordinator implements 
TransactionCoordinator, 
+               SynchronizationRegistry, TransactionDriver, IsolationDelegate {
+               
+               private static final long serialVersionUID = 1L;
+
+               private final List<TransactionObserver> registeredObservers = 
new ArrayList<>();
+
+               private final TransactionCoordinatorOwner owner;
+
+               private final boolean autoJoin;
+               
+               private boolean joined = false;
+               
+               public 
HibernateTxControlCoordinator(TransactionCoordinatorOwner owner, boolean 
autoJoin) {
+                       this.owner = owner;
+                       this.autoJoin = autoJoin;
+               }
+
+               @Override
+               public void explicitJoin() {
+                       if(!joined) {
+                               if(!control.activeTransaction()) {
+                                       throw new 
TransactionRequiredException("There is no transaction active to join");
+                               }
+                               
+                               internalJoin();
+                       }
+               }
+
+               private void internalJoin() {
+                       TransactionContext currentContext = 
control.getCurrentContext();
+                       currentContext.preCompletion(this::beforeCompletion);
+                       currentContext.postCompletion(this::afterCompletion);
+                       joined = true;
+               }
+
+               @Override
+               public boolean isJoined() {
+                       return joined;
+               }
+
+               @Override
+               public void pulse() {
+                       if (autoJoin && !joined && control.activeTransaction()) 
{
+                               internalJoin();
+                       }
+               }
+
+               @Override
+               public TransactionDriver getTransactionDriverControl() {
+                       return this;
+               }
+
+               @Override
+               public SynchronizationRegistry getLocalSynchronizations() {
+                       return this;
+               }
+
+               @Override
+               public boolean isActive() {
+                       return control.activeTransaction();
+               }
+
+               @Override
+               public IsolationDelegate createIsolationDelegate() {
+                       return this;
+               }
+
+               @Override
+               public void addObserver(TransactionObserver observer) {
+                       registeredObservers.add(observer);
+               }
+
+               @Override
+               public void removeObserver(TransactionObserver observer) {
+                       registeredObservers.remove(observer);
+               }
+
+               @Override
+               public TransactionCoordinatorBuilder 
getTransactionCoordinatorBuilder() {
+                       return HibernateTxControlPlatform.this;
+               }
+
+               @Override
+               public void setTimeOut(int seconds) {
+                       // TODO How do we support this?
+               }
+
+               @Override
+               public int getTimeOut() {
+                       return -1;
+               }
+       
+               @Override
+               public void registerSynchronization(Synchronization 
synchronization) {
+                       TransactionContext currentContext = 
control.getCurrentContext();
+                       
currentContext.preCompletion(synchronization::beforeCompletion);
+                       currentContext.postCompletion(status -> 
synchronization.afterCompletion(toIntStatus(status)));
+               }
+
+               private void beforeCompletion() {
+                       try {
+                               owner.beforeTransactionCompletion();
+                       }
+                       catch (RuntimeException re) {
+                               control.setRollbackOnly();
+                               throw re;
+                       }
+                       finally {
+                               
registeredObservers.forEach(TransactionObserver::beforeCompletion);
+                       }
+               }
+               
+               private void afterCompletion(TransactionStatus status) {
+                       if ( owner.isActive() ) {
+                               toIntStatus(status);
+                               
+                               boolean committed = status == COMMITTED;
+                               owner.afterTransactionCompletion(committed, 
false);
+                               
+                               registeredObservers.forEach(o -> 
o.afterCompletion(committed, false));
+                       }
+               }
+
+               private int toIntStatus(TransactionStatus status) {
+                       switch(status) {
+                               case COMMITTED:
+                                       return STATUS_COMMITTED;
+                               case ROLLED_BACK:
+                                       return STATUS_ROLLEDBACK;
+                               default:
+                                       return STATUS_UNKNOWN;
+                       }
+               }
+
+               @Override
+               public void begin() {
+                       if(!control.activeTransaction()) {
+                               throw new IllegalStateException("There is no 
existing active transaction scope");
+                       }
+               }
+
+               @Override
+               public void commit() {
+                       if(!control.activeTransaction()) {
+                               throw new IllegalStateException("There is no 
existing active transaction scope");
+                       }
+               }
+
+               @Override
+               public void rollback() {
+                       if(!control.activeTransaction()) {
+                               throw new IllegalStateException("There is no 
existing active transaction scope");
+                       }
+                       control.setRollbackOnly();
+               }
+
+               @Override
+               public org.hibernate.resource.transaction.spi.TransactionStatus 
getStatus() {
+                       TransactionStatus status = 
control.getCurrentContext().getTransactionStatus();
+                       switch(status) {
+                               case ACTIVE:
+                                       return 
org.hibernate.resource.transaction.spi.TransactionStatus.ACTIVE;
+                               case COMMITTED:
+                                       return 
org.hibernate.resource.transaction.spi.TransactionStatus.COMMITTED;
+                               case PREPARING:
+                               case PREPARED:
+                               case COMMITTING:
+                                       return 
org.hibernate.resource.transaction.spi.TransactionStatus.COMMITTING;
+                               case MARKED_ROLLBACK:
+                                       return 
org.hibernate.resource.transaction.spi.TransactionStatus.MARKED_ROLLBACK;
+                               case NO_TRANSACTION:
+                                       return 
org.hibernate.resource.transaction.spi.TransactionStatus.NOT_ACTIVE;
+                               case ROLLED_BACK:
+                                       return 
org.hibernate.resource.transaction.spi.TransactionStatus.ROLLED_BACK;
+                               case ROLLING_BACK:
+                                       return 
org.hibernate.resource.transaction.spi.TransactionStatus.ROLLING_BACK;
+                               default:
+                                       throw new IllegalStateException("The 
state " + status + " is unknown");
+                       }
+               }
+
+               @Override
+               public void markRollbackOnly() {
+                       control.setRollbackOnly();
+               }
+
+               @Override
+               public <T> T delegateWork(WorkExecutorVisitable<T> work, 
boolean transacted) throws HibernateException {
+                       Callable<T> c = () -> {
+                       
+                               JdbcSessionOwner sessionOwner = 
owner.getJdbcSessionOwner();
+                               Connection conn = 
sessionOwner.getJdbcConnectionAccess().obtainConnection();
+                               
+                               try {
+                                       return work.accept(new 
WorkExecutor<>(), conn);
+                               } finally {
+                                       
sessionOwner.getJdbcConnectionAccess().releaseConnection(conn);
+                               }
+                       };
+                       
+                       if(transacted) {
+                               return control.requiresNew(c);
+                       } else {
+                               return control.notSupported(c);
+                       }
+                               
+               }
+       }
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/Activator.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/Activator.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/Activator.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/Activator.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,56 @@
+package org.apache.aries.tx.control.jpa.xa.impl;
+
+import static org.osgi.framework.Constants.SERVICE_PID;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.geronimo.specs.jpa.PersistenceActivator;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ManagedServiceFactory;
+import 
org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory;
+
+public class Activator implements BundleActivator {
+
+       private final BundleActivator geronimoActivator;
+       
+       private ServiceRegistration<JPAEntityManagerProviderFactory> reg;
+       private ServiceRegistration<ManagedServiceFactory> factoryReg;
+       
+       public Activator() {
+               geronimoActivator = new PersistenceActivator();
+       }
+       
+       @Override
+       public void start(BundleContext context) throws Exception {
+               geronimoActivator.start(context);
+               
+               reg = 
context.registerService(JPAEntityManagerProviderFactory.class, 
+                               new JPAEntityManagerProviderFactoryImpl(), 
getProperties());
+               
+               factoryReg = 
context.registerService(ManagedServiceFactory.class, 
+                               new ManagedServiceFactoryImpl(context), 
getMSFProperties());
+       }
+
+       @Override
+       public void stop(BundleContext context) throws Exception {
+               reg.unregister();
+               factoryReg.unregister();
+               geronimoActivator.stop(context);
+       }
+
+       private Dictionary<String, Object> getProperties() {
+               Dictionary<String, Object> props = new Hashtable<>();
+               props.put("osgi.xa.enabled", Boolean.TRUE);
+               return props;
+       }
+
+       private Dictionary<String, ?> getMSFProperties() {
+               Dictionary<String, Object> props = new Hashtable<>();
+               props.put(SERVICE_PID, "org.apache.aries.tx.control.jpa.xa");
+               return props;
+       }
+
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/DelayedJPAEntityManagerProvider.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/DelayedJPAEntityManagerProvider.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/DelayedJPAEntityManagerProvider.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/DelayedJPAEntityManagerProvider.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,40 @@
+package org.apache.aries.tx.control.jpa.xa.impl;
+
+import java.util.function.Function;
+
+import javax.persistence.EntityManager;
+
+import org.osgi.service.transaction.control.TransactionControl;
+import org.osgi.service.transaction.control.TransactionException;
+import org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider;
+
+public class DelayedJPAEntityManagerProvider implements 
JPAEntityManagerProvider {
+       
+       private final Function<TransactionControl, JPAEntityManagerProvider> 
wireToTransactionControl;
+       
+       private JPAEntityManagerProvider delegate;
+       
+       private TransactionControl wiredTxControl;
+
+       public DelayedJPAEntityManagerProvider(Function<TransactionControl, 
JPAEntityManagerProvider> wireToTransactionControl) {
+               this.wireToTransactionControl = wireToTransactionControl;
+       }
+
+       @Override
+       public EntityManager getResource(TransactionControl txControl) throws 
TransactionException {
+               synchronized (wireToTransactionControl) {
+                       
+                       if(wiredTxControl != null && 
!wiredTxControl.equals(txControl)) {
+                               throw new TransactionException("This 
JPAEntityManagerProvider has already been wired to a different Transaction 
Control service.");
+                       }
+                       if(delegate == null) {
+                               delegate = 
wireToTransactionControl.apply(txControl);
+                               wiredTxControl = txControl;
+                       }
+               }
+               return delegate.getResource(txControl);
+       }
+       
+       
+
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,160 @@
+package org.apache.aries.tx.control.jpa.xa.impl;
+
+import static java.util.Optional.ofNullable;
+import static javax.persistence.spi.PersistenceUnitTransactionType.JTA;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
+
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+import org.osgi.service.transaction.control.TransactionControl;
+import org.osgi.service.transaction.control.TransactionException;
+import org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider;
+import 
org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory;
+
+public class JPAEntityManagerProviderFactoryImpl implements 
JPAEntityManagerProviderFactory {
+
+       @Override
+       public JPAEntityManagerProvider 
getProviderFor(EntityManagerFactoryBuilder emfb, Map<String, Object> 
jpaProperties,
+                       Map<String, Object> resourceProviderProperties) {
+               if(checkEnlistment(resourceProviderProperties)) {
+                       return new DelayedJPAEntityManagerProvider(tx -> {
+                               
+                               Map<String, Object> toUse = 
enlistDataSource(tx, jpaProperties);
+                               
+                               return internalBuilderCreate(emfb, toUse);
+                       });
+               }
+               
+               return internalBuilderCreate(emfb, jpaProperties);
+       }
+
+       private Map<String, Object> enlistDataSource(TransactionControl tx, 
Map<String, Object> jpaProperties) {
+               Map<String, Object> toReturn = new HashMap<>(jpaProperties);
+               
+               DataSource ds = (DataSource) 
jpaProperties.get("javax.persistence.jtaDataSource");
+
+               
if(!jpaProperties.containsKey("javax.persistence.nonJtaDataSource")) {
+                       toReturn.put("javax.persistence.jtaDataSource", ds);
+               }
+               
+               toReturn.put("javax.persistence.jtaDataSource", new 
EnlistingDataSource(ds));
+               
+               return toReturn;
+       }
+
+       private JPAEntityManagerProvider 
internalBuilderCreate(EntityManagerFactoryBuilder emfb,
+                       Map<String, Object> jpaProperties) {
+               EntityManagerFactory emf = 
emfb.createEntityManagerFactory(jpaProperties);
+               
+               validateEMF(emf);
+               
+               return new JPAEntityManagerProviderImpl(emf);
+       }
+
+       private void validateEMF(EntityManagerFactory emf) {
+               Object o = 
emf.getProperties().get("javax.persistence.transactionType");
+               
+               PersistenceUnitTransactionType tranType;
+               if(o instanceof PersistenceUnitTransactionType) {
+                       tranType = (PersistenceUnitTransactionType) o;
+               } else if (o instanceof String) {
+                       tranType = 
PersistenceUnitTransactionType.valueOf(o.toString());
+               } else {
+                       //TODO log this?
+                       tranType = JTA;
+               }
+               
+               if(JTA != tranType) {
+                       throw new IllegalArgumentException("The supplied 
EntityManagerFactory is not declared RESOURCE_LOCAL");
+               }
+       }
+
+       @Override
+       public JPAEntityManagerProvider getProviderFor(EntityManagerFactory emf,
+                       Map<String, Object> resourceProviderProperties) {
+               checkEnlistment(resourceProviderProperties);
+               validateEMF(emf);
+               
+               return new JPAEntityManagerProviderImpl(emf);
+       }
+
+       private boolean checkEnlistment(Map<String, Object> 
resourceProviderProperties) {
+               if (toBoolean(resourceProviderProperties, 
LOCAL_ENLISTMENT_ENABLED, false)) {
+                       throw new TransactionException("This Resource Provider 
does not support Local transactions");
+               } else if (!toBoolean(resourceProviderProperties, 
XA_ENLISTMENT_ENABLED, true)) {
+                       throw new TransactionException(
+                                       "This Resource Provider always enlists 
in XA transactions as it does not support local transactions");
+               }
+               
+               return !toBoolean(resourceProviderProperties, 
PRE_ENLISTED_DB_CONNECTION, false);
+       }
+       
+       public static boolean toBoolean(Map<String, Object> props, String key, 
boolean defaultValue) {
+               Object o =  ofNullable(props)
+                       .map(m -> m.get(key))
+                       .orElse(defaultValue);
+               
+               if (o instanceof Boolean) {
+                       return ((Boolean) o).booleanValue();
+               } else if(o instanceof String) {
+                       return Boolean.parseBoolean((String) o);
+               } else {
+                       throw new IllegalArgumentException("The property " + 
key + " cannot be converted to a boolean");
+               }
+       }
+       
+       public class EnlistingDataSource implements DataSource {
+               
+               private final DataSource delegate;
+
+               public EnlistingDataSource(DataSource delegate) {
+                       this.delegate = delegate;
+               }
+
+               public PrintWriter getLogWriter() throws SQLException {
+                       return delegate.getLogWriter();
+               }
+
+               public <T> T unwrap(Class<T> iface) throws SQLException {
+                       return delegate.unwrap(iface);
+               }
+
+               public void setLogWriter(PrintWriter out) throws SQLException {
+                       delegate.setLogWriter(out);
+               }
+
+               public boolean isWrapperFor(Class<?> iface) throws SQLException 
{
+                       return delegate.isWrapperFor(iface);
+               }
+
+               public Connection getConnection() throws SQLException {
+                       return delegate.getConnection();
+               }
+
+               public void setLoginTimeout(int seconds) throws SQLException {
+                       delegate.setLoginTimeout(seconds);
+               }
+
+               public Connection getConnection(String username, String 
password) throws SQLException {
+                       return delegate.getConnection(username, password);
+               }
+
+               public int getLoginTimeout() throws SQLException {
+                       return delegate.getLoginTimeout();
+               }
+
+               public Logger getParentLogger() throws 
SQLFeatureNotSupportedException {
+                       return delegate.getParentLogger();
+               }
+       }
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderImpl.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderImpl.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderImpl.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,26 @@
+package org.apache.aries.tx.control.jpa.xa.impl;
+
+import java.util.UUID;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.osgi.service.transaction.control.TransactionControl;
+import org.osgi.service.transaction.control.TransactionException;
+import org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider;
+
+public class JPAEntityManagerProviderImpl implements JPAEntityManagerProvider {
+
+       private final UUID                                      uuid    = 
UUID.randomUUID();
+
+       private final EntityManagerFactory      emf;
+
+       public JPAEntityManagerProviderImpl(EntityManagerFactory emf) {
+               this.emf = emf;
+       }
+
+       @Override
+       public EntityManager getResource(TransactionControl txControl) throws 
TransactionException {
+               return new XATxContextBindingEntityManager(txControl, emf, 
uuid);
+       }
+}

Added: 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/LifecycleAware.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/LifecycleAware.java?rev=1738630&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/LifecycleAware.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/LifecycleAware.java
 Mon Apr 11 19:36:03 2016
@@ -0,0 +1,8 @@
+package org.apache.aries.tx.control.jpa.xa.impl;
+
+public interface LifecycleAware {
+
+       public void start();
+       
+       public void stop();
+}


Reply via email to