Search in sources :

Example 1 with BootstrapServiceRegistryImpl

use of org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl in project hibernate-orm by hibernate.

the class ConnectionCreatorTest method testBadUrl.

@Test
@TestForIssue(jiraKey = "HHH-8621")
public void testBadUrl() throws Exception {
    DriverConnectionCreator connectionCreator = new DriverConnectionCreator((Driver) Class.forName("org.h2.Driver").newInstance(), new StandardServiceRegistryImpl(true, new BootstrapServiceRegistryImpl(), Collections.<StandardServiceInitiator>emptyList(), Collections.<ProvidedService>emptyList(), Collections.emptyMap()) {

        @Override
        @SuppressWarnings("unchecked")
        public <R extends Service> R getService(Class<R> serviceRole) {
            if (JdbcServices.class.equals(serviceRole)) {
                // return a new, not fully initialized JdbcServicesImpl
                return (R) new JdbcServicesImpl();
            }
            return super.getService(serviceRole);
        }
    }, "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", new Properties(), false, null);
    try {
        Connection conn = connectionCreator.createConnection();
        conn.close();
        fail("Expecting the bad Connection URL to cause an exception");
    } catch (JDBCConnectionException expected) {
    }
}
Also used : JdbcServicesImpl(org.hibernate.engine.jdbc.internal.JdbcServicesImpl) JDBCConnectionException(org.hibernate.exception.JDBCConnectionException) ProvidedService(org.hibernate.service.internal.ProvidedService) DriverConnectionCreator(org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator) StandardServiceInitiator(org.hibernate.boot.registry.StandardServiceInitiator) Connection(java.sql.Connection) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) Properties(java.util.Properties) BootstrapServiceRegistryImpl(org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with BootstrapServiceRegistryImpl

use of org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl in project hibernate-orm by hibernate.

the class BootstrapServiceRegistryBuilder method build.

/**
	 * Build the bootstrap registry.
	 *
	 * @return The built bootstrap registry
	 */
public BootstrapServiceRegistry build() {
    final ClassLoaderService classLoaderService;
    if (providedClassLoaderService == null) {
        // Use a set.  As an example, in JPA, OsgiClassLoader may be in both
        // the providedClassLoaders and the overridenClassLoader.
        final Set<ClassLoader> classLoaders = new HashSet<ClassLoader>();
        if (providedClassLoaders != null) {
            classLoaders.addAll(providedClassLoaders);
        }
        classLoaderService = new ClassLoaderServiceImpl(classLoaders, tcclLookupPrecedence);
    } else {
        classLoaderService = providedClassLoaderService;
    }
    final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(providedIntegrators, classLoaderService);
    return new BootstrapServiceRegistryImpl(autoCloseRegistry, classLoaderService, strategySelectorBuilder.buildSelector(classLoaderService), integratorService);
}
Also used : BootstrapServiceRegistryImpl(org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl) IntegratorServiceImpl(org.hibernate.integrator.internal.IntegratorServiceImpl) ClassLoaderServiceImpl(org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

BootstrapServiceRegistryImpl (org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl)2 Connection (java.sql.Connection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 StandardServiceInitiator (org.hibernate.boot.registry.StandardServiceInitiator)1 ClassLoaderServiceImpl (org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 StandardServiceRegistryImpl (org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)1 DriverConnectionCreator (org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator)1 JdbcServicesImpl (org.hibernate.engine.jdbc.internal.JdbcServicesImpl)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 JDBCConnectionException (org.hibernate.exception.JDBCConnectionException)1 IntegratorServiceImpl (org.hibernate.integrator.internal.IntegratorServiceImpl)1 ProvidedService (org.hibernate.service.internal.ProvidedService)1 TestForIssue (org.hibernate.testing.TestForIssue)1 Test (org.junit.Test)1