branch feature/661_do_not_force_pools_in_classpath created (now c091b194)
This is an automated email from the git hooks/post-receive script. New change to branch feature/661_do_not_force_pools_in_classpath in repository topia. See https://gitlab.nuiton.org/nuiton/topia.git at c091b194 Make connection pools runtime dependencies thus allowing exlusion from class-path for final apps This branch includes the following new commits: new c091b194 Make connection pools runtime dependencies thus allowing exlusion from class-path for final apps The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit c091b19497d1205454c77c280b36c61d8e9c6dc5 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue May 15 17:06:07 2018 +0200 Make connection pools runtime dependencies thus allowing exlusion from class-path for final apps refs #661 -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/661_do_not_force_pools_in_classpath in repository topia. See https://gitlab.nuiton.org/nuiton/topia.git commit c091b19497d1205454c77c280b36c61d8e9c6dc5 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue May 15 17:06:07 2018 +0200 Make connection pools runtime dependencies thus allowing exlusion from class-path for final apps refs #661 --- pom.xml | 2 ++ .../persistence/internal/HibernateProvider.java | 8 +++++-- .../internal/HibernateProviderTest.java | 27 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 25f9087c..d0d892de 100644 --- a/pom.xml +++ b/pom.xml @@ -330,12 +330,14 @@ <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>${hibernateVersion}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-hikaricp</artifactId> <version>${hibernateVersion}</version> + <scope>runtime</scope> </dependency> <dependency> diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/HibernateProvider.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/HibernateProvider.java index aa02e5fd..8b30c333 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/HibernateProvider.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/HibernateProvider.java @@ -71,6 +71,10 @@ public class HibernateProvider { private static final Log log = LogFactory.getLog(HibernateProvider.class); + static final String HIKARI_CP_HIBERNATE_CONNECTION_PROVIDER_CLASS_NAME = "org.hibernate.hikaricp.internal.HikariCPConnectionProvider"; + + static final String C3P0_HIBERNATE_CONNECTION_PROVIDER_CLASS_NAME = "org.hibernate.c3p0.internal.C3P0ConnectionProvider"; + protected SessionFactory hibernateSessionFactory; protected Configuration hibernateConfiguration; @@ -139,9 +143,9 @@ public class HibernateProvider { // using c3p0 with default configuration if (topiaConfiguration.isUseHikariForJdbcConnectionPooling()) { - properties.put(AvailableSettings.CONNECTION_PROVIDER, org.hibernate.hikaricp.internal.HikariCPConnectionProvider.class.getName()); + properties.put(AvailableSettings.CONNECTION_PROVIDER, HIKARI_CP_HIBERNATE_CONNECTION_PROVIDER_CLASS_NAME); } else { - properties.put(AvailableSettings.CONNECTION_PROVIDER, org.hibernate.c3p0.internal.C3P0ConnectionProvider.class.getName()); + properties.put(AvailableSettings.CONNECTION_PROVIDER, C3P0_HIBERNATE_CONNECTION_PROVIDER_CLASS_NAME); properties.put(AvailableSettings.C3P0_MIN_SIZE, 5); properties.put(AvailableSettings.C3P0_MAX_SIZE, 20); properties.put(AvailableSettings.C3P0_TIMEOUT, 1800); diff --git a/topia-persistence/src/test/java/org/nuiton/topia/persistence/internal/HibernateProviderTest.java b/topia-persistence/src/test/java/org/nuiton/topia/persistence/internal/HibernateProviderTest.java new file mode 100644 index 00000000..d16e1b24 --- /dev/null +++ b/topia-persistence/src/test/java/org/nuiton/topia/persistence/internal/HibernateProviderTest.java @@ -0,0 +1,27 @@ +package org.nuiton.topia.persistence.internal; + +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.junit.Assert; +import org.junit.Test; + +public class HibernateProviderTest { + + @Test + public void testHikariCpHibernateConnectionProviderClassName() { + testProviderClassName(HibernateProvider.HIKARI_CP_HIBERNATE_CONNECTION_PROVIDER_CLASS_NAME); + } + + @Test + public void testC3P0HibernateConnectionProviderClassName() { + testProviderClassName(HibernateProvider.C3P0_HIBERNATE_CONNECTION_PROVIDER_CLASS_NAME); + } + + private void testProviderClassName(String connectionProviderClassName) { + try { + Class<?> connectionProviderClass = Class.forName(connectionProviderClassName); + Assert.assertTrue(connectionProviderClassName + " must be a subclass of " + ConnectionProvider.class, ConnectionProvider.class.isAssignableFrom(connectionProviderClass)); + } catch (ClassNotFoundException e) { + Assert.fail(connectionProviderClassName + " should be available in classpath at runtime, maybe the constant is wrong and the library moved the connection provider"); + } + } +} \ No newline at end of file -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm