Search in sources :

Example 1 with ConnectionProviderJdbcConnectionAccess

use of org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess in project hibernate-orm by hibernate.

the class ServiceBootstrappingTest method testBuildWithLogging.

@Test
public void testBuildWithLogging() {
    Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
    props.put(Environment.SHOW_SQL, "true");
    StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(props).build();
    try {
        JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(DriverManagerConnectionProviderImpl.class));
        assertTrue(jdbcServices.getSqlStatementLogger().isLogToStdout());
    } finally {
        serviceRegistry.destroy();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) H2Dialect(org.hibernate.dialect.H2Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) Properties(java.util.Properties) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) Test(org.junit.Test)

Example 2 with ConnectionProviderJdbcConnectionAccess

use of org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess in project hibernate-orm by hibernate.

the class ServiceBootstrappingTest method testBasicBuild.

@Test
public void testBasicBuild() {
    // this test requires that SHOW_SQL property isn't passed from the outside (eg. via Gradle)
    final String showSqlPropertyFromOutside = System.getProperty(Environment.SHOW_SQL);
    Assume.assumeFalse("true".equals(showSqlPropertyFromOutside));
    final StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(ConnectionProviderBuilder.getConnectionProviderProperties()).build();
    try {
        final JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(DriverManagerConnectionProviderImpl.class));
        assertFalse(jdbcServices.getSqlStatementLogger().isLogToStdout());
    } finally {
        serviceRegistry.destroy();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) H2Dialect(org.hibernate.dialect.H2Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) Test(org.junit.Test)

Example 3 with ConnectionProviderJdbcConnectionAccess

use of org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess in project hibernate-orm by hibernate.

the class AgroalConnectionProviderTest method testAgroalConnectionProvider.

@Test
public void testAgroalConnectionProvider() throws Exception {
    JdbcServices jdbcServices = serviceRegistry().getService(JdbcServices.class);
    ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
    assertTyping(AgroalConnectionProvider.class, connectionAccess.getConnectionProvider());
    AgroalConnectionProvider agroalConnectionProvider = (AgroalConnectionProvider) connectionAccess.getConnectionProvider();
    // For simplicity's sake, using the following in hibernate.properties:
    // hibernate.agroal.maxSize 2
    // hibernate.agroal.minSize 2
    List<Connection> conns = new ArrayList<>();
    for (int i = 0; i < 2; i++) {
        Connection conn = agroalConnectionProvider.getConnection();
        assertNotNull(conn);
        assertFalse(conn.isClosed());
        conns.add(conn);
    }
    try {
        agroalConnectionProvider.getConnection();
        fail("SQLException expected -- no more connections should have been available in the pool.");
    } catch (SQLException e) {
        // expected
        assertTrue(e.getMessage().contains("timeout"));
    }
    for (Connection conn : conns) {
        agroalConnectionProvider.closeConnection(conn);
        assertTrue(conn.isClosed());
    }
    releaseSessionFactory();
    try {
        agroalConnectionProvider.getConnection();
        fail("Exception expected -- the pool should have been shutdown.");
    } catch (Exception e) {
        // expected
        assertTrue(e.getMessage().contains("closed"));
    }
}
Also used : AgroalConnectionProvider(org.hibernate.agroal.internal.AgroalConnectionProvider) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) SQLException(java.sql.SQLException) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) Test(org.junit.Test)

Example 4 with ConnectionProviderJdbcConnectionAccess

use of org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess in project hibernate-orm by hibernate.

the class HikariCPConnectionProviderTest method testHikariCPConnectionProvider.

@Test
public void testHikariCPConnectionProvider() throws Exception {
    JdbcServices jdbcServices = serviceRegistry().getService(JdbcServices.class);
    ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
    assertTyping(HikariCPConnectionProvider.class, connectionAccess.getConnectionProvider());
    HikariCPConnectionProvider hikariCP = (HikariCPConnectionProvider) connectionAccess.getConnectionProvider();
    // For simplicity's sake, using the following in hibernate.properties:
    // hibernate.hikari.minimumPoolSize 2
    // hibernate.hikari.maximumPoolSize 2
    final List<Connection> conns = new ArrayList<Connection>();
    for (int i = 0; i < 2; i++) {
        Connection conn = hikariCP.getConnection();
        assertNotNull(conn);
        assertFalse(conn.isClosed());
        conns.add(conn);
    }
    try {
        hikariCP.getConnection();
        fail("SQLException expected -- no more connections should have been available in the pool.");
    } catch (SQLException e) {
        // expected
        assertTrue(e.getMessage().contains("Connection is not available, request timed out after"));
    }
    for (Connection conn : conns) {
        hikariCP.closeConnection(conn);
        assertTrue(conn.isClosed());
    }
    releaseSessionFactory();
    try {
        hikariCP.getConnection();
        fail("Exception expected -- the pool should have been shutdown.");
    } catch (Exception e) {
        // expected
        assertTrue(e.getMessage().contains("has been closed"));
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) SQLException(java.sql.SQLException) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) HikariCPConnectionProvider(org.hibernate.hikaricp.internal.HikariCPConnectionProvider) Test(org.junit.Test)

Example 5 with ConnectionProviderJdbcConnectionAccess

use of org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess in project hibernate-orm by hibernate.

the class C3P0ConnectionProviderTest method testC3P0isDefaultWhenThereIsC3P0Properties.

@Test
public void testC3P0isDefaultWhenThereIsC3P0Properties() {
    JdbcServices jdbcServices = serviceRegistry().getService(JdbcServices.class);
    ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
    assertTrue(connectionAccess.getConnectionProvider() instanceof C3P0ConnectionProvider);
}
Also used : C3P0ConnectionProvider(org.hibernate.c3p0.internal.C3P0ConnectionProvider) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) Test(org.junit.Test)

Aggregations

ConnectionProviderJdbcConnectionAccess (org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess)6 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)6 Test (org.junit.Test)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 StandardServiceRegistryImpl (org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)3 H2Dialect (org.hibernate.dialect.H2Dialect)3 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 AgroalConnectionProvider (org.hibernate.agroal.internal.AgroalConnectionProvider)1 C3P0ConnectionProvider (org.hibernate.c3p0.internal.C3P0ConnectionProvider)1 UserSuppliedConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl)1 ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)1 HikariCPConnectionProvider (org.hibernate.hikaricp.internal.HikariCPConnectionProvider)1