org.hibernate.resource.beans.spi.BeanInstanceProducer Java Examples

The following examples show how to use org.hibernate.resource.beans.spi.BeanInstanceProducer. 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 vote down vote up
@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: CdiBeanContainerExtendedAccessImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected <B> ContainedBeanImplementor<B> createBean(
		String name,
		Class<B> beanType,
		BeanLifecycleStrategy lifecycleStrategy,
		BeanInstanceProducer fallbackProducer) {
	if ( usableBeanManager == null ) {
		return new NamedBeanImpl<>(
				name,
				beanType,
				lifecycleStrategy,
				fallbackProducer
		);
	}
	else {
		return lifecycleStrategy.createBean( name, beanType, fallbackProducer, this );
	}
}
 
Example #3
Source File: AbstractCdiBeanContainer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <B> ContainedBeanImplementor<B> createBean(
		String beanName,
		Class<B> beanType,
		LifecycleOptions lifecycleOptions,
		BeanInstanceProducer fallbackProducer) {
	final ContainedBeanImplementor bean = createBean(
			beanName,
			beanType,
			lifecycleOptions.useJpaCompliantCreation()
					? JpaCompliantLifecycleStrategy.INSTANCE
					: ContainerManagedLifecycleStrategy.INSTANCE,
			fallbackProducer
	);
	registeredBeans.add( bean );
	return bean;
}
 
Example #4
Source File: AbstractCdiBeanContainer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <B> ContainedBeanImplementor<B> getCacheableBean(
		String beanName,
		Class<B> beanType,
		LifecycleOptions lifecycleOptions,
		BeanInstanceProducer fallbackProducer) {
	final String beanCacheKey = Helper.INSTANCE.determineBeanCacheKey( beanName, beanType );

	final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
	if ( existing != null ) {
		return existing;
	}

	final ContainedBeanImplementor bean = createBean( beanName, beanType, lifecycleOptions, fallbackProducer );
	beanCache.put( beanCacheKey, bean );
	return bean;
}
 
Example #5
Source File: AbstractCdiBeanContainer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <B> ContainedBean<B> getCacheableBean(
		Class<B> beanType,
		LifecycleOptions lifecycleOptions,
		BeanInstanceProducer fallbackProducer) {
	final String beanCacheKey = Helper.INSTANCE.determineBeanCacheKey( beanType );

	final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
	if ( existing != null ) {
		return existing;
	}

	final ContainedBeanImplementor bean = createBean( beanType, lifecycleOptions, fallbackProducer );
	beanCache.put( beanCacheKey, bean );
	return bean;
}
 
Example #6
Source File: SpringBeanContainer.java    From java-technology-stack with MIT License 6 votes vote down vote up
private SpringContainedBean<?> createBean(
		String name, Class<?> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) {

	try {
		if (lifecycleOptions.useJpaCompliantCreation()) {
			Object bean = this.beanFactory.autowire(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
			this.beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
			this.beanFactory.applyBeanPropertyValues(bean, name);
			bean = this.beanFactory.initializeBean(bean, name);
			return new SpringContainedBean<>(bean, beanInstance -> this.beanFactory.destroyBean(name, beanInstance));
		}
		else {
			return new SpringContainedBean<>(this.beanFactory.getBean(name, beanType));
		}
	}
	catch (BeansException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("Falling back to Hibernate's default producer after bean creation failure for " +
					beanType + ": " + ex);
		}
		return new SpringContainedBean<>(fallbackProducer.produceBeanInstance(name, beanType));
	}
}
 
Example #7
Source File: SpringBeanContainer.java    From java-technology-stack with MIT License 6 votes vote down vote up
private SpringContainedBean<?> createBean(
		Class<?> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) {

	try {
		if (lifecycleOptions.useJpaCompliantCreation()) {
			return new SpringContainedBean<>(
					this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false),
					this.beanFactory::destroyBean);
		}
		else {
			return new SpringContainedBean<>(this.beanFactory.getBean(beanType));
		}
	}
	catch (BeansException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("Falling back to Hibernate's default producer after bean creation failure for " +
					beanType + ": " + ex);
		}
		return new SpringContainedBean<>(fallbackProducer.produceBeanInstance(beanType));
	}
}
 
Example #8
Source File: SpringBeanContainer.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 vote down vote up
@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: SpringBeanContainer.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 #11
Source File: CdiBeanContainerImmediateAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected <B> ContainedBeanImplementor<B> createBean(
		String name,
		Class<B> beanType,
		BeanLifecycleStrategy lifecycleStrategy,
		BeanInstanceProducer fallbackProducer) {
	final ContainedBeanImplementor<B> bean = lifecycleStrategy.createBean(
			name,
			beanType,
			fallbackProducer,
			this
	);
	bean.initialize();
	return bean;
}
 
Example #12
Source File: ContainerManagedLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <B> ContainedBeanImplementor<B> createBean(
		Class<B> beanClass,
		BeanInstanceProducer fallbackProducer,
		BeanContainer beanContainer) {
	return new BeanImpl<>( beanClass, fallbackProducer, ( (CdiBasedBeanContainer) beanContainer ).getUsableBeanManager() );
}
 
Example #13
Source File: ContainerManagedLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <B> ContainedBeanImplementor<B> createBean(
		String beanName,
		Class<B> beanClass,
		BeanInstanceProducer fallbackProducer,
		BeanContainer beanContainer) {
	return new NamedBeanImpl<>( beanName, beanClass, fallbackProducer, ( (CdiBasedBeanContainer) beanContainer ).getUsableBeanManager() );
}
 
Example #14
Source File: ContainerManagedLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private AbstractBeanImpl(
		Class<B> beanType,
		BeanInstanceProducer fallbackProducer,
		BeanManager beanManager) {
	this.beanType = beanType;
	this.fallbackProducer = fallbackProducer;
	this.beanManager = beanManager;
}
 
Example #15
Source File: ContainerManagedLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private NamedBeanImpl(
		String beanName,
		Class<B> beanType,
		BeanInstanceProducer fallbackProducer,
		BeanManager beanManager) {
	super( beanType, fallbackProducer, beanManager );
	this.beanName = beanName;
}
 
Example #16
Source File: CdiBeanContainerExtendedAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected <B> ContainedBeanImplementor<B> createBean(
		Class<B> beanType,
		BeanLifecycleStrategy lifecycleStrategy,
		BeanInstanceProducer fallbackProducer) {
	if ( usableBeanManager == null ) {
		return new BeanImpl<>( beanType, lifecycleStrategy, fallbackProducer );
	}
	else {
		return lifecycleStrategy.createBean( beanType, fallbackProducer, this );
	}
}
 
Example #17
Source File: JpaCompliantLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private NamedBeanImpl(
		String beanName,
		Class<B> beanType,
		BeanInstanceProducer fallbackProducer,
		BeanManager beanManager) {
	this.beanName = beanName;
	this.beanType = beanType;
	this.fallbackProducer = fallbackProducer;
	this.beanManager = beanManager;
}
 
Example #18
Source File: CdiBeanContainerImmediateAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected <B> ContainedBeanImplementor<B> createBean(
		Class<B> beanType,
		BeanLifecycleStrategy lifecycleStrategy,
		BeanInstanceProducer fallbackProducer) {
	final ContainedBeanImplementor<B> bean = lifecycleStrategy.createBean( beanType, fallbackProducer, this );
	bean.initialize();
	return bean;
}
 
Example #19
Source File: CdiBeanContainerExtendedAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private BeanImpl(
		Class<B> beanType,
		BeanLifecycleStrategy lifecycleStrategy,
		BeanInstanceProducer fallbackProducer) {
	this.beanType = beanType;
	this.lifecycleStrategy = lifecycleStrategy;
	this.fallbackProducer = fallbackProducer;
}
 
Example #20
Source File: CdiBeanContainerExtendedAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private NamedBeanImpl(
		String name,
		Class<B> beanType,
		BeanLifecycleStrategy lifecycleStrategy, 
		BeanInstanceProducer fallbackProducer) {
	this.name = name;
	this.beanType = beanType;
	this.lifecycleStrategy = lifecycleStrategy;
	this.fallbackProducer = fallbackProducer;
}
 
Example #21
Source File: CdiBeanContainerExtendedAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #22
Source File: CdiBeanContainerExtendedAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #23
Source File: JpaCompliantLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <B> ContainedBeanImplementor<B> createBean(
		Class<B> beanClass,
		BeanInstanceProducer fallbackProducer,
		BeanContainer beanContainer) {
	return new BeanImpl<>(
			beanClass,
			fallbackProducer,
			( (CdiBasedBeanContainer) beanContainer ).getUsableBeanManager()
	);
}
 
Example #24
Source File: JpaCompliantLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <B> ContainedBeanImplementor<B> createBean(
		String beanName,
		Class<B> beanClass,
		BeanInstanceProducer fallbackProducer,
		BeanContainer beanContainer) {
	return new NamedBeanImpl<>(
			beanName,
			beanClass,
			fallbackProducer,
			( (CdiBasedBeanContainer) beanContainer ).getUsableBeanManager()
	);
}
 
Example #25
Source File: JpaCompliantLifecycleStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public BeanImpl(
		Class<B> beanType,
		BeanInstanceProducer fallbackProducer,
		BeanManager beanManager) {
	this.beanType = beanType;
	this.fallbackProducer = fallbackProducer;
	this.beanManager = beanManager;
}
 
Example #26
Source File: CdiBeanContainerDelayedAccessImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private BeanImpl(
		Class<B> beanType,
		BeanLifecycleStrategy lifecycleStrategy, 
		BeanInstanceProducer fallbackProducer) {
	this.beanType = beanType;
	this.lifecycleStrategy = lifecycleStrategy;
	this.fallbackProducer = fallbackProducer;
}
 
Example #27
Source File: SpringBeanContainer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private SpringContainedBean<?> createBean(
		Class<?> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) {

	try {
		if (lifecycleOptions.useJpaCompliantCreation()) {
			return new SpringContainedBean<>(
					this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false),
					this.beanFactory::destroyBean);
		}
		else {
			return new SpringContainedBean<>(this.beanFactory.getBean(beanType));
		}
	}
	catch (BeansException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("Falling back to Hibernate's default producer after bean creation failure for " +
					beanType + ": " + ex);
		}
		try {
			return new SpringContainedBean<>(fallbackProducer.produceBeanInstance(beanType));
		}
		catch (RuntimeException ex2) {
			if (ex instanceof BeanCreationException) {
				if (logger.isDebugEnabled()) {
					logger.debug("Fallback producer failed for " + beanType + ": " + ex2);
				}
				// Rethrow original Spring exception from first attempt.
				throw ex;
			}
			else {
				// Throw fallback producer exception since original was probably NoSuchBeanDefinitionException.
				throw ex2;
			}
		}
	}
}
 
Example #28
Source File: SpringBeanContainer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private SpringContainedBean<?> createBean(
		String name, Class<?> beanType, LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer) {

	try {
		if (lifecycleOptions.useJpaCompliantCreation()) {
			Object bean = this.beanFactory.autowire(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
			this.beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
			this.beanFactory.applyBeanPropertyValues(bean, name);
			bean = this.beanFactory.initializeBean(bean, name);
			return new SpringContainedBean<>(bean, beanInstance -> this.beanFactory.destroyBean(name, beanInstance));
		}
		else {
			return new SpringContainedBean<>(this.beanFactory.getBean(name, beanType));
		}
	}
	catch (BeansException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("Falling back to Hibernate's default producer after bean creation failure for " +
					beanType + " with name '" + name + "': " + ex);
		}
		try {
			return new SpringContainedBean<>(fallbackProducer.produceBeanInstance(name, beanType));
		}
		catch (RuntimeException ex2) {
			if (ex instanceof BeanCreationException) {
				if (logger.isDebugEnabled()) {
					logger.debug("Fallback producer failed for " + beanType + " with name '" + name + "': " + ex2);
				}
				// Rethrow original Spring exception from first attempt.
				throw ex;
			}
			else {
				// Throw fallback producer exception since original was probably NoSuchBeanDefinitionException.
				throw ex2;
			}
		}
	}
}
 
Example #29
Source File: AbstractCdiBeanContainer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <B> ContainedBean<B> getBean(
		Class<B> beanType,
		LifecycleOptions lifecycleOptions,
		BeanInstanceProducer fallbackProducer) {
	if ( lifecycleOptions.canUseCachedReferences() ) {
		return getCacheableBean( beanType, lifecycleOptions, fallbackProducer );
	}
	else {
		return createBean( beanType, lifecycleOptions, fallbackProducer );
	}
}
 
Example #30
Source File: AbstractCdiBeanContainer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <B> ContainedBeanImplementor<B> createBean(
		Class<B> beanType,
		LifecycleOptions lifecycleOptions,
		BeanInstanceProducer fallbackProducer) {
	final ContainedBeanImplementor bean = createBean(
			beanType,
			lifecycleOptions.useJpaCompliantCreation()
					? JpaCompliantLifecycleStrategy.INSTANCE
					: ContainerManagedLifecycleStrategy.INSTANCE,
			fallbackProducer
	);
	registeredBeans.add( bean );
	return bean;
}