use of org.hibernate.resource.beans.container.spi.BeanContainer in project hibernate-orm by hibernate.
the class DelayedMixedAccessTest method testDelayedMixedAccess.
@Test
public void testDelayedMixedAccess() {
try (final SeContainer cdiContainer = Helper.createSeContainer()) {
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 BeanContainer beanContainer = CdiBeanContainerBuilder.fromBeanManagerReference(cdiContainer.getBeanManager(), ssr);
assertThat(beanContainer, instanceOf(CdiBeanContainerDelayedAccessImpl.class));
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());
}
}
use of org.hibernate.resource.beans.container.spi.BeanContainer in project hibernate-orm by hibernate.
the class ImmediateMixedAccessTests method testImmediateMixedAccess.
@Test
public void testImmediateMixedAccess() {
try (final SeContainer cdiContainer = Helper.createSeContainer()) {
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 BeanContainer beanContainer = CdiBeanContainerBuilder.fromBeanManagerReference(cdiContainer.getBeanManager(), ssr);
assertThat(beanContainer, instanceOf(CdiBeanContainerImmediateAccessImpl.class));
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());
}
}
use of org.hibernate.resource.beans.container.spi.BeanContainer 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.resource.beans.container.spi.BeanContainer in project hibernate-orm by hibernate.
the class NonRegistryManagedBeanConsumingIntegrator method integrate.
@Override
@SuppressWarnings("unchecked")
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
ManagedBeanRegistry registry = sessionFactory.getServiceRegistry().getService(ManagedBeanRegistry.class);
BeanContainer beanContainer = registry.getBeanContainer();
assertThat(beanContainer, CoreMatchers.notNullValue());
applicationScopedBean1 = (ContainedBeanImplementor) beanContainer.getBean(TheApplicationScopedBean.class, this, fallbackBeanInstanceProducer);
applicationScopedBean2 = (ContainedBeanImplementor) beanContainer.getBean(TheApplicationScopedBean.class, this, fallbackBeanInstanceProducer);
dependentBean1 = (ContainedBeanImplementor) beanContainer.getBean(TheDependentBean.class, this, fallbackBeanInstanceProducer);
dependentBean2 = (ContainedBeanImplementor) beanContainer.getBean(TheDependentBean.class, this, fallbackBeanInstanceProducer);
reflectionInstantiatedBean1 = (ContainedBeanImplementor) beanContainer.getBean(TheReflectionInstantiatedBean.class, this, fallbackBeanInstanceProducer);
reflectionInstantiatedBean2 = (ContainedBeanImplementor) beanContainer.getBean(TheReflectionInstantiatedBean.class, this, fallbackBeanInstanceProducer);
namedApplicationScopedBean1 = (ContainedBeanImplementor) beanContainer.getBean(TheMainNamedApplicationScopedBeanImpl.NAME, TheNamedApplicationScopedBean.class, this, fallbackBeanInstanceProducer);
namedApplicationScopedBean2 = (ContainedBeanImplementor) beanContainer.getBean(TheMainNamedApplicationScopedBeanImpl.NAME, TheNamedApplicationScopedBean.class, this, fallbackBeanInstanceProducer);
namedDependentBean1 = (ContainedBeanImplementor) beanContainer.getBean(TheMainNamedDependentBeanImpl.NAME, TheNamedDependentBean.class, this, fallbackBeanInstanceProducer);
namedDependentBean2 = (ContainedBeanImplementor) beanContainer.getBean(TheMainNamedDependentBeanImpl.NAME, TheNamedDependentBean.class, this, fallbackBeanInstanceProducer);
namedReflectionInstantiatedBean1 = (ContainedBeanImplementor) beanContainer.getBean(TheReflectionInstantiatedBean.class.getName(), TheReflectionInstantiatedBean.class, this, fallbackBeanInstanceProducer);
namedReflectionInstantiatedBean2 = (ContainedBeanImplementor) beanContainer.getBean(TheReflectionInstantiatedBean.class.getName(), TheReflectionInstantiatedBean.class, this, fallbackBeanInstanceProducer);
}
use of org.hibernate.resource.beans.container.spi.BeanContainer in project hibernate-orm by hibernate.
the class ManagedBeanRegistryInitiator method interpretExplicitBeanContainer.
private BeanContainer interpretExplicitBeanContainer(Object explicitSetting, ClassLoaderService classLoaderService, ServiceRegistryImplementor serviceRegistry) {
if (explicitSetting == null) {
return null;
}
if (explicitSetting instanceof BeanContainer) {
return (BeanContainer) explicitSetting;
}
// otherwise we ultimately need to resolve this to a class
final Class containerClass;
if (explicitSetting instanceof Class) {
containerClass = (Class) explicitSetting;
} else {
final String name = explicitSetting.toString();
// try the StrategySelector service
final Class selected = serviceRegistry.getService(StrategySelector.class).selectStrategyImplementor(BeanContainer.class, name);
if (selected != null) {
containerClass = selected;
} else {
containerClass = classLoaderService.classForName(name);
}
}
try {
return (BeanContainer) containerClass.newInstance();
} catch (Exception e) {
throw new InstantiationException("Unable to instantiate specified BeanContainer : " + containerClass.getName(), containerClass, e);
}
}
Aggregations