Java Code Examples for org.springframework.orm.jpa.EntityManagerFactoryUtils#findEntityManagerFactory()

The following examples show how to use org.springframework.orm.jpa.EntityManagerFactoryUtils#findEntityManagerFactory() . 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: OpenEntityManagerInViewFilter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Look up the EntityManagerFactory that this filter should use.
 * <p>The default implementation looks for a bean with the specified name
 * in Spring's root application context.
 * @return the EntityManagerFactory to use
 * @see #getEntityManagerFactoryBeanName
 */
protected EntityManagerFactory lookupEntityManagerFactory() {
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
	String emfBeanName = getEntityManagerFactoryBeanName();
	String puName = getPersistenceUnitName();
	if (StringUtils.hasLength(emfBeanName)) {
		return wac.getBean(emfBeanName, EntityManagerFactory.class);
	}
	else if (!StringUtils.hasLength(puName) && wac.containsBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME)) {
		return wac.getBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME, EntityManagerFactory.class);
	}
	else {
		// Includes fallback search for single EntityManagerFactory bean by type.
		return EntityManagerFactoryUtils.findEntityManagerFactory(wac, puName);
	}
}
 
Example 2
Source File: OpenEntityManagerInViewFilter.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Look up the EntityManagerFactory that this filter should use.
 * <p>The default implementation looks for a bean with the specified name
 * in Spring's root application context.
 * @return the EntityManagerFactory to use
 * @see #getEntityManagerFactoryBeanName
 */
protected EntityManagerFactory lookupEntityManagerFactory() {
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
	String emfBeanName = getEntityManagerFactoryBeanName();
	String puName = getPersistenceUnitName();
	if (StringUtils.hasLength(emfBeanName)) {
		return wac.getBean(emfBeanName, EntityManagerFactory.class);
	}
	else if (!StringUtils.hasLength(puName) && wac.containsBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME)) {
		return wac.getBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME, EntityManagerFactory.class);
	}
	else {
		// Includes fallback search for single EntityManagerFactory bean by type.
		return EntityManagerFactoryUtils.findEntityManagerFactory(wac, puName);
	}
}
 
Example 3
Source File: OpenEntityManagerInViewFilter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Look up the EntityManagerFactory that this filter should use.
 * <p>The default implementation looks for a bean with the specified name
 * in Spring's root application context.
 * @return the EntityManagerFactory to use
 * @see #getEntityManagerFactoryBeanName
 */
protected EntityManagerFactory lookupEntityManagerFactory() {
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
	String emfBeanName = getEntityManagerFactoryBeanName();
	String puName = getPersistenceUnitName();
	if (StringUtils.hasLength(emfBeanName)) {
		return wac.getBean(emfBeanName, EntityManagerFactory.class);
	}
	else if (!StringUtils.hasLength(puName) && wac.containsBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME)) {
		return wac.getBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME, EntityManagerFactory.class);
	}
	else {
		// Includes fallback search for single EntityManagerFactory bean by type.
		return EntityManagerFactoryUtils.findEntityManagerFactory(wac, puName);
	}
}
 
Example 4
Source File: OpenEntityManagerInViewFilter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Look up the EntityManagerFactory that this filter should use.
 * <p>The default implementation looks for a bean with the specified name
 * in Spring's root application context.
 * @return the EntityManagerFactory to use
 * @see #getEntityManagerFactoryBeanName
 */
protected EntityManagerFactory lookupEntityManagerFactory() {
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
	String emfBeanName = getEntityManagerFactoryBeanName();
	String puName = getPersistenceUnitName();
	if (StringUtils.hasLength(emfBeanName)) {
		return wac.getBean(emfBeanName, EntityManagerFactory.class);
	}
	else if (!StringUtils.hasLength(puName) && wac.containsBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME)) {
		return wac.getBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME, EntityManagerFactory.class);
	}
	else {
		// Includes fallback search for single EntityManagerFactory bean by type.
		return EntityManagerFactoryUtils.findEntityManagerFactory(wac, puName);
	}
}
 
Example 5
Source File: PersistenceAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Find an EntityManagerFactory with the given name in the current
 * Spring application context.
 * @param unitName the name of the persistence unit (never empty)
 * @param requestingBeanName the name of the requesting bean
 * @return the EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context
 */
protected EntityManagerFactory findNamedEntityManagerFactory(String unitName, @Nullable String requestingBeanName)
		throws NoSuchBeanDefinitionException {

	Assert.state(this.beanFactory != null, "ListableBeanFactory required for EntityManagerFactory bean lookup");

	EntityManagerFactory emf = EntityManagerFactoryUtils.findEntityManagerFactory(this.beanFactory, unitName);
	if (requestingBeanName != null && this.beanFactory instanceof ConfigurableBeanFactory) {
		((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
	}
	return emf;
}
 
Example 6
Source File: PersistenceAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Find an EntityManagerFactory with the given name in the current
 * Spring application context.
 * @param unitName the name of the persistence unit (never empty)
 * @param requestingBeanName the name of the requesting bean
 * @return the EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context
 */
protected EntityManagerFactory findNamedEntityManagerFactory(String unitName, @Nullable String requestingBeanName)
		throws NoSuchBeanDefinitionException {

	Assert.state(this.beanFactory != null, "ListableBeanFactory required for EntityManagerFactory bean lookup");

	EntityManagerFactory emf = EntityManagerFactoryUtils.findEntityManagerFactory(this.beanFactory, unitName);
	if (requestingBeanName != null && this.beanFactory instanceof ConfigurableBeanFactory) {
		((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
	}
	return emf;
}
 
Example 7
Source File: PersistenceAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find an EntityManagerFactory with the given name in the current
 * Spring application context.
 * @param unitName the name of the persistence unit (never empty)
 * @param requestingBeanName the name of the requesting bean
 * @return the EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context
 */
protected EntityManagerFactory findNamedEntityManagerFactory(String unitName, String requestingBeanName)
		throws NoSuchBeanDefinitionException {

	EntityManagerFactory emf = EntityManagerFactoryUtils.findEntityManagerFactory(this.beanFactory, unitName);
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
	}
	return emf;
}
 
Example 8
Source File: PersistenceAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Find an EntityManagerFactory with the given name in the current
 * Spring application context.
 * @param unitName the name of the persistence unit (never empty)
 * @param requestingBeanName the name of the requesting bean
 * @return the EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context
 */
protected EntityManagerFactory findNamedEntityManagerFactory(String unitName, String requestingBeanName)
		throws NoSuchBeanDefinitionException {

	EntityManagerFactory emf = EntityManagerFactoryUtils.findEntityManagerFactory(this.beanFactory, unitName);
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
	}
	return emf;
}