javax.persistence.PersistenceContextType Java Examples

The following examples show how to use javax.persistence.PersistenceContextType. 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 5 votes vote down vote up
/**
 * Resolve the object against the application context.
 */
@Override
protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
	// Resolves to EntityManagerFactory or EntityManager.
	if (this.type != null) {
		return (this.type == PersistenceContextType.EXTENDED ?
				resolveExtendedEntityManager(target, requestingBeanName) :
				resolveEntityManager(requestingBeanName));
	}
	else {
		// OK, so we need an EntityManagerFactory...
		return resolveEntityManagerFactory(requestingBeanName);
	}
}
 
Example #2
Source File: PersistenceInjectionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@PersistenceContext(type = PersistenceContextType.EXTENDED)
public void setEntityManager(EntityManager em) {
	if (this.em != null) {
		throw new IllegalStateException("Already called");
	}
	this.em = em;
}
 
Example #3
Source File: PersistenceAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Resolve the object against the application context.
 */
@Override
protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
	// Resolves to EntityManagerFactory or EntityManager.
	if (this.type != null) {
		return (this.type == PersistenceContextType.EXTENDED ?
				resolveExtendedEntityManager(target, requestingBeanName) :
				resolveEntityManager(requestingBeanName));
	}
	else {
		// OK, so we need an EntityManagerFactory...
		return resolveEntityManagerFactory(requestingBeanName);
	}
}
 
Example #4
Source File: PersistenceInjectionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@PersistenceContext(type = PersistenceContextType.EXTENDED)
public void setEntityManager(EntityManager em) {
	if (this.em != null) {
		throw new IllegalStateException("Already called");
	}
	this.em = em;
}
 
Example #5
Source File: PersistenceAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolve the object against the application context.
 */
@Override
protected Object getResourceToInject(Object target, String requestingBeanName) {
	// Resolves to EntityManagerFactory or EntityManager.
	if (this.type != null) {
		return (this.type == PersistenceContextType.EXTENDED ?
				resolveExtendedEntityManager(target, requestingBeanName) :
				resolveEntityManager(requestingBeanName));
	}
	else {
		// OK, so we need an EntityManagerFactory...
		return resolveEntityManagerFactory(requestingBeanName);
	}
}
 
Example #6
Source File: PersistenceAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the object against the application context.
 */
@Override
protected Object getResourceToInject(Object target, String requestingBeanName) {
	// Resolves to EntityManagerFactory or EntityManager.
	if (this.type != null) {
		return (this.type == PersistenceContextType.EXTENDED ?
				resolveExtendedEntityManager(target, requestingBeanName) :
				resolveEntityManager(requestingBeanName));
	}
	else {
		// OK, so we need an EntityManagerFactory...
		return resolveEntityManagerFactory(requestingBeanName);
	}
}
 
Example #7
Source File: PersistenceInjectionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@PersistenceContext(type = PersistenceContextType.EXTENDED)
public void setEntityManager(EntityManager em) {
	if (this.em != null) {
		throw new IllegalStateException("Already called");
	}
	this.em = em;
}
 
Example #8
Source File: PersistenceContextDecorator.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
@Override
public void afterTest(final TestInvocation invocation) throws Exception {
    final ExecutionContext context = invocation.getContext();

    final EntityManager em = (EntityManager) context.getData(Constants.KEY_ENTITY_MANAGER);
    if (em != null && getPersistenceContextType(context) != PersistenceContextType.EXTENDED) {
        context.storeData(Constants.KEY_ENTITY_MANAGER, null);
        em.close();
    }
}
 
Example #9
Source File: PersistenceInjectionTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@PersistenceContext(unitName="unit2", type = PersistenceContextType.EXTENDED)
public void setEntityManager(EntityManager em) {
	super.setEntityManager(em);
}
 
Example #10
Source File: PersistenceInjectionTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@PersistenceContext(unitName="unit2", type = PersistenceContextType.EXTENDED)
public void setEntityManager(EntityManager em) {
	super.setEntityManager(em);
}
 
Example #11
Source File: PersistenceInjectionTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@PersistenceContext(unitName="unit2", type = PersistenceContextType.EXTENDED)
public void setEntityManager(EntityManager em) {
	super.setEntityManager(em);
}
 
Example #12
Source File: PersistenceContextDecorator.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
private PersistenceContextType getPersistenceContextType(final ExecutionContext context) {
    final Field field = context.getPersistenceField();
    final PersistenceContext pc = field.getAnnotation(PersistenceContext.class);
    return pc.type();
}
 
Example #13
Source File: PersistenceContextAnnFactoryTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@PersistenceContext(name = "method", unitName = "mu", type = PersistenceContextType.EXTENDED, properties = {
    @PersistenceProperty(name = "method1", value = "m1"),
    @PersistenceProperty(name = "method2", value = "m2")
})
public void method() {
}
 
Example #14
Source File: PersistenceContextAnnFactoryTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@PersistenceContext(unitName = "mymu", type = PersistenceContextType.EXTENDED, properties = {
    @PersistenceProperty(name = "myMethod1", value = "mym1"),
    @PersistenceProperty(name = "myMethod2", value = "mym2")
})
public void setMyMethod() {
}