aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1774648 - in /aries/trunk/tx-control: tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/ tx-control-api/src/main/java/org/osgi/service/transaction/control/jpa/ tx-control-itests/src/test/java/org/apache/aries/tx/contro...
Date Fri, 16 Dec 2016 18:31:33 GMT
Author: timothyjward
Date: Fri Dec 16 18:31:32 2016
New Revision: 1774648

URL: http://svn.apache.org/viewvc?rev=1774648&view=rev
Log:
[tx-control] Add support for releasing resource providers to the factories

Modified:
    aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java
    aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jpa/JPAEntityManagerProviderFactory.java
    aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
    aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ConnectionLifecycleTest.java
    aries/trunk/tx-control/tx-control-provider-common/src/main/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactory.java
    aries/trunk/tx-control/tx-control-provider-common/src/test/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactoryTest.java
    aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/AbstractJDBCConnectionProvider.java
    aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/InternalJDBCConnectionProviderFactory.java
    aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ResourceTrackingJDBCConnectionProviderFactory.java
    aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java
    aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java
    aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java
    aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.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/JDBCConnectionProviderImpl.java
    aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/RecoverableXAResourceImpl.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-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/AbstractJPAEntityManagerProvider.java
    aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/InternalJPAEntityManagerProviderFactory.java
    aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ResourceTrackingJPAEntityManagerProviderFactory.java
    aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderFactoryImpl.java
    aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderImpl.java
    aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManager.java
    aries/trunk/tx-control/tx-control-provider-jpa-local/src/test/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManagerTest.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/XATxContextBindingEntityManager.java
    aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManagerTest.java

Modified: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java (original)
+++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java Fri Dec 16 18:31:32 2016
@@ -147,4 +147,18 @@ public interface JDBCConnectionProviderF
 	JDBCConnectionProvider getProviderFor(XADataSource ds,
 			Map<String,Object> resourceProviderProperties);
 
+	/**
+	 * Release a {@link JDBCConnectionProvider} instance that has been created
+	 * by this factory. Released instances are eligible to be shut down and have
+	 * any remaining open connections closed.
+	 * <p>
+	 * Note that all {@link JDBCConnectionProvider} instances created by this
+	 * factory service are implicitly released when the factory service is
+	 * released by this bundle.
+	 * 
+	 * @param provider
+	 * @throws IllegalArgumentException if the supplied resource was not created
+	 *             by this factory service instance.
+	 */
+	void releaseProvider(JDBCConnectionProvider provider);
 }

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=1774648&r1=1774647&r2=1774648&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 Fri Dec 16 18:31:32 2016
@@ -88,4 +88,18 @@ public interface JPAEntityManagerProvide
 	JPAEntityManagerProvider getProviderFor(EntityManagerFactory emf,
 			Map<String,Object> resourceProviderProperties);
 
+	/**
+	 * Release a {@link JPAEntityManagerProvider} instance that has been created
+	 * by this factory. Released instances are eligible to be shut down and have
+	 * any remaining open connections closed.
+	 * <p>
+	 * Note that all {@link JPAEntityManagerProvider} instances created by this
+	 * factory service are implicitly released when the factory service is
+	 * released by this bundle.
+	 * 
+	 * @param provider
+	 * @throws IllegalArgumentException if the supplied resource was not created
+	 *             by this factory service instance.
+	 */
+	void releaseProvider(JPAEntityManagerProvider provider);
 }

Modified: aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java (original)
+++ aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java Fri Dec 16 18:31:32 2016
@@ -76,6 +76,8 @@ public abstract class AbstractTransactio
 	
 	protected TransactionControl txControl;
 
+	protected JDBCConnectionProvider provider;
+	
 	protected Connection connection;
 
 	private Server server;
@@ -165,8 +167,8 @@ public abstract class AbstractTransactio
 		
 		DataSourceFactory dsf = getService(DataSourceFactory.class, 5000);
 		
-		return resourceProviderFactory.getProviderFor(dsf, jdbc, resourceProviderConfig())
-				.getResource(txControl);
+		provider = resourceProviderFactory.getProviderFor(dsf, jdbc, resourceProviderConfig());
+		return provider.getResource(txControl);
 	}
 
 	@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -189,7 +191,8 @@ public abstract class AbstractTransactio
 				pid, "?");
 		config.update((Hashtable)jdbc);
 		
-		return getService(JDBCConnectionProvider.class, 5000).getResource(txControl);
+		provider = getService(JDBCConnectionProvider.class, 5000);
+		return provider.getResource(txControl);
 	}
 	
 	@After

Modified: aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ConnectionLifecycleTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ConnectionLifecycleTest.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ConnectionLifecycleTest.java (original)
+++ aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ConnectionLifecycleTest.java Fri Dec 16 18:31:32 2016
@@ -234,6 +234,39 @@ public class ConnectionLifecycleTest ext
 	}
 
 	@Test
+	public void testReleaseOfFactoryCreatedService() {
+		Assume.assumeFalse("Not a factory test", isConfigured());
+		
+		txControl.required(
+				() -> connection.createStatement().execute("Insert into TEST_TABLE values ( 'Hello World!' )"));
+		
+		assertEquals("Hello World!", txControl.notSupported(() -> {
+			ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
+			rs.next();
+			return rs.getString(1);
+		}));
+		
+		JDBCConnectionProviderFactory factory = (JDBCConnectionProviderFactory) trackers.stream()
+				.filter(t -> t.getService() instanceof JDBCConnectionProviderFactory)
+				.findFirst()
+				.get().getService();
+
+		factory.releaseProvider(provider);
+		
+		try {
+			assertEquals("Hello World!", txControl.notSupported(() -> {
+				ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
+				rs.next();
+				return rs.getString(1);
+			}));
+			fail("Should not be accessible");
+		} catch (ScopedWorkException swe) {
+			assertTrue(swe.getCause().toString(), swe.getCause() instanceof TransactionException);
+			assertEquals("There was a problem getting hold of a database connection", swe.getCause().getMessage());
+		}
+	}
+
+	@Test
 	public void testPoolLifecycle() throws Exception {
 		Set<String> allIds = new TreeSet<>();
 

Modified: aries/trunk/tx-control/tx-control-provider-common/src/main/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-common/src/main/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactory.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-common/src/main/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactory.java (original)
+++ aries/trunk/tx-control/tx-control-provider-common/src/main/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactory.java Fri Dec 16 18:31:32 2016
@@ -18,8 +18,10 @@
  */
 package org.apache.aries.tx.control.resource.common.impl;
 
-import java.util.ArrayList;
-import java.util.List;
+import static java.util.Collections.newSetFromMap;
+
+import java.util.IdentityHashMap;
+import java.util.Set;
 import java.util.concurrent.Callable;
 
 import org.osgi.framework.ServiceException;
@@ -30,7 +32,7 @@ public abstract class TrackingResourcePr
 
 	private static final Logger LOG = LoggerFactory.getLogger(TrackingResourceProviderFactory.class);
 	
-	private final List<T> toClose = new ArrayList<>();
+	private final Set<T> toClose = newSetFromMap(new IdentityHashMap<>());
 	
 	private boolean closed;
 	
@@ -79,4 +81,19 @@ public abstract class TrackingResourcePr
 		
 		toClose.clear();
 	}
+	
+	protected void release(T t) {
+		synchronized (toClose) {
+			if(closed) {
+				throw new IllegalStateException("This resource factory is closed");
+			}
+			
+			if (!toClose.remove(t)) {
+				throw new IllegalArgumentException("The resource " + t + " is not managed by this factory");
+			}
+		}
+		try {
+			t.close();
+		} catch (Exception e) {}
+	}
 }
\ No newline at end of file

Modified: aries/trunk/tx-control/tx-control-provider-common/src/test/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-common/src/test/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactoryTest.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-common/src/test/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactoryTest.java (original)
+++ aries/trunk/tx-control/tx-control-provider-common/src/test/java/org/apache/aries/tx/control/resource/common/impl/TrackingResourceProviderFactoryTest.java Fri Dec 16 18:31:32 2016
@@ -34,4 +34,34 @@ public class TrackingResourceProviderFac
 		
 		Mockito.verify(result).close();
 	}
+
+	@Test
+	public void testReleaseResource() throws Exception {
+		TrackingResourceProviderFactory<AutoCloseable> trpf = new TrackingResourceProviderFactory<AutoCloseable>(){};
+		
+		AutoCloseable result = trpf.doGetResult(() -> Mockito.mock(AutoCloseable.class));
+		
+		trpf.release(result);
+		
+		Mockito.verify(result).close();
+	}
+	
+	@Test(expected=IllegalArgumentException.class)
+	public void testReleaseResourceNotFromThisFactory() throws Exception {
+		TrackingResourceProviderFactory<AutoCloseable> trpf = new TrackingResourceProviderFactory<AutoCloseable>(){};
+		
+		AutoCloseable result = Mockito.mock(AutoCloseable.class);
+		
+		trpf.release(result);
+	}
+
+	@Test(expected=IllegalStateException.class)
+	public void testReleaseAfterFactoryClosed() throws Exception {
+		TrackingResourceProviderFactory<AutoCloseable> trpf = new TrackingResourceProviderFactory<AutoCloseable>(){};
+		trpf.closeAll();
+		
+		AutoCloseable result = Mockito.mock(AutoCloseable.class);
+		
+		trpf.release(result);
+	}
 }

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/AbstractJDBCConnectionProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/AbstractJDBCConnectionProvider.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/AbstractJDBCConnectionProvider.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/AbstractJDBCConnectionProvider.java Fri Dec 16 18:31:32 2016
@@ -19,6 +19,8 @@
 package org.apache.aries.tx.control.jdbc.common.impl;
 
 import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.sql.DataSource;
 
@@ -32,7 +34,9 @@ public abstract class AbstractJDBCConnec
 
 	private static final Logger LOG = LoggerFactory.getLogger(AbstractJDBCConnectionProvider.class);
 	
-	protected final DataSource dataSource;
+	private final DataSource dataSource;
+	
+	private final AtomicBoolean closed = new AtomicBoolean(false);
 	
 	public AbstractJDBCConnectionProvider(DataSource dataSource) {
 		this.dataSource = dataSource;
@@ -43,7 +47,18 @@ public abstract class AbstractJDBCConnec
 			throws TransactionException;
 
 	
+	public Connection getConnection() throws SQLException {
+		if(closed.get()) throw new IllegalStateException("This resource provider is no longer in use");
+		return dataSource.getConnection();
+	}
+	
+	public Connection getConnection(String recoveryUser, String recoveryPw) throws SQLException {
+		if(closed.get()) throw new IllegalStateException("This resource provider is no longer in use");
+		return dataSource.getConnection(recoveryUser, recoveryPw);
+	}
+
 	public void close() {
+		closed.set(true);
 		if(dataSource instanceof AutoCloseable) {
 			try {
 				((AutoCloseable) dataSource).close();

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/InternalJDBCConnectionProviderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/InternalJDBCConnectionProviderFactory.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/InternalJDBCConnectionProviderFactory.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/InternalJDBCConnectionProviderFactory.java Fri Dec 16 18:31:32 2016
@@ -26,17 +26,14 @@ import javax.sql.DataSource;
 import javax.sql.XADataSource;
 
 import org.osgi.service.jdbc.DataSourceFactory;
-import org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory;
 
-public interface InternalJDBCConnectionProviderFactory extends JDBCConnectionProviderFactory {
+public interface InternalJDBCConnectionProviderFactory {
 
-	@Override
 	AbstractJDBCConnectionProvider getProviderFor(DataSourceFactory dsf, Properties jdbcProperties,
 			Map<String, Object> resourceProviderProperties);
 
 	AbstractJDBCConnectionProvider getProviderFor(DataSource ds, Map<String, Object> resourceProviderProperties);
 
-	@Override
 	AbstractJDBCConnectionProvider getProviderFor(Driver driver, Properties jdbcProperties,
 			Map<String, Object> resourceProviderProperties);
 

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ResourceTrackingJDBCConnectionProviderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ResourceTrackingJDBCConnectionProviderFactory.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ResourceTrackingJDBCConnectionProviderFactory.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-common/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ResourceTrackingJDBCConnectionProviderFactory.java Fri Dec 16 18:31:32 2016
@@ -65,4 +65,14 @@ public class ResourceTrackingJDBCConnect
 		return doGetResult(() -> factory.getProviderFor(ds, 
 				resourceProviderProperties));
 	}
+
+	@Override
+	public void releaseProvider(JDBCConnectionProvider provider) {
+		if(provider instanceof AbstractJDBCConnectionProvider) {
+			release((AbstractJDBCConnectionProvider)provider);
+		} else {
+			throw new IllegalArgumentException(
+					"The supplied JDBCConnectionProvider was not created by this JDBCConnectionProviderFactory");
+		}
+	}
 }
\ No newline at end of file

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java Fri Dec 16 18:31:32 2016
@@ -22,6 +22,15 @@ import static java.util.Optional.ofNulla
 import static java.util.concurrent.TimeUnit.HOURS;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.osgi.service.jdbc.DataSourceFactory.JDBC_URL;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.CONNECTION_LIFETIME;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.CONNECTION_POOLING_ENABLED;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.CONNECTION_TIMEOUT;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.IDLE_TIMEOUT;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.LOCAL_ENLISTMENT_ENABLED;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.MAX_CONNECTIONS;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.MIN_CONNECTIONS;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.USE_DRIVER;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.XA_ENLISTMENT_ENABLED;
 
 import java.sql.Driver;
 import java.sql.SQLException;
@@ -37,12 +46,11 @@ import org.apache.aries.tx.control.jdbc.
 import org.apache.aries.tx.control.jdbc.common.impl.InternalJDBCConnectionProviderFactory;
 import org.osgi.service.jdbc.DataSourceFactory;
 import org.osgi.service.transaction.control.TransactionException;
-import org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory;
 
 import com.zaxxer.hikari.HikariConfig;
 import com.zaxxer.hikari.HikariDataSource;
 
-public class JDBCConnectionProviderFactoryImpl implements JDBCConnectionProviderFactory, InternalJDBCConnectionProviderFactory {
+public class JDBCConnectionProviderFactoryImpl implements InternalJDBCConnectionProviderFactory {
 
 	@Override
 	public AbstractJDBCConnectionProvider getProviderFor(DataSourceFactory dsf, Properties jdbcProperties,

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java Fri Dec 16 18:31:32 2016
@@ -38,6 +38,6 @@ public class JDBCConnectionProviderImpl
 	@Override
 	public Connection getResource(TransactionControl txControl)
 			throws TransactionException {
-		return new TxContextBindingConnection(txControl, dataSource , uuid);
+		return new TxContextBindingConnection(txControl, this , uuid);
 	}
 }

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java Fri Dec 16 18:31:32 2016
@@ -24,8 +24,7 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.UUID;
 
-import javax.sql.DataSource;
-
+import org.apache.aries.tx.control.jdbc.common.impl.AbstractJDBCConnectionProvider;
 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;
@@ -36,14 +35,14 @@ import org.osgi.service.transaction.cont
 
 public class TxContextBindingConnection extends ConnectionWrapper {
 
-	private final TransactionControl	txControl;
-	private final UUID					resourceId;
-	private final DataSource			dataSource;
+	private final TransactionControl				txControl;
+	private final UUID								resourceId;
+	private final AbstractJDBCConnectionProvider	provider;
 
 	public TxContextBindingConnection(TransactionControl txControl,
-			DataSource dataSource, UUID resourceId) {
+			AbstractJDBCConnectionProvider provider, UUID resourceId) {
 		this.txControl = txControl;
-		this.dataSource = dataSource;
+		this.provider = provider;
 		this.resourceId = resourceId;
 	}
 
@@ -53,7 +52,7 @@ public class TxContextBindingConnection
 		TransactionContext txContext = txControl.getCurrentContext();
 
 		if (txContext == null) {
-			throw new TransactionException("The resource " + dataSource
+			throw new TransactionException("The resource " + provider
 					+ " cannot be accessed outside of an active Transaction Context");
 		}
 
@@ -68,10 +67,10 @@ public class TxContextBindingConnection
 
 		try {
 			if (txContext.getTransactionStatus() == NO_TRANSACTION) {
-				toClose = dataSource.getConnection();
+				toClose = provider.getConnection();
 				toReturn = new ScopedConnectionWrapper(toClose);
 			} else if (txContext.supportsLocal()) {
-				toClose = dataSource.getConnection();
+				toClose = provider.getConnection();
 				toReturn = new TxConnectionWrapper(toClose);
 				txContext.registerLocalResource(getLocalResource(toClose));
 			} else {

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java Fri Dec 16 18:31:32 2016
@@ -30,6 +30,7 @@ import java.util.UUID;
 
 import javax.sql.DataSource;
 
+import org.apache.aries.tx.control.jdbc.common.impl.AbstractJDBCConnectionProvider;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -62,6 +63,8 @@ public class TxContextBindingConnectionT
 	UUID id = UUID.randomUUID();
 	
 	TxContextBindingConnection conn;
+
+	private AbstractJDBCConnectionProvider provider;
 	
 	@Before
 	public void setUp() throws SQLException {
@@ -72,7 +75,9 @@ public class TxContextBindingConnectionT
 		Mockito.when(context.getScopedValue(Mockito.any()))
 			.thenAnswer(i -> variables.get(i.getArguments()[0]));
 		
-		conn = new TxContextBindingConnection(control, dataSource, id);
+		provider = new JDBCConnectionProviderImpl(dataSource);
+		
+		conn = new TxContextBindingConnection(control, provider, id);
 	}
 	
 	private void setupNoTransaction() {
@@ -151,4 +156,12 @@ public class TxContextBindingConnectionT
 		conn.isValid(500);
 	}
 
+	@Test(expected=TransactionException.class)
+	public void testActiveTransactionClosedProvider() throws SQLException {
+		setupActiveTransaction();
+		
+		provider.close();
+		conn.isValid(500);
+	}
+
 }

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=1774648&r1=1774647&r2=1774648&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 Fri Dec 16 18:31:32 2016
@@ -22,6 +22,16 @@ import static java.util.Optional.ofNulla
 import static java.util.concurrent.TimeUnit.HOURS;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.osgi.service.jdbc.DataSourceFactory.JDBC_URL;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.CONNECTION_LIFETIME;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.CONNECTION_POOLING_ENABLED;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.CONNECTION_TIMEOUT;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.IDLE_TIMEOUT;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.LOCAL_ENLISTMENT_ENABLED;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.MAX_CONNECTIONS;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.MIN_CONNECTIONS;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.OSGI_RECOVERY_IDENTIFIER;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.USE_DRIVER;
+import static org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory.XA_ENLISTMENT_ENABLED;
 
 import java.sql.Driver;
 import java.sql.SQLException;
@@ -32,19 +42,19 @@ import java.util.concurrent.TimeUnit;
 import javax.sql.DataSource;
 import javax.sql.XADataSource;
 
+import org.apache.aries.tx.control.jdbc.common.impl.AbstractJDBCConnectionProvider;
 import org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource;
 import org.apache.aries.tx.control.jdbc.common.impl.InternalJDBCConnectionProviderFactory;
 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.JDBCConnectionProviderFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.zaxxer.hikari.HikariConfig;
 import com.zaxxer.hikari.HikariDataSource;
 
-public class JDBCConnectionProviderFactoryImpl implements JDBCConnectionProviderFactory, InternalJDBCConnectionProviderFactory {
+public class JDBCConnectionProviderFactoryImpl implements InternalJDBCConnectionProviderFactory {
 
 	private static final Logger LOG = LoggerFactory.getLogger(ManagedServiceFactoryImpl.class);
 	
@@ -91,7 +101,7 @@ public class JDBCConnectionProviderFacto
 	}
 
 	@Override
-	public JDBCConnectionProviderImpl getProviderFor(DataSource ds, Map<String, Object> resourceProviderProperties) {
+	public AbstractJDBCConnectionProvider getProviderFor(DataSource ds, Map<String, Object> resourceProviderProperties) {
 		boolean xaEnabled = toBoolean(resourceProviderProperties, XA_ENLISTMENT_ENABLED, true);
 		boolean localEnabled = toBoolean(resourceProviderProperties, LOCAL_ENLISTMENT_ENABLED, true);
 		
@@ -108,7 +118,7 @@ public class JDBCConnectionProviderFacto
 	}
 
 	@Override
-	public JDBCConnectionProviderImpl getProviderFor(Driver driver, Properties jdbcProperties, 
+	public AbstractJDBCConnectionProvider getProviderFor(Driver driver, Properties jdbcProperties, 
 			Map<String, Object> resourceProviderProperties) {
 		
 		boolean xaEnabled = toBoolean(resourceProviderProperties, XA_ENLISTMENT_ENABLED, false);
@@ -124,7 +134,7 @@ public class JDBCConnectionProviderFacto
 	}
 
 	@Override
-	public JDBCConnectionProviderImpl getProviderFor(XADataSource ds, Map<String, Object> resourceProviderProperties) {
+	public AbstractJDBCConnectionProvider getProviderFor(XADataSource ds, Map<String, Object> resourceProviderProperties) {
 		
 		boolean xaEnabled = toBoolean(resourceProviderProperties, XA_ENLISTMENT_ENABLED, true);
 		boolean localEnabled = toBoolean(resourceProviderProperties, LOCAL_ENLISTMENT_ENABLED, true);

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderImpl.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/JDBCConnectionProviderImpl.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderImpl.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/JDBCConnectionProviderImpl.java Fri Dec 16 18:31:32 2016
@@ -48,12 +48,7 @@ public class JDBCConnectionProviderImpl
 	@Override
 	public Connection getResource(TransactionControl txControl)
 			throws TransactionException {
-		return new XAEnabledTxContextBindingConnection(txControl, dataSource , uuid,
+		return new XAEnabledTxContextBindingConnection(txControl, this, uuid,
 				xaEnabled, localEnabled, recoveryIdentifier);
 	}
-
-	public DataSource getRawDataSource() {
-		return dataSource;
-	}
-
 }

Modified: aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/RecoverableXAResourceImpl.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/RecoverableXAResourceImpl.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/RecoverableXAResourceImpl.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-xa/src/main/java/org/apache/aries/tx/control/jdbc/xa/impl/RecoverableXAResourceImpl.java Fri Dec 16 18:31:32 2016
@@ -21,7 +21,6 @@ package org.apache.aries.tx.control.jdbc
 import java.sql.Connection;
 import java.sql.SQLException;
 
-import javax.sql.DataSource;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
@@ -53,13 +52,11 @@ public class RecoverableXAResourceImpl i
 
 	@Override
 	public XAResource getXAResource() throws Exception {
-		DataSource rawDataSource = providerImpl.getRawDataSource();
-
 		Connection recoveryConn;
 		if(recoveryUser != null) {
-			recoveryConn = rawDataSource.getConnection(recoveryUser, recoveryPw);
+			recoveryConn = providerImpl.getConnection(recoveryUser, recoveryPw);
 		} else {
-			recoveryConn = rawDataSource.getConnection();
+			recoveryConn = providerImpl.getConnection();
 		}
 		
 		return new CloseableXAResource(recoveryConn);

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=1774648&r1=1774647&r2=1774648&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 Fri Dec 16 18:31:32 2016
@@ -24,9 +24,9 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.UUID;
 
-import javax.sql.DataSource;
 import javax.transaction.xa.XAResource;
 
+import org.apache.aries.tx.control.jdbc.common.impl.AbstractJDBCConnectionProvider;
 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;
@@ -38,18 +38,18 @@ import org.osgi.service.transaction.cont
 
 public class XAEnabledTxContextBindingConnection extends ConnectionWrapper {
 
-	private final TransactionControl	txControl;
-	private final UUID					resourceId;
-	private final DataSource			dataSource;
-	private final boolean				xaEnabled;
-	private final boolean				localEnabled;
-	private final String				recoveryIdentifier;
+	private final TransactionControl				txControl;
+	private final UUID								resourceId;
+	private final AbstractJDBCConnectionProvider	provider;
+	private final boolean							xaEnabled;
+	private final boolean							localEnabled;
+	private final String							recoveryIdentifier;
 
 	public XAEnabledTxContextBindingConnection(TransactionControl txControl,
-			DataSource dataSource, UUID resourceId, boolean xaEnabled, boolean localEnabled,
+			AbstractJDBCConnectionProvider provider, UUID resourceId, boolean xaEnabled, boolean localEnabled,
 			String recoveryIdentifier) {
 		this.txControl = txControl;
-		this.dataSource = dataSource;
+		this.provider = provider;
 		this.resourceId = resourceId;
 		this.xaEnabled = xaEnabled;
 		this.localEnabled = localEnabled;
@@ -62,7 +62,7 @@ public class XAEnabledTxContextBindingCo
 		TransactionContext txContext = txControl.getCurrentContext();
 
 		if (txContext == null) {
-			throw new TransactionException("The resource " + dataSource
+			throw new TransactionException("The resource " + provider
 					+ " cannot be accessed outside of an active Transaction Context");
 		}
 
@@ -77,14 +77,14 @@ public class XAEnabledTxContextBindingCo
 
 		try {
 			if (txContext.getTransactionStatus() == NO_TRANSACTION) {
-				toClose = dataSource.getConnection();
+				toClose = provider.getConnection();
 				toReturn = new ScopedConnectionWrapper(toClose);
 			} else if (txContext.supportsXA() && xaEnabled) {
-				toClose = dataSource.getConnection();
+				toClose = provider.getConnection();
 				toReturn = new TxConnectionWrapper(toClose);
 				txContext.registerXAResource(getXAResource(toClose), recoveryIdentifier);
 			} else if (txContext.supportsLocal() && localEnabled) {
-				toClose = dataSource.getConnection();
+				toClose = provider.getConnection();
 				toReturn = new TxConnectionWrapper(toClose);
 				txContext.registerLocalResource(getLocalResource(toClose));
 			} else {

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=1774648&r1=1774647&r2=1774648&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 Fri Dec 16 18:31:32 2016
@@ -33,6 +33,7 @@ import javax.sql.XAConnection;
 import javax.sql.XADataSource;
 import javax.transaction.xa.XAResource;
 
+import org.apache.aries.tx.control.jdbc.common.impl.AbstractJDBCConnectionProvider;
 import org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper;
 import org.junit.Before;
 import org.junit.Test;
@@ -74,6 +75,9 @@ public class XAEnabledTxContextBindingCo
 	
 	UUID id = UUID.randomUUID();
 	
+	
+	AbstractJDBCConnectionProvider localProvider;
+	AbstractJDBCConnectionProvider xaProvider;
 	XAEnabledTxContextBindingConnection localConn;
 	XAEnabledTxContextBindingConnection xaConn;
 	
@@ -90,8 +94,13 @@ public class XAEnabledTxContextBindingCo
 		Mockito.when(xaMock.getConnection()).thenReturn(rawConnection);
 		Mockito.when(xaMock.getXAResource()).thenReturn(xaResource);
 		
-		localConn = new XAEnabledTxContextBindingConnection(control, dataSource, id, false, true, null);
-		xaConn = new XAEnabledTxContextBindingConnection(control, new XADataSourceMapper(xaDataSource), 
+		localProvider = new JDBCConnectionProviderImpl(dataSource, false, true, null);
+		xaProvider = new JDBCConnectionProviderImpl(new XADataSourceMapper(xaDataSource), 
+				true, false, null);
+		
+		localConn = new XAEnabledTxContextBindingConnection(control, localProvider, 
+				id, false, true, null);
+		xaConn = new XAEnabledTxContextBindingConnection(control, xaProvider, 
 				id, true, false, null);
 	}
 	
@@ -194,6 +203,14 @@ public class XAEnabledTxContextBindingCo
 		Mockito.when(context.supportsLocal()).thenReturn(false);
 		localConn.isValid(500);
 	}
+
+	@Test(expected=TransactionException.class)
+	public void testLocalResourceProviderClosed() throws SQLException {
+		setupLocalTransaction();
+		
+		localProvider.close();
+		localConn.isValid(500);
+	}
 	
 	@Test(expected=TransactionException.class)
 	public void testLocalConnWithXATransaction() throws SQLException {
@@ -239,5 +256,14 @@ public class XAEnabledTxContextBindingCo
 		
 		xaConn.isValid(500);
 	}
+
+	@Test(expected=TransactionException.class)
+	public void testRemoteResourceProviderClosed() throws SQLException {
+		setupXATransaction();
+		
+		xaProvider.close();
+		
+		xaConn.isValid(500);
+	}
 
 }

Modified: aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/AbstractJPAEntityManagerProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/AbstractJPAEntityManagerProvider.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/AbstractJPAEntityManagerProvider.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/AbstractJPAEntityManagerProvider.java Fri Dec 16 18:31:32 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.aries.tx.control.jpa.common.impl;
 
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 
@@ -31,10 +33,12 @@ public abstract class AbstractJPAEntityM
 
 	private static final Logger LOG = LoggerFactory.getLogger(AbstractJPAEntityManagerProvider.class);
 	
-	protected final EntityManagerFactory emf;
+	private final EntityManagerFactory emf;
 
 	private final Runnable onClose;
 	
+	private final AtomicBoolean closed = new AtomicBoolean(false);
+	
 	public AbstractJPAEntityManagerProvider(EntityManagerFactory emf, Runnable onClose) {
 		this.emf = emf;
 		this.onClose = onClose;
@@ -45,7 +49,13 @@ public abstract class AbstractJPAEntityM
 			throws TransactionException;
 
 	
+	public EntityManager createEntityManager() {
+		if(closed.get()) throw new IllegalStateException("This resource provider is no longer in use");
+		return emf.createEntityManager();
+	}
+
 	public void close() {
+		closed.set(true);
 		if(onClose != null) {
 			try {
 				onClose.run();

Modified: aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/InternalJPAEntityManagerProviderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/InternalJPAEntityManagerProviderFactory.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/InternalJPAEntityManagerProviderFactory.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/InternalJPAEntityManagerProviderFactory.java Fri Dec 16 18:31:32 2016
@@ -23,15 +23,12 @@ import java.util.Map;
 import javax.persistence.EntityManagerFactory;
 
 import org.osgi.service.jpa.EntityManagerFactoryBuilder;
-import org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory;
 
-public interface InternalJPAEntityManagerProviderFactory extends JPAEntityManagerProviderFactory {
+public interface InternalJPAEntityManagerProviderFactory {
 
-	@Override
 	AbstractJPAEntityManagerProvider getProviderFor(EntityManagerFactoryBuilder emfb, 
 			Map<String, Object> jpaProperties, Map<String, Object> resourceProviderProperties);
 
-	@Override
 	AbstractJPAEntityManagerProvider getProviderFor(EntityManagerFactory emf,
 			Map<String, Object> resourceProviderProperties);
 

Modified: aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ResourceTrackingJPAEntityManagerProviderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ResourceTrackingJPAEntityManagerProviderFactory.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ResourceTrackingJPAEntityManagerProviderFactory.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-common/src/main/java/org/apache/aries/tx/control/jpa/common/impl/ResourceTrackingJPAEntityManagerProviderFactory.java Fri Dec 16 18:31:32 2016
@@ -49,4 +49,14 @@ public class ResourceTrackingJPAEntityMa
 		return doGetResult(() -> factory.getProviderFor(emf, 
 				resourceProviderProperties));
 	}
+
+	@Override
+	public void releaseProvider(JPAEntityManagerProvider provider) {
+		if(provider instanceof AbstractJPAEntityManagerProvider) {
+			release((AbstractJPAEntityManagerProvider)provider);
+		} else {
+			throw new IllegalArgumentException(
+					"The supplied JPAEntityManagerProvider was not created by this JPAEntityManagerProviderFactory");
+		}
+	}
 }
\ No newline at end of file

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=1774648&r1=1774647&r2=1774648&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 Fri Dec 16 18:31:32 2016
@@ -20,6 +20,8 @@ package org.apache.aries.tx.control.jpa.
 
 import static java.util.Optional.ofNullable;
 import static javax.persistence.spi.PersistenceUnitTransactionType.RESOURCE_LOCAL;
+import static org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory.LOCAL_ENLISTMENT_ENABLED;
+import static org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory.XA_ENLISTMENT_ENABLED;
 
 import java.util.Map;
 

Modified: aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderImpl.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/JPAEntityManagerProviderImpl.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderImpl.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/JPAEntityManagerProviderImpl.java Fri Dec 16 18:31:32 2016
@@ -37,6 +37,6 @@ public class JPAEntityManagerProviderImp
 
 	@Override
 	public EntityManager getResource(TransactionControl txControl) throws TransactionException {
-		return new TxContextBindingEntityManager(txControl, emf, uuid);
+		return new TxContextBindingEntityManager(txControl, this, uuid);
 	}
 }

Modified: aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManager.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/TxContextBindingEntityManager.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManager.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-local/src/main/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManager.java Fri Dec 16 18:31:32 2016
@@ -23,9 +23,9 @@ import static org.osgi.service.transacti
 import java.util.UUID;
 
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceException;
 
+import org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider;
 import org.apache.aries.tx.control.jpa.common.impl.EntityManagerWrapper;
 import org.apache.aries.tx.control.jpa.common.impl.ScopedEntityManagerWrapper;
 import org.apache.aries.tx.control.jpa.common.impl.TxEntityManagerWrapper;
@@ -36,14 +36,14 @@ import org.osgi.service.transaction.cont
 
 public class TxContextBindingEntityManager extends EntityManagerWrapper {
 
-	private final TransactionControl	txControl;
-	private final UUID					resourceId;
-	private final EntityManagerFactory	emf;
+	private final TransactionControl				txControl;
+	private final UUID								resourceId;
+	private final AbstractJPAEntityManagerProvider	provider;
 
 	public TxContextBindingEntityManager(TransactionControl txControl,
-			EntityManagerFactory emf, UUID resourceId) {
+			AbstractJPAEntityManagerProvider provider, UUID resourceId) {
 		this.txControl = txControl;
-		this.emf = emf;
+		this.provider = provider;
 		this.resourceId = resourceId;
 	}
 
@@ -53,7 +53,7 @@ public class TxContextBindingEntityManag
 		TransactionContext txContext = txControl.getCurrentContext();
 
 		if (txContext == null) {
-			throw new TransactionException("The resource " + emf
+			throw new TransactionException("The resource " + provider
 					+ " cannot be accessed outside of an active Transaction Context");
 		}
 
@@ -68,10 +68,10 @@ public class TxContextBindingEntityManag
 
 		try {
 			if (txContext.getTransactionStatus() == NO_TRANSACTION) {
-				toClose = emf.createEntityManager();
+				toClose = provider.createEntityManager();
 				toReturn = new ScopedEntityManagerWrapper(toClose);
 			} else if (txContext.supportsLocal()) {
-				toClose = emf.createEntityManager();
+				toClose = provider.createEntityManager();
 				toReturn = new TxEntityManagerWrapper(toClose);
 				txContext.registerLocalResource(getLocalResource(toClose));
 				toClose.getTransaction().begin();

Modified: aries/trunk/tx-control/tx-control-provider-jpa-local/src/test/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManagerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-local/src/test/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManagerTest.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-local/src/test/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManagerTest.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-local/src/test/java/org/apache/aries/tx/control/jpa/local/impl/TxContextBindingEntityManagerTest.java Fri Dec 16 18:31:32 2016
@@ -32,6 +32,7 @@ import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
 
+import org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -66,6 +67,8 @@ public class TxContextBindingEntityManag
 	
 	UUID id = UUID.randomUUID();
 	
+	AbstractJPAEntityManagerProvider provider;
+	
 	TxContextBindingEntityManager em;
 	
 	@Before
@@ -79,7 +82,9 @@ public class TxContextBindingEntityManag
 		Mockito.when(context.getScopedValue(Mockito.any()))
 			.thenAnswer(i -> variables.get(i.getArguments()[0]));
 		
-		em = new TxContextBindingEntityManager(control, emf, id);
+		provider = new JPAEntityManagerProviderImpl(emf, null);
+		
+		em = new TxContextBindingEntityManager(control, provider, id);
 	}
 	
 	private void setupNoTransaction() {
@@ -167,4 +172,13 @@ public class TxContextBindingEntityManag
 		em.isOpen();
 	}
 
+	@Test(expected=TransactionException.class)
+	public void testClosedProvider() throws SQLException {
+		setupActiveTransaction();
+		
+		provider.close();
+		
+		em.isOpen();
+	}
+
 }

Modified: 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=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java Fri Dec 16 18:31:32 2016
@@ -21,6 +21,9 @@ package org.apache.aries.tx.control.jpa.
 import static java.util.Optional.ofNullable;
 import static javax.persistence.spi.PersistenceUnitTransactionType.JTA;
 import static org.osgi.service.transaction.control.TransactionStatus.NO_TRANSACTION;
+import static org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory.LOCAL_ENLISTMENT_ENABLED;
+import static org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory.PRE_ENLISTED_DB_CONNECTION;
+import static org.osgi.service.transaction.control.jpa.JPAEntityManagerProviderFactory.XA_ENLISTMENT_ENABLED;
 
 import java.io.PrintWriter;
 import java.sql.Connection;

Modified: 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=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderImpl.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderImpl.java Fri Dec 16 18:31:32 2016
@@ -41,6 +41,6 @@ public class JPAEntityManagerProviderImp
 
 	@Override
 	public EntityManager getResource(TransactionControl txControl) throws TransactionException {
-		return new XATxContextBindingEntityManager(txControl, emf, uuid, tx);
+		return new XATxContextBindingEntityManager(txControl, this, uuid, tx);
 	}
 }

Modified: aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManager.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/XATxContextBindingEntityManager.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManager.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManager.java Fri Dec 16 18:31:32 2016
@@ -23,9 +23,9 @@ import static org.osgi.service.transacti
 import java.util.UUID;
 
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceException;
 
+import org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider;
 import org.apache.aries.tx.control.jpa.common.impl.EntityManagerWrapper;
 import org.apache.aries.tx.control.jpa.common.impl.ScopedEntityManagerWrapper;
 import org.apache.aries.tx.control.jpa.common.impl.TxEntityManagerWrapper;
@@ -35,16 +35,17 @@ import org.osgi.service.transaction.cont
 
 public class XATxContextBindingEntityManager extends EntityManagerWrapper {
 
-	private final TransactionControl	txControl;
-	private final UUID					resourceId;
-	private final EntityManagerFactory	emf;
-	private final ThreadLocal<TransactionControl> commonTxStore;
+	private final TransactionControl				txControl;
+	private final UUID								resourceId;
+	private final AbstractJPAEntityManagerProvider	provider;
+	private final ThreadLocal<TransactionControl>	commonTxStore;
 	
 
 	public XATxContextBindingEntityManager(TransactionControl txControl,
-			EntityManagerFactory emf, UUID resourceId, ThreadLocal<TransactionControl> commonTxStore) {
+			AbstractJPAEntityManagerProvider provider, UUID resourceId, 
+			ThreadLocal<TransactionControl> commonTxStore) {
 		this.txControl = txControl;
-		this.emf = emf;
+		this.provider = provider;
 		this.resourceId = resourceId;
 		this.commonTxStore = commonTxStore;
 	}
@@ -55,7 +56,7 @@ public class XATxContextBindingEntityMan
 		TransactionContext txContext = txControl.getCurrentContext();
 
 		if (txContext == null) {
-			throw new TransactionException("The resource " + emf
+			throw new TransactionException("The resource " + provider
 					+ " cannot be accessed outside of an active Transaction Context");
 		}
 
@@ -73,10 +74,10 @@ public class XATxContextBindingEntityMan
 
 		try {
 			if (txContext.getTransactionStatus() == NO_TRANSACTION) {
-				toClose = emf.createEntityManager();
+				toClose = provider.createEntityManager();
 				toReturn = new ScopedEntityManagerWrapper(toClose);
 			} else if (txContext.supportsXA()) {
-				toClose = emf.createEntityManager();
+				toClose = provider.createEntityManager();
 				toReturn = new TxEntityManagerWrapper(toClose);
 				toClose.joinTransaction();
 			} else {

Modified: aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManagerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManagerTest.java?rev=1774648&r1=1774647&r2=1774648&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManagerTest.java (original)
+++ aries/trunk/tx-control/tx-control-provider-jpa-xa/src/test/java/org/apache/aries/tx/control/jpa/xa/impl/XATxContextBindingEntityManagerTest.java Fri Dec 16 18:31:32 2016
@@ -38,6 +38,7 @@ import javax.sql.XAConnection;
 import javax.transaction.xa.XAResource;
 
 import org.apache.aries.tx.control.jdbc.xa.connection.impl.XAConnectionWrapper;
+import org.apache.aries.tx.control.jpa.common.impl.AbstractJPAEntityManagerProvider;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -76,6 +77,8 @@ public class XATxContextBindingEntityMan
 	
 	ThreadLocal<TransactionControl> commonTxControl = new ThreadLocal<>();
 	
+	AbstractJPAEntityManagerProvider provider;
+	
 	@Before
 	public void setUp() throws SQLException {
 		Mockito.when(emf.createEntityManager()).thenReturn(rawEm).thenReturn(null);
@@ -85,7 +88,9 @@ public class XATxContextBindingEntityMan
 		Mockito.when(context.getScopedValue(Mockito.any()))
 			.thenAnswer(i -> variables.get(i.getArguments()[0]));
 		
-		em = new XATxContextBindingEntityManager(control, emf, id, commonTxControl);
+		provider = new JPAEntityManagerProviderImpl(emf, commonTxControl, null);
+		
+		em = new XATxContextBindingEntityManager(control, provider, id, commonTxControl);
 	}
 	
 	private void setupNoTransaction() {
@@ -225,6 +230,14 @@ public class XATxContextBindingEntityMan
 		em.isOpen();
 	}
 
+	@Test(expected=TransactionException.class)
+	public void testResourceProviderClosed() throws SQLException {
+		setupActiveTransaction();
+		
+		provider.close();
+		em.isOpen();
+	}
+
 	@Test
 	public void testActiveTransactionWithPreviousCommonTxControl() throws SQLException {
 		



Mime
View raw message