use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class ValidNoCdiSupportTest method testIt.
@Test
public void testIt() {
AnotherListener.reset();
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build();
final SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(AnotherEntity.class).buildMetadata().getSessionFactoryBuilder().build();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
throw e;
}
// The CDI bean should have been built immediately...
assertTrue(AnotherListener.wasInstantiated());
assertEquals(0, AnotherListener.currentCount());
try {
inTransaction(sessionFactory, session -> session.persist(new AnotherEntity(1)));
assertEquals(1, AnotherListener.currentCount());
inTransaction(sessionFactory, session -> {
AnotherEntity it = session.find(AnotherEntity.class, 1);
assertNotNull(it);
});
} finally {
inTransaction(sessionFactory, session -> {
session.createQuery("delete AnotherEntity").executeUpdate();
});
sessionFactory.close();
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class StandardCdiSupportTest 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()).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(Monitor.wasInstantiated());
assertEquals(0, Monitor.currentCount());
try {
inTransaction(sessionFactory, session -> session.persist(new TheEntity(1)));
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();
}
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class NonRegistryManagedStandardCdiSupportTest method buildSessionFactory.
private SessionFactoryImplementor buildSessionFactory(SeContainer cdiContainer, 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, cdiContainer.getBeanManager()).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 NonRegistryManagedDelayedCdiSupportTest method buildSessionFactory.
private SessionFactoryImplementor buildSessionFactory(SeContainer cdiContainer, 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, cdiContainer.getBeanManager()).applySetting(AvailableSettings.DELAY_CDI_ACCESS, "true").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 BootstrapTest method test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example.
@Test
public void test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example() {
ClassLoader customClassLoader = Thread.currentThread().getContextClassLoader();
Integrator customIntegrator = new BeanValidationIntegrator();
// tag::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
BootstrapServiceRegistryBuilder bootstrapRegistryBuilder = new BootstrapServiceRegistryBuilder();
// add a custom ClassLoader
bootstrapRegistryBuilder.applyClassLoader(customClassLoader);
// manually add an Integrator
bootstrapRegistryBuilder.applyIntegrator(customIntegrator);
BootstrapServiceRegistry bootstrapRegistry = bootstrapRegistryBuilder.build();
// end::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
}
Aggregations