Search in sources :

Example 11 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class BootstrapServiceRegistryImpl method destroy.

@Override
public void destroy() {
    if (!active) {
        return;
    }
    active = false;
    destroy(classLoaderServiceBinding);
    destroy(strategySelectorBinding);
    destroy(integratorServiceBinding);
    if (childRegistries != null) {
        for (ServiceRegistry serviceRegistry : childRegistries) {
            if (serviceRegistry instanceof ServiceRegistryImplementor) {
                ServiceRegistryImplementor serviceRegistryImplementor = (ServiceRegistryImplementor) serviceRegistry;
                serviceRegistryImplementor.destroy();
            }
        }
    }
}
Also used : ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry)

Example 12 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class ConfigurationValidationTest method testReleaseMode.

@Test
public void testReleaseMode() {
    ServiceRegistryImplementor serviceRegistry = null;
    try {
        serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA).applySetting(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.name()).addService(MultiTenantConnectionProvider.class, new TestingConnectionProvider(new TestingConnectionProvider.NamedConnectionProviderPair("acme", ConnectionProviderBuilder.buildConnectionProvider("acme")))).build();
        new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory().close();
    } finally {
        if (serviceRegistry != null) {
            try {
                StandardServiceRegistryBuilder.destroy(serviceRegistry);
            } catch (Exception ignore) {
            }
        }
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) ServiceException(org.hibernate.service.spi.ServiceException) Test(org.junit.Test)

Example 13 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class AbstractMultiTenancyTest method sessionFactory.

protected SessionFactory sessionFactory(Map<String, Object> settings) {
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    for (Class annotatedClasses : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(annotatedClasses);
    }
    Metadata metadata = metadataSources.buildMetadata();
    HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
    tool.injectServices(serviceRegistry);
    final GenerationTargetToDatabase frontEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(FRONT_END_TENANT)));
    final GenerationTargetToDatabase backEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(BACK_END_TENANT)));
    new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
    new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
    final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
    return sessionFactoryBuilder.build();
}
Also used : DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)

Example 14 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class NegativeValueSequenceTest method testPositiveOneAllocationSizeNoopOptimizer.

@Test
@TestForIssue(jiraKey = "HHH-11709")
public void testPositiveOneAllocationSizeNoopOptimizer() {
    ServiceRegistryImplementor serviceRegistry = null;
    SessionFactoryImplementor sessionFactory = null;
    Session session = null;
    try {
        serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
        Triggerable triggerable = logInspection.watchForLogMessages("HHH000116");
        Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(PositiveOneIncrementSize.class).buildMetadata();
        // PositiveOneIncrementSize ID has allocationSize == 1, so warning should not be triggered.
        assertEquals(false, triggerable.wasTriggered());
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
        assertOptimizer(sessionFactory, PositiveOneIncrementSize.class, NoopOptimizer.class);
        session = sessionFactory.openSession();
        session.getTransaction().begin();
        // initial value is -5; sequence should be incremented by 1 (since allocationSize is 1)
        for (Integer i = -5; i <= 5; i++) {
            PositiveOneIncrementSize theEntity = new PositiveOneIncrementSize();
            session.persist(theEntity);
            assertEquals(i, theEntity.id);
        }
    } finally {
        if (session != null) {
            session.getTransaction().rollback();
            session.close();
        }
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        if (serviceRegistry != null) {
            serviceRegistry.destroy();
        }
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 15 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class NegativeValueSequenceTest method testNegativeOneAllocationSizeNoopOptimizer.

@Test
@TestForIssue(jiraKey = "HHH-5933")
public void testNegativeOneAllocationSizeNoopOptimizer() {
    ServiceRegistryImplementor serviceRegistry = null;
    SessionFactoryImplementor sessionFactory = null;
    Session session = null;
    try {
        serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
        Triggerable triggerable = logInspection.watchForLogMessages("HHH000116");
        Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(NegativeOneIncrementSize.class).buildMetadata();
        // NegativeOneIncrementSize ID has allocationSize == -1, so warning should not be triggered.
        assertEquals(false, triggerable.wasTriggered());
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
        assertOptimizer(sessionFactory, NegativeOneIncrementSize.class, NoopOptimizer.class);
        session = sessionFactory.openSession();
        session.getTransaction().begin();
        // initial value is -10; sequence should be decremented by 1 (since allocationSize is -1)
        for (Integer i = -10; i >= -15; i--) {
            NegativeOneIncrementSize theEntity = new NegativeOneIncrementSize();
            session.persist(theEntity);
            assertEquals(i, theEntity.id);
        }
    } finally {
        if (session != null) {
            session.getTransaction().rollback();
            session.close();
        }
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        if (serviceRegistry != null) {
            serviceRegistry.destroy();
        }
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)16 MetadataSources (org.hibernate.boot.MetadataSources)15 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)15 Test (org.junit.Test)13 Metadata (org.hibernate.boot.Metadata)10 Triggerable (org.hibernate.testing.logger.Triggerable)8 HashMap (java.util.HashMap)6 Session (org.hibernate.Session)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)6 TestForIssue (org.hibernate.testing.TestForIssue)6 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)5 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)5 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)5 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)5 Map (java.util.Map)3 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)3 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 JdbcConnectionAccessImpl (org.hibernate.testing.boot.JdbcConnectionAccessImpl)3 CachingRegionFactory (org.hibernate.testing.cache.CachingRegionFactory)3 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)2