|
|
|
@ -280,8 +280,8 @@ public abstract class AbstractEntityManagerFactoryBean implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the JpaVendorAdapter implementation for this |
|
|
|
* Return the JpaVendorAdapter implementation for this EntityManagerFactory, |
|
|
|
* EntityManagerFactory, or {@code null} if not known. |
|
|
|
* or {@code null} if not known. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public JpaVendorAdapter getJpaVendorAdapter() { |
|
|
|
public JpaVendorAdapter getJpaVendorAdapter() { |
|
|
|
@ -335,13 +335,16 @@ public abstract class AbstractEntityManagerFactoryBean implements |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public final void afterPropertiesSet() throws PersistenceException { |
|
|
|
public void afterPropertiesSet() throws PersistenceException { |
|
|
|
if (this.jpaVendorAdapter != null) { |
|
|
|
JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter(); |
|
|
|
|
|
|
|
if (jpaVendorAdapter != null) { |
|
|
|
if (this.persistenceProvider == null) { |
|
|
|
if (this.persistenceProvider == null) { |
|
|
|
this.persistenceProvider = this.jpaVendorAdapter.getPersistenceProvider(); |
|
|
|
this.persistenceProvider = jpaVendorAdapter.getPersistenceProvider(); |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String, ?> vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap(); |
|
|
|
PersistenceUnitInfo pui = getPersistenceUnitInfo(); |
|
|
|
if (vendorPropertyMap != null) { |
|
|
|
Map<String, ?> vendorPropertyMap = (pui != null ? jpaVendorAdapter.getJpaPropertyMap(pui) : |
|
|
|
|
|
|
|
jpaVendorAdapter.getJpaPropertyMap()); |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(vendorPropertyMap)) { |
|
|
|
vendorPropertyMap.forEach((key, value) -> { |
|
|
|
vendorPropertyMap.forEach((key, value) -> { |
|
|
|
if (!this.jpaPropertyMap.containsKey(key)) { |
|
|
|
if (!this.jpaPropertyMap.containsKey(key)) { |
|
|
|
this.jpaPropertyMap.put(key, value); |
|
|
|
this.jpaPropertyMap.put(key, value); |
|
|
|
@ -349,25 +352,25 @@ public abstract class AbstractEntityManagerFactoryBean implements |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.entityManagerFactoryInterface == null) { |
|
|
|
if (this.entityManagerFactoryInterface == null) { |
|
|
|
this.entityManagerFactoryInterface = this.jpaVendorAdapter.getEntityManagerFactoryInterface(); |
|
|
|
this.entityManagerFactoryInterface = jpaVendorAdapter.getEntityManagerFactoryInterface(); |
|
|
|
if (!ClassUtils.isVisible(this.entityManagerFactoryInterface, this.beanClassLoader)) { |
|
|
|
if (!ClassUtils.isVisible(this.entityManagerFactoryInterface, this.beanClassLoader)) { |
|
|
|
this.entityManagerFactoryInterface = EntityManagerFactory.class; |
|
|
|
this.entityManagerFactoryInterface = EntityManagerFactory.class; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.entityManagerInterface == null) { |
|
|
|
if (this.entityManagerInterface == null) { |
|
|
|
this.entityManagerInterface = this.jpaVendorAdapter.getEntityManagerInterface(); |
|
|
|
this.entityManagerInterface = jpaVendorAdapter.getEntityManagerInterface(); |
|
|
|
if (!ClassUtils.isVisible(this.entityManagerInterface, this.beanClassLoader)) { |
|
|
|
if (!ClassUtils.isVisible(this.entityManagerInterface, this.beanClassLoader)) { |
|
|
|
this.entityManagerInterface = EntityManager.class; |
|
|
|
this.entityManagerInterface = EntityManager.class; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.jpaDialect == null) { |
|
|
|
if (this.jpaDialect == null) { |
|
|
|
this.jpaDialect = this.jpaVendorAdapter.getJpaDialect(); |
|
|
|
this.jpaDialect = jpaVendorAdapter.getJpaDialect(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.bootstrapExecutor != null) { |
|
|
|
AsyncTaskExecutor bootstrapExecutor = getBootstrapExecutor(); |
|
|
|
this.nativeEntityManagerFactoryFuture = this.bootstrapExecutor.submit( |
|
|
|
if (bootstrapExecutor != null) { |
|
|
|
this::buildNativeEntityManagerFactory); |
|
|
|
this.nativeEntityManagerFactoryFuture = bootstrapExecutor.submit(this::buildNativeEntityManagerFactory); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
this.nativeEntityManagerFactory = buildNativeEntityManagerFactory(); |
|
|
|
this.nativeEntityManagerFactory = buildNativeEntityManagerFactory(); |
|
|
|
@ -382,8 +385,9 @@ public abstract class AbstractEntityManagerFactoryBean implements |
|
|
|
|
|
|
|
|
|
|
|
private EntityManagerFactory buildNativeEntityManagerFactory() { |
|
|
|
private EntityManagerFactory buildNativeEntityManagerFactory() { |
|
|
|
EntityManagerFactory emf = createNativeEntityManagerFactory(); |
|
|
|
EntityManagerFactory emf = createNativeEntityManagerFactory(); |
|
|
|
if (this.jpaVendorAdapter != null) { |
|
|
|
JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter(); |
|
|
|
this.jpaVendorAdapter.postProcessEntityManagerFactory(emf); |
|
|
|
if (jpaVendorAdapter != null) { |
|
|
|
|
|
|
|
jpaVendorAdapter.postProcessEntityManagerFactory(emf); |
|
|
|
} |
|
|
|
} |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
logger.info("Initialized JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName() + "'"); |
|
|
|
logger.info("Initialized JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName() + "'"); |
|
|
|
@ -401,8 +405,9 @@ public abstract class AbstractEntityManagerFactoryBean implements |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected EntityManagerFactory createEntityManagerFactoryProxy(@Nullable EntityManagerFactory emf) { |
|
|
|
protected EntityManagerFactory createEntityManagerFactoryProxy(@Nullable EntityManagerFactory emf) { |
|
|
|
Set<Class<?>> ifcs = new LinkedHashSet<>(); |
|
|
|
Set<Class<?>> ifcs = new LinkedHashSet<>(); |
|
|
|
if (this.entityManagerFactoryInterface != null) { |
|
|
|
Class<?> entityManagerFactoryInterface = this.entityManagerFactoryInterface; |
|
|
|
ifcs.add(this.entityManagerFactoryInterface); |
|
|
|
if (entityManagerFactoryInterface != null) { |
|
|
|
|
|
|
|
ifcs.add(entityManagerFactoryInterface); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (emf != null) { |
|
|
|
else if (emf != null) { |
|
|
|
ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(emf.getClass(), this.beanClassLoader)); |
|
|
|
ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(emf.getClass(), this.beanClassLoader)); |
|
|
|
@ -417,8 +422,8 @@ public abstract class AbstractEntityManagerFactoryBean implements |
|
|
|
new ManagedEntityManagerFactoryInvocationHandler(this)); |
|
|
|
new ManagedEntityManagerFactoryInvocationHandler(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IllegalArgumentException ex) { |
|
|
|
catch (IllegalArgumentException ex) { |
|
|
|
if (this.entityManagerFactoryInterface != null) { |
|
|
|
if (entityManagerFactoryInterface != null) { |
|
|
|
throw new IllegalStateException("EntityManagerFactory interface [" + this.entityManagerFactoryInterface + |
|
|
|
throw new IllegalStateException("EntityManagerFactory interface [" + entityManagerFactoryInterface + |
|
|
|
"] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the "+ |
|
|
|
"] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the "+ |
|
|
|
"'entityManagerFactoryInterface' property to plain [javax.persistence.EntityManagerFactory]", ex); |
|
|
|
"'entityManagerFactoryInterface' property to plain [javax.persistence.EntityManagerFactory]", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -497,7 +502,8 @@ public abstract class AbstractEntityManagerFactoryBean implements |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public DataAccessException translateExceptionIfPossible(RuntimeException ex) { |
|
|
|
public DataAccessException translateExceptionIfPossible(RuntimeException ex) { |
|
|
|
return (this.jpaDialect != null ? this.jpaDialect.translateExceptionIfPossible(ex) : |
|
|
|
JpaDialect jpaDialect = getJpaDialect(); |
|
|
|
|
|
|
|
return (jpaDialect != null ? jpaDialect.translateExceptionIfPossible(ex) : |
|
|
|
EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex)); |
|
|
|
EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|