use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class DefaultCacheConcurrencyPropertyTest method testExplicitDefault.
@Test
@TestForIssue(jiraKey = "HHH-9763")
@FailureExpected(jiraKey = "HHH-9763")
public void testExplicitDefault() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-only").build();
try {
assertEquals("read-only", ssr.getService(ConfigurationService.class).getSettings().get(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY));
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
assertEquals(AccessType.READ_ONLY, metadata.getMetadataBuildingOptions().getMappingDefaults().getImplicitCacheAccessType());
final SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory();
try {
final EntityPersister persister = sf.getMetamodel().entityPersister(TheEntity.class.getName());
assertTrue(persister.canReadFromCache());
assertTrue(persister.canWriteToCache());
assertNotNull(persister.getCacheAccessStrategy());
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class ValidExtendedCdiSupportTest method testIt.
@Test
public void testIt() {
Monitor.reset();
final ExtendedBeanManagerImpl standIn = new ExtendedBeanManagerImpl();
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, standIn).build();
final SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
throw e;
}
try {
// The CDI bean should not be built immediately...
assertFalse(Monitor.wasInstantiated());
assertEquals(0, Monitor.currentCount());
// But now lets initialize CDI and do the callback
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(Monitor.class, TheListener.class);
try (final SeContainer cdiContainer = cdiInitializer.initialize()) {
standIn.beanManagerReady(cdiContainer.getBeanManager());
// at this point the bean should have been accessed
assertTrue(Monitor.wasInstantiated());
assertEquals(0, Monitor.currentCount());
try {
inTransaction(sessionFactory, session -> session.persist(new TheEntity(1)));
inTransaction(sessionFactory, session -> {
TheEntity it = session.find(TheEntity.class, 1);
assertNotNull(it);
});
} finally {
inTransaction(sessionFactory, session -> {
session.createQuery("delete TheEntity").executeUpdate();
});
}
}
} finally {
sessionFactory.close();
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class ExtendedMixedAccessTest method testExtendedMixedAccess.
@Test
public void testExtendedMixedAccess() {
final Helper.TestingExtendedBeanManager extendedBeanManager = Helper.createExtendedBeanManager();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, extendedBeanManager).build();
final BeanContainer beanContainer = ssr.getService(ManagedBeanRegistry.class).getBeanContainer();
assertThat(beanContainer, instanceOf(CdiBeanContainerExtendedAccessImpl.class));
try (final SeContainer cdiContainer = Helper.createSeContainer()) {
final BeanManager beanManager = cdiContainer.getBeanManager();
extendedBeanManager.notifyListenerReady(beanManager);
assertThat(beanManager, sameInstance(((CdiBeanContainerExtendedAccessImpl) beanContainer).getUsableBeanManager()));
final ContainedBean<HostedBean> hostedBean = beanContainer.getBean(HostedBean.class, this, FallbackBeanInstanceProducer.INSTANCE);
assertThat(hostedBean, notNullValue());
assertThat(hostedBean.getBeanInstance(), notNullValue());
assertThat(hostedBean.getBeanInstance().getInjectedHostedBean(), notNullValue());
final ContainedBean<NonHostedBean> nonHostedBean = beanContainer.getBean(NonHostedBean.class, this, FallbackBeanInstanceProducer.INSTANCE);
assertThat(nonHostedBean, notNullValue());
assertThat(nonHostedBean.getBeanInstance(), notNullValue());
extendedBeanManager.notifyListenerShuttingDown(beanManager);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class InvalidExtendedCdiSupportTest method testIt.
@Test
public void testIt() {
Monitor.reset();
final ExtendedBeanManagerImpl standIn = new ExtendedBeanManagerImpl();
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).applySetting(AvailableSettings.CDI_BEAN_MANAGER, standIn).build();
final SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
throw e;
}
try {
// The CDI bean should not be built immediately...
assertFalse(Monitor.wasInstantiated());
assertEquals(0, Monitor.currentCount());
try {
inTransaction(sessionFactory, session -> session.persist(new TheEntity(1)));
inTransaction(sessionFactory, session -> {
session.createQuery("delete TheEntity").executeUpdate();
});
fail("Expecting failure");
} catch (IllegalStateException expected) {
}
} finally {
sessionFactory.close();
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class InvalidNoCdiSupportTest method testIt.
@Test
public void testIt() {
Monitor.reset();
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build();
final SessionFactoryImplementor sessionFactory;
try {
// because there is no CDI available, building the SF should immediately
// try to build the ManagedBeans which should fail here
sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata().getSessionFactoryBuilder().build();
sessionFactory.close();
fail("Expecting failure");
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
assertThat(e, instanceOf(InstantiationException.class));
}
}
Aggregations