Polishing
Issue: SPR-12396
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,15 +55,15 @@ import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Abstract {@link org.springframework.beans.factory.FactoryBean} that
|
||||
* creates a local JPA {@link javax.persistence.EntityManagerFactory}
|
||||
* instance within a Spring application context.
|
||||
* Abstract {@link org.springframework.beans.factory.FactoryBean} that creates
|
||||
* a local JPA {@link javax.persistence.EntityManagerFactory} instance within
|
||||
* a Spring application context.
|
||||
*
|
||||
* <p>Encapsulates the common functionality between the different JPA
|
||||
* bootstrap contracts (standalone as well as container).
|
||||
* <p>Encapsulates the common functionality between the different JPA bootstrap
|
||||
* contracts (standalone as well as container).
|
||||
*
|
||||
* <p>Implements support for standard JPA configuration as well as
|
||||
* Spring's {@link JpaVendorAdapter} abstraction, and controls the
|
||||
* <p>Implements support for standard JPA configuration conventions as well as
|
||||
* Spring's customizable {@link JpaVendorAdapter} mechanism, and controls the
|
||||
* EntityManagerFactory's lifecycle.
|
||||
*
|
||||
* <p>This class also implements the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,8 +33,8 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Base class for any class that needs to access an EntityManagerFactory,
|
||||
* usually in order to obtain an EntityManager. Defines common properties.
|
||||
* Base class for any class that needs to access a JPA {@link EntityManagerFactory},
|
||||
* usually in order to obtain a JPA {@link EntityManager}. Defines common properties.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -80,6 +80,7 @@ public abstract class EntityManagerFactoryUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(EntityManagerFactoryUtils.class);
|
||||
|
||||
|
||||
private static Method createEntityManagerWithSynchronizationTypeMethod;
|
||||
|
||||
private static Object synchronizationTypeUnsynchronized;
|
||||
@@ -144,9 +145,8 @@ public abstract class EntityManagerFactoryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a
|
||||
* corresponding EntityManager bound to the current thread,
|
||||
* for example when using JpaTransactionManager.
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a corresponding
|
||||
* EntityManager bound to the current thread, e.g. when using JpaTransactionManager.
|
||||
* <p>Note: Will return {@code null} if no thread-bound EntityManager found!
|
||||
* @param emf EntityManagerFactory to create the EntityManager with
|
||||
* @return the EntityManager, or {@code null} if none found
|
||||
@@ -160,9 +160,8 @@ public abstract class EntityManagerFactoryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a
|
||||
* corresponding EntityManager bound to the current thread,
|
||||
* for example when using JpaTransactionManager.
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a corresponding
|
||||
* EntityManager bound to the current thread, e.g. when using JpaTransactionManager.
|
||||
* <p>Note: Will return {@code null} if no thread-bound EntityManager found!
|
||||
* @param emf EntityManagerFactory to create the EntityManager with
|
||||
* @param properties the properties to be passed into the {@code createEntityManager}
|
||||
@@ -182,9 +181,8 @@ public abstract class EntityManagerFactoryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a
|
||||
* corresponding EntityManager bound to the current thread,
|
||||
* for example when using JpaTransactionManager.
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a corresponding
|
||||
* EntityManager bound to the current thread, e.g. when using JpaTransactionManager.
|
||||
* <p>Same as {@code getEntityManager}, but throwing the original PersistenceException.
|
||||
* @param emf EntityManagerFactory to create the EntityManager with
|
||||
* @param properties the properties to be passed into the {@code createEntityManager}
|
||||
@@ -201,9 +199,8 @@ public abstract class EntityManagerFactoryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a
|
||||
* corresponding EntityManager bound to the current thread,
|
||||
* for example when using JpaTransactionManager.
|
||||
* Obtain a JPA EntityManager from the given factory. Is aware of a corresponding
|
||||
* EntityManager bound to the current thread, e.g. when using JpaTransactionManager.
|
||||
* <p>Same as {@code getEntityManager}, but throwing the original PersistenceException.
|
||||
* @param emf EntityManagerFactory to create the EntityManager with
|
||||
* @param properties the properties to be passed into the {@code createEntityManager}
|
||||
@@ -285,8 +282,8 @@ public abstract class EntityManagerFactoryUtils {
|
||||
em = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager());
|
||||
}
|
||||
|
||||
// Use same EntityManager for further JPA actions within the transaction.
|
||||
// Thread object will get removed by synchronization at transaction completion.
|
||||
// Use same EntityManager for further JPA operations within the transaction.
|
||||
// Thread-bound object will get removed by synchronization at transaction completion.
|
||||
logger.debug("Registering transaction synchronization for JPA EntityManager");
|
||||
emHolder = new EntityManagerHolder(em);
|
||||
if (synchronizedWithTransaction) {
|
||||
@@ -296,7 +293,7 @@ public abstract class EntityManagerFactoryUtils {
|
||||
emHolder.setSynchronizedWithTransaction(true);
|
||||
}
|
||||
else {
|
||||
// unsynchronized - just scope it for the transaction, as demanded by the JPA 2.1 spec
|
||||
// Unsynchronized - just scope it for the transaction, as demanded by the JPA 2.1 spec...
|
||||
TransactionSynchronizationManager.registerSynchronization(
|
||||
new TransactionScopedEntityManagerSynchronization(emHolder, emf));
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ public abstract class ExtendedEntityManagerCreator {
|
||||
* 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) {
|
||||
@@ -156,6 +157,7 @@ public abstract class ExtendedEntityManagerCreator {
|
||||
* @return a container-managed EntityManager that expects container-driven lifecycle
|
||||
* management but may opt out of automatic transaction synchronization
|
||||
* @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map)
|
||||
* @since 4.0
|
||||
*/
|
||||
public static EntityManager createContainerManagedEntityManager(
|
||||
EntityManagerFactory emf, Map<?, ?> properties, boolean synchronizedWithTransaction) {
|
||||
|
||||
@@ -68,7 +68,9 @@ import org.springframework.util.ClassUtils;
|
||||
* metadata as assembled by this FactoryBean.
|
||||
*
|
||||
* <p><b>NOTE: Spring's JPA support requires JPA 2.0 or higher, as of Spring 4.0.</b>
|
||||
* Spring's persistence unit bootstrapping automatically detects JPA 2.1 at runtime.
|
||||
* JPA 1.0 based applications are still supported; however, a JPA 2.0/2.1 compliant
|
||||
* persistence provider is needed at runtime. Spring's persistence unit bootstrapping
|
||||
* automatically detects JPA 2.0 vs 2.1 through checking the JPA API on the classpath.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rod Johnson
|
||||
|
||||
@@ -41,7 +41,7 @@ import javax.persistence.spi.PersistenceProvider;
|
||||
* <p>This EntityManagerFactory bootstrap is appropriate for standalone applications
|
||||
* which solely use JPA for data access. If you want to set up your persistence
|
||||
* provider for an external DataSource and/or for global transactions which span
|
||||
* multiple resources, you will need to either deploy it into a full Java EE 5
|
||||
* multiple resources, you will need to either deploy it into a full Java EE
|
||||
* application server and access the deployed EntityManagerFactory via JNDI,
|
||||
* or use Spring's {@link LocalContainerEntityManagerFactoryBean} with appropriate
|
||||
* configuration for local setup according to JPA's container contract.
|
||||
@@ -53,6 +53,8 @@ import javax.persistence.spi.PersistenceProvider;
|
||||
* {@link LocalContainerEntityManagerFactoryBean} instead.
|
||||
*
|
||||
* <p><b>NOTE: Spring's JPA support requires JPA 2.0 or higher, as of Spring 4.0.</b>
|
||||
* JPA 1.0 based applications are still supported; however, a JPA 2.0/2.1 compliant
|
||||
* persistence provider is needed at runtime.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rod Johnson
|
||||
|
||||
@@ -110,6 +110,7 @@ public abstract class SharedEntityManagerCreator {
|
||||
* @param synchronizedWithTransaction whether to automatically join ongoing
|
||||
* transactions (according to the JPA 2.1 SynchronizationType rules)
|
||||
* @return a shareable transaction EntityManager proxy
|
||||
* @since 4.0
|
||||
*/
|
||||
public static EntityManager createSharedEntityManager(
|
||||
EntityManagerFactory emf, Map<?, ?> properties, boolean synchronizedWithTransaction) {
|
||||
@@ -145,6 +146,7 @@ public abstract class SharedEntityManagerCreator {
|
||||
* @param entityManagerInterfaces the interfaces to be implemented by the
|
||||
* EntityManager. Allows the addition or specification of proprietary interfaces.
|
||||
* @return a shareable transactional EntityManager proxy
|
||||
* @since 4.0
|
||||
*/
|
||||
public static EntityManager createSharedEntityManager(EntityManagerFactory emf, Map<?, ?> properties,
|
||||
boolean synchronizedWithTransaction, Class<?>... entityManagerInterfaces) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
||||
* {@link FactoryBean} that exposes a shared JPA {@link javax.persistence.EntityManager}
|
||||
* reference for a given EntityManagerFactory. Typically used for an EntityManagerFactory
|
||||
* created by {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean},
|
||||
* as direct alternative to a JNDI lookup for a Java EE 5 server's EntityManager reference.
|
||||
* as direct alternative to a JNDI lookup for a Java EE server's EntityManager reference.
|
||||
*
|
||||
* <p>The shared EntityManager will behave just like an EntityManager fetched from an
|
||||
* application server's JNDI environment, as defined by the JPA specification.
|
||||
|
||||
Reference in New Issue
Block a user