Search in sources :

Example 6 with JdbcServices

use of org.hibernate.engine.jdbc.spi.JdbcServices 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)

Example 7 with JdbcServices

use of org.hibernate.engine.jdbc.spi.JdbcServices 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

JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)7 Test (org.junit.Test)7 ConnectionProviderJdbcConnectionAccess (org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess)5 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 StandardServiceRegistryImpl (org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)3 H2Dialect (org.hibernate.dialect.H2Dialect)3 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 JdbcConnectionAccess (org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess)2 SqlExceptionHelper (org.hibernate.engine.jdbc.spi.SqlExceptionHelper)2 JdbcSessionContext (org.hibernate.resource.jdbc.spi.JdbcSessionContext)2 JdbcSessionOwner (org.hibernate.resource.jdbc.spi.JdbcSessionOwner)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)2 Field (java.lang.reflect.Field)1 Arrays (java.util.Arrays)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1