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();
}
}
}
}
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) {
}
}
}
}
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();
}
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();
}
}
}
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();
}
}
}
Aggregations