org.hibernate.resource.beans.container.spi.ContainedBean Java Examples
The following examples show how to use
org.hibernate.resource.beans.container.spi.ContainedBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringBeanContainer.java From spring-analysis-note with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public <B> ContainedBean<B> getBean( String name, Class<B> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) { SpringContainedBean<?> bean; if (lifecycleOptions.canUseCachedReferences()) { bean = this.beanCache.get(name); if (bean == null) { bean = createBean(name, beanType, lifecycleOptions, fallbackProducer); this.beanCache.put(name, bean); } } else { bean = createBean(name, beanType, lifecycleOptions, fallbackProducer); } return (SpringContainedBean<B>) bean; }
Example #2
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByNameWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( "some name", NoDefinitionInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(0, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(1, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertEquals("some name", instance.getName()); assertNull(instance.getApplicationContext()); }
Example #3
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByTypeWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( NoDefinitionInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(1, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(0, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertNull(instance.getApplicationContext()); }
Example #4
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByNameWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( "some name", NoDefinitionInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(0, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(1, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertEquals("some name", instance.getName()); assertNull(instance.getApplicationContext()); }
Example #5
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByTypeWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( NoDefinitionInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(1, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(0, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertNull(instance.getApplicationContext()); }
Example #6
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCanRetrieveBeanByNameWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<MultiplePrototypesInSpringContextTestBean> bean = beanContainer.getBean( "multiple-1", MultiplePrototypesInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); MultiplePrototypesInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals("multiple-1", instance.getName()); assertSame(applicationContext, instance.getApplicationContext()); }
Example #7
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCanRetrieveBeanByTypeWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<SinglePrototypeInSpringContextTestBean> bean = beanContainer.getBean( SinglePrototypeInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); SinglePrototypeInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertSame(applicationContext, instance.getApplicationContext()); }
Example #8
Source File: SpringBeanContainer.java From java-technology-stack with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public <B> ContainedBean<B> getBean( String name, Class<B> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) { SpringContainedBean<?> bean; if (lifecycleOptions.canUseCachedReferences()) { bean = this.beanCache.get(name); if (bean == null) { bean = createBean(name, beanType, lifecycleOptions, fallbackProducer); this.beanCache.put(name, bean); } } else { bean = createBean(name, beanType, lifecycleOptions, fallbackProducer); } return (SpringContainedBean<B>) bean; }
Example #9
Source File: SpringBeanContainer.java From java-technology-stack with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public <B> ContainedBean<B> getBean( Class<B> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) { SpringContainedBean<?> bean; if (lifecycleOptions.canUseCachedReferences()) { bean = this.beanCache.get(beanType); if (bean == null) { bean = createBean(beanType, lifecycleOptions, fallbackProducer); this.beanCache.put(beanType, bean); } } else { bean = createBean(beanType, lifecycleOptions, fallbackProducer); } return (SpringContainedBean<B>) bean; }
Example #10
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByNameWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( "some name", NoDefinitionInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(0, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(1, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertEquals("some name", instance.getName()); assertNull(instance.getApplicationContext()); }
Example #11
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByTypeWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( NoDefinitionInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(1, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(0, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertNull(instance.getApplicationContext()); }
Example #12
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByNameWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( "some name", NoDefinitionInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(0, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(1, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertEquals("some name", instance.getName()); assertNull(instance.getApplicationContext()); }
Example #13
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testCanRetrieveFallbackBeanByTypeWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer(); ContainedBean<NoDefinitionInSpringContextTestBean> bean = beanContainer.getBean( NoDefinitionInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, fallbackProducer ); assertEquals(1, fallbackProducer.currentUnnamedInstantiationCount()); assertEquals(0, fallbackProducer.currentNamedInstantiationCount()); assertNotNull(bean); NoDefinitionInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals(BeanSource.FALLBACK, instance.getSource()); assertNull(instance.getApplicationContext()); }
Example #14
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testCanRetrieveBeanByNameWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<MultiplePrototypesInSpringContextTestBean> bean = beanContainer.getBean( "multiple-1", MultiplePrototypesInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); MultiplePrototypesInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals("multiple-1", instance.getName()); assertSame(applicationContext, instance.getApplicationContext()); }
Example #15
Source File: SpringBeanContainer.java From spring-analysis-note with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public <B> ContainedBean<B> getBean( Class<B> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) { SpringContainedBean<?> bean; if (lifecycleOptions.canUseCachedReferences()) { bean = this.beanCache.get(beanType); if (bean == null) { bean = createBean(beanType, lifecycleOptions, fallbackProducer); this.beanCache.put(beanType, bean); } } else { bean = createBean(beanType, lifecycleOptions, fallbackProducer); } return (SpringContainedBean<B>) bean; }
Example #16
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCanRetrieveBeanByNameWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<MultiplePrototypesInSpringContextTestBean> bean = beanContainer.getBean( "multiple-1", MultiplePrototypesInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); MultiplePrototypesInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals("multiple-1", instance.getName()); assertSame(applicationContext, instance.getApplicationContext()); ContainedBean<MultiplePrototypesInSpringContextTestBean> bean2 = beanContainer.getBean( "multiple-1", MultiplePrototypesInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean2); MultiplePrototypesInSpringContextTestBean instance2 = bean2.getBeanInstance(); assertNotNull(instance2); // Due to the lifecycle options, and because the bean has the "prototype" scope, we should not return the same instance assertNotSame(instance, instance2); }
Example #17
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testCanRetrieveBeanByTypeWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<SinglePrototypeInSpringContextTestBean> bean = beanContainer.getBean( SinglePrototypeInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); SinglePrototypeInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals("single", instance.getName()); assertSame(applicationContext, instance.getApplicationContext()); ContainedBean<SinglePrototypeInSpringContextTestBean> bean2 = beanContainer.getBean( SinglePrototypeInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean2); SinglePrototypeInSpringContextTestBean instance2 = bean2.getBeanInstance(); assertNotNull(instance2); // Due to the lifecycle options, and because the bean has the "prototype" scope, we should not return the same instance assertNotSame(instance, instance2); }
Example #18
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testCanRetrieveBeanByNameWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<MultiplePrototypesInSpringContextTestBean> bean = beanContainer.getBean( "multiple-1", MultiplePrototypesInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); MultiplePrototypesInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals("multiple-1", instance.getName()); assertSame(applicationContext, instance.getApplicationContext()); ContainedBean<MultiplePrototypesInSpringContextTestBean> bean2 = beanContainer.getBean( "multiple-1", MultiplePrototypesInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean2); MultiplePrototypesInSpringContextTestBean instance2 = bean2.getBeanInstance(); assertNotNull(instance2); // Due to the lifecycle options, and because the bean has the "prototype" scope, we should not return the same instance assertNotSame(instance, instance2); }
Example #19
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCanRetrieveBeanByTypeWithNativeOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<SinglePrototypeInSpringContextTestBean> bean = beanContainer.getBean( SinglePrototypeInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); SinglePrototypeInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertEquals("single", instance.getName()); assertSame(applicationContext, instance.getApplicationContext()); ContainedBean<SinglePrototypeInSpringContextTestBean> bean2 = beanContainer.getBean( SinglePrototypeInSpringContextTestBean.class, NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean2); SinglePrototypeInSpringContextTestBean instance2 = bean2.getBeanInstance(); assertNotNull(instance2); // Due to the lifecycle options, and because the bean has the "prototype" scope, we should not return the same instance assertNotSame(instance, instance2); }
Example #20
Source File: HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCanRetrieveBeanByTypeWithJpaCompliantOptions() { BeanContainer beanContainer = getBeanContainer(); assertNotNull(beanContainer); ContainedBean<SinglePrototypeInSpringContextTestBean> bean = beanContainer.getBean( SinglePrototypeInSpringContextTestBean.class, JpaLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE ); assertNotNull(bean); SinglePrototypeInSpringContextTestBean instance = bean.getBeanInstance(); assertNotNull(instance); assertSame(applicationContext, instance.getApplicationContext()); }
Example #21
Source File: ManagedBeanRegistryImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public <T> ManagedBean<T> getBean(Class<T> beanClass) { final ManagedBean existing = registrations.get( beanClass.getName() ); if ( existing != null ) { return existing; } final ManagedBean bean; if ( beanContainer == null ) { bean = new FallbackContainedBean( beanClass, FallbackBeanInstanceProducer.INSTANCE ); } else { final ContainedBean<T> containedBean = beanContainer.getBean( beanClass, this, FallbackBeanInstanceProducer.INSTANCE ); if ( containedBean instanceof ManagedBean ) { bean = (ManagedBean) containedBean; } else { bean = new ContainedBeanManagedBeanAdapter( beanClass, containedBean ); } } registrations.put( beanClass.getName(), bean ); return bean; }
Example #22
Source File: ManagedBeanRegistryImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public <T> ManagedBean<T> getBean(String beanName, Class<T> beanContract) { final String key = beanContract.getName() + ':' + beanName; final ManagedBean existing = registrations.get( key ); if ( existing != null ) { return existing; } final ManagedBean bean; if ( beanContainer == null ) { bean = new FallbackContainedBean( beanName, beanContract, FallbackBeanInstanceProducer.INSTANCE ); } else { final ContainedBean<T> containedBean = beanContainer.getBean( beanName, beanContract, this, FallbackBeanInstanceProducer.INSTANCE ); if ( containedBean instanceof ManagedBean ) { bean = (ManagedBean) containedBean; } else { bean = new ContainedBeanManagedBeanAdapter( beanContract, containedBean ); } } registrations.put( key, bean ); return bean; }
Example #23
Source File: CdiBeanContainerExtendedAccessImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public <B> ContainedBean<B> getBean( Class<B> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) { // todo (5.3) : should this throw an exception instead? return CdiBeanContainerExtendedAccessImpl.this.getBean( beanType, lifecycleOptions, fallbackProducer ); }
Example #24
Source File: CdiBeanContainerExtendedAccessImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public <B> ContainedBean<B> getBean( String beanName, Class<B> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) { // todo (5.3) : should this throw an exception instead? return CdiBeanContainerExtendedAccessImpl.this.getBean( beanName, beanType, lifecycleOptions, fallbackProducer ); }
Example #25
Source File: ManagedBeanRegistryImpl.java From lams with GNU General Public License v2.0 | 4 votes |
private ContainedBeanManagedBeanAdapter(Class<B> beanClass, ContainedBean<B> containedBean) { this.beanClass = beanClass; this.containedBean = containedBean; }