use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class SQLServerDialectCollationTest method buildSessionFactory.
protected void buildSessionFactory() {
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
StandardServiceRegistryImpl _serviceRegistry = buildServiceRegistry(bootRegistry, constructConfiguration());
try {
try (Connection connection = _serviceRegistry.getService(JdbcServices.class).getBootstrapJdbcConnectionAccess().obtainConnection();
Statement statement = connection.createStatement()) {
connection.setAutoCommit(true);
statement.executeUpdate("DROP DATABASE hibernate_orm_test_collation");
} catch (SQLException e) {
log.debug(e.getMessage());
}
try (Connection connection = _serviceRegistry.getService(JdbcServices.class).getBootstrapJdbcConnectionAccess().obtainConnection();
Statement statement = connection.createStatement()) {
connection.setAutoCommit(true);
statement.executeUpdate("CREATE DATABASE hibernate_orm_test_collation COLLATE Latin1_General_CS_AS");
statement.executeUpdate("ALTER DATABASE [hibernate_orm_test_collation] SET AUTO_CLOSE OFF ");
} catch (SQLException e) {
log.debug(e.getMessage());
}
} finally {
_serviceRegistry.destroy();
}
super.buildSessionFactory();
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class BaseNonConfigCoreFunctionalTestCase method constructStandardServiceRegistryBuilder.
protected final StandardServiceRegistryBuilder constructStandardServiceRegistryBuilder() {
final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder();
bsrb.applyClassLoader(getClass().getClassLoader());
// by default we do not share the BootstrapServiceRegistry nor the StandardServiceRegistry,
// so we want the BootstrapServiceRegistry to be automatically closed when the
// StandardServiceRegistry is closed.
bsrb.enableAutoClose();
configureBootstrapServiceRegistryBuilder(bsrb);
final BootstrapServiceRegistry bsr = bsrb.build();
afterBootstrapServiceRegistryBuilt(bsr);
final Map settings = new HashMap();
addSettings(settings);
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(bsr);
initialize(ssrb);
ssrb.applySettings(settings);
configureStandardServiceRegistryBuilder(ssrb);
return ssrb;
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class NonRegistryManagedExtendedCdiSupportTest method buildSessionFactory.
private SessionFactoryImplementor buildSessionFactory(ExtendedBeanManagerImpl standIn, NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().applyIntegrator(beanConsumingIntegrator).build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, standIn).build();
try {
return (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
throw e;
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class CdiHostedConverterTest method testIt.
@Test
public void testIt() {
MonitorBean.reset();
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(MonitorBean.class, ConverterBean.class);
try (final SeContainer cdiContainer = cdiInitializer.initialize()) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager()).build();
final SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
throw e;
}
// The CDI bean should have been built immediately...
assertTrue(MonitorBean.wasInstantiated());
assertEquals(0, MonitorBean.currentFromDbCount());
assertEquals(0, MonitorBean.currentToDbCount());
try {
inTransaction(sessionFactory, session -> session.persist(new TheEntity(1, "me", 5)));
assertEquals(0, MonitorBean.currentFromDbCount());
assertEquals(1, MonitorBean.currentToDbCount());
inTransaction(sessionFactory, session -> {
TheEntity it = session.find(TheEntity.class, 1);
assertNotNull(it);
});
assertEquals(1, MonitorBean.currentFromDbCount());
assertEquals(1, MonitorBean.currentToDbCount());
} finally {
inTransaction(sessionFactory, session -> {
session.createQuery("delete TheEntity").executeUpdate();
});
sessionFactory.close();
}
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class DelayedCdiSupportTest method testIt.
@Test
public void testIt() {
Monitor.reset();
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(Monitor.class, TheListener.class);
try (final SeContainer cdiContainer = cdiInitializer.initialize()) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager()).applySetting(AvailableSettings.DELAY_CDI_ACCESS, "true").build();
final SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
throw e;
}
// The CDI bean should not be built immediately...
assertFalse(Monitor.wasInstantiated());
assertEquals(0, Monitor.currentCount());
try {
inTransaction(sessionFactory, session -> session.persist(new TheEntity(1)));
// The CDI bean should have been built on first use
assertTrue(Monitor.wasInstantiated());
assertEquals(1, Monitor.currentCount());
inTransaction(sessionFactory, session -> {
TheEntity it = session.find(TheEntity.class, 1);
assertNotNull(it);
});
} finally {
inTransaction(sessionFactory, session -> {
session.createQuery("delete TheEntity").executeUpdate();
});
sessionFactory.close();
}
}
}
Aggregations