diff --git a/hibernate-proxool/hibernate-proxool.gradle b/hibernate-proxool/hibernate-proxool.gradle index a6358c1721..1727fe9103 100644 --- a/hibernate-proxool/hibernate-proxool.gradle +++ b/hibernate-proxool/hibernate-proxool.gradle @@ -4,4 +4,5 @@ dependencies { compile( project( ':hibernate-core' ) ) compile( [group: 'proxool', name: 'proxool', version: '0.8.3'] ) testCompile( project(':hibernate-core').sourceSets.test.classes ) + testRuntime( libraries.h2 ) } diff --git a/hibernate-proxool/src/main/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProvider.java b/hibernate-proxool/src/main/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProvider.java index 63d092ddc8..43c111220c 100644 --- a/hibernate-proxool/src/main/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProvider.java +++ b/hibernate-proxool/src/main/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProvider.java @@ -202,7 +202,12 @@ public void close() throws HibernateException { // We have created the pool ourselves, so shut it down try { - ProxoolFacade.removeConnectionPool(proxoolAlias.substring(PROXOOL_JDBC_STEM.length())); + if ( ProxoolFacade.getAliases().length == 1 ) { + ProxoolFacade.shutdown( 0 ); + } + else { + ProxoolFacade.removeConnectionPool(proxoolAlias.substring(PROXOOL_JDBC_STEM.length())); + } } catch (Exception e) { // If you're closing down the ConnectionProvider chances are an diff --git a/hibernate-proxool/src/test/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProviderTest.java b/hibernate-proxool/src/test/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProviderTest.java new file mode 100644 index 0000000000..77719b23bc --- /dev/null +++ b/hibernate-proxool/src/test/java/org/hibernate/service/jdbc/connections/internal/ProxoolConnectionProviderTest.java @@ -0,0 +1,78 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat, Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.service.jdbc.connections.internal; + +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +import org.hibernate.cfg.Environment; +import org.logicalcobwebs.proxool.ProxoolFacade; + +import junit.framework.TestCase; + +/** + * Test to verify connection pools are closed, and that only the managed one is closed. + * @author Sanne Grinovero + */ +public class ProxoolConnectionProviderTest extends TestCase { + + public void testPoolsClosed() { + assertDefinedPools(); // zero-length-vararg used as parameter + + ProxoolConnectionProvider providerOne = new ProxoolConnectionProvider(); + providerOne.configure( getPoolConfigurarion( "pool-one" ) ); + assertDefinedPools( "pool-one" ); + + ProxoolConnectionProvider providerTwo = new ProxoolConnectionProvider(); + providerTwo.configure( getPoolConfigurarion( "pool-two" ) ); + assertDefinedPools( "pool-one", "pool-two" ); + + providerOne.close(); + assertDefinedPools( "pool-two" ); + + providerTwo.close(); + assertDefinedPools(); + } + + private void assertDefinedPools(String... expectedPoolNames) { + List aliases = Arrays.asList( ProxoolFacade.getAliases() ); + assertEquals( expectedPoolNames.length, aliases.size() ); + for (String poolName : expectedPoolNames) { + assertTrue( "pool named " + poolName + " missing", aliases.contains( poolName ) ); + } + } + + /** + * @param pool name + * @return his configuration - see src/tests/resources for matches + */ + private Properties getPoolConfigurarion(String poolName) { + Properties cfg = new Properties(); + cfg.setProperty( Environment.PROXOOL_POOL_ALIAS, poolName ); + cfg.setProperty( Environment.PROXOOL_PROPERTIES, poolName + ".properties" ); + return cfg; + } + +} diff --git a/hibernate-proxool/src/test/resources/pool-one.properties b/hibernate-proxool/src/test/resources/pool-one.properties new file mode 100644 index 0000000000..abaee38558 --- /dev/null +++ b/hibernate-proxool/src/test/resources/pool-one.properties @@ -0,0 +1,7 @@ +jdbc-0.proxool.alias=pool-one +jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE +jdbc-0.proxool.driver-class=org.h2.Driver +jdbc-0.user=sa +jdbc-0.password= +jdbc-0.proxool.maximum-connection-count=2 +jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE \ No newline at end of file diff --git a/hibernate-proxool/src/test/resources/pool-two.properties b/hibernate-proxool/src/test/resources/pool-two.properties new file mode 100644 index 0000000000..c087d2bb15 --- /dev/null +++ b/hibernate-proxool/src/test/resources/pool-two.properties @@ -0,0 +1,7 @@ +jdbc-0.proxool.alias=pool-two +jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE +jdbc-0.proxool.driver-class=org.h2.Driver +jdbc-0.user=sa +jdbc-0.password= +jdbc-0.proxool.maximum-connection-count=2 +jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE \ No newline at end of file