Search in sources :

Example 1 with UserSuppliedConnectionProviderImpl

use of org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl 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

Properties (java.util.Properties)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 StandardServiceRegistryImpl (org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)1 H2Dialect (org.hibernate.dialect.H2Dialect)1 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)1 UserSuppliedConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl)1 ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)1 ConnectionProviderJdbcConnectionAccess (org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 Test (org.junit.Test)1