Search in sources :

Example 6 with ConnectionProviderJdbcConnectionAccess

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

the class ServiceBootstrappingTest method testBuildWithServiceOverride.

@Test
public void testBuildWithServiceOverride() {
    StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(ConnectionProviderBuilder.getConnectionProviderProperties()).build();
    Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
    props.setProperty(Environment.DIALECT, H2Dialect.class.getName());
    try {
        JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(DriverManagerConnectionProviderImpl.class));
    } finally {
        serviceRegistry.destroy();
    }
    try {
        serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(props).addService(ConnectionProvider.class, new UserSuppliedConnectionProviderImpl()).build();
        JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
        assertTrue(jdbcServices.getDialect() instanceof H2Dialect);
        ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
        assertTrue(connectionAccess.getConnectionProvider().isUnwrappableAs(UserSuppliedConnectionProviderImpl.class));
    } finally {
        serviceRegistry.destroy();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) UserSuppliedConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl) 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) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) 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