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();
}
}
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();
}
}
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"));
}
}
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"));
}
}
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);
}
Aggregations