Search in sources :

Example 1 with StandardServiceRegistryImpl

use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl 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();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) 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) Test(org.junit.Test)

Example 2 with StandardServiceRegistryImpl

use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl 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();
    }
}
Also used : DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) H2Dialect(org.hibernate.dialect.H2Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ConnectionProviderJdbcConnectionAccess(org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess) Test(org.junit.Test)

Example 3 with StandardServiceRegistryImpl

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

the class BaseCoreFunctionalTestCase method buildServiceRegistry.

protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) {
    Properties properties = new Properties();
    properties.putAll(configuration.getProperties());
    Environment.verifyProperties(properties);
    ConfigurationHelper.resolvePlaceHolders(properties);
    StandardServiceRegistryBuilder cfgRegistryBuilder = configuration.getStandardServiceRegistryBuilder();
    StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(bootRegistry, cfgRegistryBuilder.getAggregatedCfgXml()).applySettings(properties);
    prepareBasicRegistryBuilder(registryBuilder);
    return (StandardServiceRegistryImpl) registryBuilder.build();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)

Example 4 with StandardServiceRegistryImpl

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

the class BasicHibernateAnnotationsTest method testTypeDefWithoutNameAndDefaultForTypeAttributes.

@Test
public void testTypeDefWithoutNameAndDefaultForTypeAttributes() {
    SessionFactory sf = null;
    StandardServiceRegistryImpl ssr = null;
    try {
        Configuration config = new Configuration();
        config.addAnnotatedClass(LocalContactDetails.class);
        ssr = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
        sf = config.buildSessionFactory(ssr);
        fail("Did not throw expected exception");
    } catch (AnnotationException ex) {
        assertEquals("Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType", ex.getMessage());
    } finally {
        if (ssr != null) {
            ssr.destroy();
        }
        if (sf != null) {
            sf.close();
        }
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) AnnotationException(org.hibernate.AnnotationException) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) Test(org.junit.Test)

Example 5 with StandardServiceRegistryImpl

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

the class QueryReturnTest method testQueryReturn.

@Test
public void testQueryReturn() {
    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    StandardServiceRegistry standardServiceRegistry = serviceRegistryBuilder.build();
    MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
    try {
        metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML)));
        Metadata metadata = metadataSources.buildMetadata();
        NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryDefinition("myQuery");
        Assert.assertNotNull(myQuery);
        NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns();
        Assert.assertNotNull(myQueryReturns);
        Assert.assertEquals(1, myQueryReturns.length);
        Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0]));
        NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn) myQueryReturns[0];
        Assert.assertEquals("e", myQueryRootReturn.getAlias());
        Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName());
    } finally {
        if (standardServiceRegistry instanceof StandardServiceRegistryImpl) {
            ((StandardServiceRegistryImpl) standardServiceRegistry).destroy();
        }
    }
}
Also used : ReaderInputStream(org.hibernate.engine.jdbc.ReaderInputStream) NamedSQLQueryDefinition(org.hibernate.engine.spi.NamedSQLQueryDefinition) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) MetadataSources(org.hibernate.boot.MetadataSources) StringReader(java.io.StringReader) Metadata(org.hibernate.boot.Metadata) NativeSQLQueryRootReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

StandardServiceRegistryImpl (org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)16 Test (org.junit.Test)10 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)9 Metadata (org.hibernate.boot.Metadata)4 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)4 Properties (java.util.Properties)3 SessionFactory (org.hibernate.SessionFactory)3 MetadataSources (org.hibernate.boot.MetadataSources)3 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)3 H2Dialect (org.hibernate.dialect.H2Dialect)3 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 ConnectionProviderJdbcConnectionAccess (org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess)3 File (java.io.File)2 Connection (java.sql.Connection)2 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)2 SystemException (javax.transaction.SystemException)2 Transaction (javax.transaction.Transaction)2 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)2 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)2 Configuration (org.hibernate.cfg.Configuration)2