Java Code Examples for org.springframework.orm.jpa.ExtendedEntityManagerCreator#createContainerManagedEntityManager()

The following examples show how to use org.springframework.orm.jpa.ExtendedEntityManagerCreator#createContainerManagedEntityManager() . 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: PersistenceAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private EntityManager resolveExtendedEntityManager(Object target, @Nullable String requestingBeanName) {
	// Obtain EntityManager reference from JNDI?
	EntityManager em = getPersistenceContext(this.unitName, true);
	if (em == null) {
		// No pre-built EntityManager found -> build one based on factory.
		// Obtain EntityManagerFactory from JNDI?
		EntityManagerFactory emf = getPersistenceUnit(this.unitName);
		if (emf == null) {
			// Need to search for EntityManagerFactory beans.
			emf = findEntityManagerFactory(this.unitName, requestingBeanName);
		}
		// Inject a container-managed extended EntityManager.
		em = ExtendedEntityManagerCreator.createContainerManagedEntityManager(
				emf, this.properties, this.synchronizedWithTransaction);
	}
	if (em instanceof EntityManagerProxy && beanFactory != null && requestingBeanName != null &&
			beanFactory.containsBean(requestingBeanName) && !beanFactory.isPrototype(requestingBeanName)) {
		extendedEntityManagersToClose.put(target, ((EntityManagerProxy) em).getTargetEntityManager());
	}
	return em;
}
 
Example 2
Source File: PersistenceAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
private EntityManager resolveExtendedEntityManager(Object target, @Nullable String requestingBeanName) {
	// Obtain EntityManager reference from JNDI?
	EntityManager em = getPersistenceContext(this.unitName, true);
	if (em == null) {
		// No pre-built EntityManager found -> build one based on factory.
		// Obtain EntityManagerFactory from JNDI?
		EntityManagerFactory emf = getPersistenceUnit(this.unitName);
		if (emf == null) {
			// Need to search for EntityManagerFactory beans.
			emf = findEntityManagerFactory(this.unitName, requestingBeanName);
		}
		// Inject a container-managed extended EntityManager.
		em = ExtendedEntityManagerCreator.createContainerManagedEntityManager(
				emf, this.properties, this.synchronizedWithTransaction);
	}
	if (em instanceof EntityManagerProxy && beanFactory != null && requestingBeanName != null &&
			beanFactory.containsBean(requestingBeanName) && !beanFactory.isPrototype(requestingBeanName)) {
		extendedEntityManagersToClose.put(target, ((EntityManagerProxy) em).getTargetEntityManager());
	}
	return em;
}
 
Example 3
Source File: PersistenceAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private EntityManager resolveExtendedEntityManager(Object target, String requestingBeanName) {
	// Obtain EntityManager reference from JNDI?
	EntityManager em = getPersistenceContext(this.unitName, true);
	if (em == null) {
		// No pre-built EntityManager found -> build one based on factory.
		// Obtain EntityManagerFactory from JNDI?
		EntityManagerFactory emf = getPersistenceUnit(this.unitName);
		if (emf == null) {
			// Need to search for EntityManagerFactory beans.
			emf = findEntityManagerFactory(this.unitName, requestingBeanName);
		}
		// Inject a container-managed extended EntityManager.
		em = ExtendedEntityManagerCreator.createContainerManagedEntityManager(
				emf, this.properties, this.synchronizedWithTransaction);
	}
	if (em instanceof EntityManagerProxy && beanFactory != null &&
			beanFactory.containsBean(requestingBeanName) && !beanFactory.isPrototype(requestingBeanName)) {
		extendedEntityManagersToClose.put(target, ((EntityManagerProxy) em).getTargetEntityManager());
	}
	return em;
}
 
Example 4
Source File: PersistenceAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private EntityManager resolveExtendedEntityManager(Object target, String requestingBeanName) {
	// Obtain EntityManager reference from JNDI?
	EntityManager em = getPersistenceContext(this.unitName, true);
	if (em == null) {
		// No pre-built EntityManager found -> build one based on factory.
		// Obtain EntityManagerFactory from JNDI?
		EntityManagerFactory emf = getPersistenceUnit(this.unitName);
		if (emf == null) {
			// Need to search for EntityManagerFactory beans.
			emf = findEntityManagerFactory(this.unitName, requestingBeanName);
		}
		// Inject a container-managed extended EntityManager.
		em = ExtendedEntityManagerCreator.createContainerManagedEntityManager(
				emf, this.properties, this.synchronizedWithTransaction);
	}
	if (em instanceof EntityManagerProxy && beanFactory != null &&
			beanFactory.containsBean(requestingBeanName) && !beanFactory.isPrototype(requestingBeanName)) {
		extendedEntityManagersToClose.put(target, ((EntityManagerProxy) em).getTargetEntityManager());
	}
	return em;
}
 
Example 5
Source File: AbstractJpaTests.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create an EntityManager that will always automatically enlist itself in current
 * transactions, in contrast to an EntityManager returned by
 * {@code EntityManagerFactory.createEntityManager()}
 * (which requires an explicit {@code joinTransaction()} call).
 */
protected EntityManager createContainerManagedEntityManager() {
	return ExtendedEntityManagerCreator.createContainerManagedEntityManager(this.entityManagerFactory);
}