/** * Create an application-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @return an application-managed EntityManager that can join transactions * but does not participate in them automatically */ public static EntityManager createApplicationManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) { return createProxy(rawEntityManager, emfInfo, false, false); }
/** * Create a container-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @return a container-managed EntityManager that will automatically participate * in any managed transaction */ public static EntityManager createContainerManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) { return createProxy(rawEntityManager, emfInfo, true, true); }
/** * Create an application-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return an application-managed EntityManager that can join transactions * but does not participate in them automatically * @since 4.0 */ public static EntityManager createApplicationManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean synchronizedWithTransaction) { return createProxy(rawEntityManager, emfInfo, false, synchronizedWithTransaction); }
/** * Create a container-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @return a container-managed EntityManager that will automatically participate * in any managed transaction */ public static EntityManager createContainerManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) { return createProxy(rawEntityManager, emfInfo, true, true); }
/** * Create an application-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @return an application-managed EntityManager that can join transactions * but does not participate in them automatically */ public static EntityManager createApplicationManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) { return createProxy(rawEntityManager, emfInfo, false, false); }
/** * Create an application-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return an application-managed EntityManager that can join transactions * but does not participate in them automatically * @since 4.0 */ public static EntityManager createApplicationManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean synchronizedWithTransaction) { return createProxy(rawEntityManager, emfInfo, false, synchronizedWithTransaction); }
/** * Create a container-managed extended EntityManager proxy. * @param emf the EntityManagerFactory to create the EntityManager with. * If this implements the EntityManagerFactoryInfo interface, the corresponding * JpaDialect and PersistenceUnitInfo will be detected accordingly. * @param properties the properties to be passed into the {@code createEntityManager} * call (may be {@code null}) * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return a container-managed EntityManager that expects container-driven lifecycle * management but may opt out of automatic transaction synchronization * @since 4.0 * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ public static EntityManager createContainerManagedEntityManager( EntityManagerFactory emf, @Nullable Map<?, ?> properties, boolean synchronizedWithTransaction) { Assert.notNull(emf, "EntityManagerFactory must not be null"); if (emf instanceof EntityManagerFactoryInfo) { EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf; EntityManagerFactory nativeEmf = emfInfo.getNativeEntityManagerFactory(); EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? nativeEmf.createEntityManager(properties) : nativeEmf.createEntityManager()); return createProxy(rawEntityManager, emfInfo, true, synchronizedWithTransaction); } else { EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); return createProxy(rawEntityManager, null, null, null, null, true, synchronizedWithTransaction); } }
/** * Create a container-managed extended EntityManager proxy. * @param emf the EntityManagerFactory to create the EntityManager with. * If this implements the EntityManagerFactoryInfo interface, the corresponding * JpaDialect and PersistenceUnitInfo will be detected accordingly. * @param properties the properties to be passed into the {@code createEntityManager} * call (may be {@code null}) * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return a container-managed EntityManager that expects container-driven lifecycle * management but may opt out of automatic transaction synchronization * @since 4.0 * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ public static EntityManager createContainerManagedEntityManager( EntityManagerFactory emf, @Nullable Map<?, ?> properties, boolean synchronizedWithTransaction) { Assert.notNull(emf, "EntityManagerFactory must not be null"); if (emf instanceof EntityManagerFactoryInfo) { EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf; EntityManagerFactory nativeEmf = emfInfo.getNativeEntityManagerFactory(); EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? nativeEmf.createEntityManager(properties) : nativeEmf.createEntityManager()); return createProxy(rawEntityManager, emfInfo, true, synchronizedWithTransaction); } else { EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); return createProxy(rawEntityManager, null, null, null, null, true, synchronizedWithTransaction); } }
/** * Actually create the EntityManager proxy. * @param rawEntityManager raw EntityManager * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param containerManaged whether to follow container-managed EntityManager * or application-managed EntityManager semantics * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return the EntityManager proxy */ private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null"); JpaDialect jpaDialect = emfInfo.getJpaDialect(); PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo(); Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null); return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(), emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction); }
/** * Actually create the EntityManager proxy. * @param rawEntityManager raw EntityManager * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param containerManaged whether to follow container-managed EntityManager * or application-managed EntityManager semantics * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return the EntityManager proxy */ private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null"); JpaDialect jpaDialect = emfInfo.getJpaDialect(); PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo(); Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null); return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(), emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction); }
/** * Create a container-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @return a container-managed EntityManager that will automatically participate * in any managed transaction */ public static EntityManager createContainerManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) { return createProxy(rawEntityManager, emfInfo, true, true); }
/** * Create an application-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @return an application-managed EntityManager that can join transactions * but does not participate in them automatically */ public static EntityManager createApplicationManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) { return createProxy(rawEntityManager, emfInfo, false, false); }
/** * Create an application-managed extended EntityManager proxy. * @param rawEntityManager the raw EntityManager to decorate * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return an application-managed EntityManager that can join transactions * but does not participate in them automatically * @since 4.0 */ public static EntityManager createApplicationManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean synchronizedWithTransaction) { return createProxy(rawEntityManager, emfInfo, false, synchronizedWithTransaction); }
/** * Create a container-managed extended EntityManager proxy. * @param emf the EntityManagerFactory to create the EntityManager with. * If this implements the EntityManagerFactoryInfo interface, the corresponding * JpaDialect and PersistenceUnitInfo will be detected accordingly. * @param properties the properties to be passed into the {@code createEntityManager} * call (may be {@code null}) * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return a container-managed EntityManager that expects container-driven lifecycle * management but may opt out of automatic transaction synchronization * @since 4.0 * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ public static EntityManager createContainerManagedEntityManager( EntityManagerFactory emf, @Nullable Map<?, ?> properties, boolean synchronizedWithTransaction) { Assert.notNull(emf, "EntityManagerFactory must not be null"); if (emf instanceof EntityManagerFactoryInfo) { EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf; EntityManagerFactory nativeEmf = emfInfo.getNativeEntityManagerFactory(); EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? nativeEmf.createEntityManager(properties) : nativeEmf.createEntityManager()); return createProxy(rawEntityManager, emfInfo, true, synchronizedWithTransaction); } else { EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); return createProxy(rawEntityManager, null, null, null, null, true, synchronizedWithTransaction); } }
/** * Actually create the EntityManager proxy. * @param rawEntityManager raw EntityManager * @param emfInfo the EntityManagerFactoryInfo to obtain the JpaDialect * and PersistenceUnitInfo from * @param containerManaged whether to follow container-managed EntityManager * or application-managed EntityManager semantics * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return the EntityManager proxy */ private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(emfInfo, "EntityManagerFactoryInfo must not be null"); JpaDialect jpaDialect = emfInfo.getJpaDialect(); PersistenceUnitInfo pui = emfInfo.getPersistenceUnitInfo(); Boolean jta = (pui != null ? pui.getTransactionType() == PersistenceUnitTransactionType.JTA : null); return createProxy(rawEntityManager, emfInfo.getEntityManagerInterface(), emfInfo.getBeanClassLoader(), jpaDialect, jta, containerManaged, synchronizedWithTransaction); }