Added JPA 2.0 compliant "sharedCacheMode" and "validationMode" properties to DefaultPersistenceUnitManager and LocalContainerEntityManagerFactoryBean
Issue: SPR-10764
This commit is contained in:
parent
a841923f12
commit
219eeb2369
|
|
@ -18,6 +18,8 @@ package org.springframework.orm.jpa;
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
|
import javax.persistence.SharedCacheMode;
|
||||||
|
import javax.persistence.ValidationMode;
|
||||||
import javax.persistence.spi.PersistenceProvider;
|
import javax.persistence.spi.PersistenceProvider;
|
||||||
import javax.persistence.spi.PersistenceUnitInfo;
|
import javax.persistence.spi.PersistenceUnitInfo;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
@ -66,6 +68,7 @@ import org.springframework.util.ClassUtils;
|
||||||
* metadata as assembled by this FactoryBean.
|
* 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>
|
* <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.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
|
@ -170,6 +173,28 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
||||||
this.internalPersistenceUnitManager.setMappingResources(mappingResources);
|
this.internalPersistenceUnitManager.setMappingResources(mappingResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the JPA 2.0 shared cache mode for this persistence unit,
|
||||||
|
* overriding a value in {@code persistence.xml} if set.
|
||||||
|
* <p><b>NOTE: Only applied if no external PersistenceUnitManager specified.</b>
|
||||||
|
* @see javax.persistence.spi.PersistenceUnitInfo#getSharedCacheMode()
|
||||||
|
* @see #setPersistenceUnitManager
|
||||||
|
*/
|
||||||
|
public void setSharedCacheMode(SharedCacheMode sharedCacheMode) {
|
||||||
|
this.internalPersistenceUnitManager.setSharedCacheMode(sharedCacheMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the JPA 2.0 validation mode for this persistence unit,
|
||||||
|
* overriding a value in {@code persistence.xml} if set.
|
||||||
|
* <p><b>NOTE: Only applied if no external PersistenceUnitManager specified.</b>
|
||||||
|
* @see javax.persistence.spi.PersistenceUnitInfo#getValidationMode()
|
||||||
|
* @see #setPersistenceUnitManager
|
||||||
|
*/
|
||||||
|
public void setValidationMode(ValidationMode validationMode) {
|
||||||
|
this.internalPersistenceUnitManager.setValidationMode(validationMode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the JDBC DataSource that the JPA persistence provider is supposed
|
* Specify the JDBC DataSource that the JPA persistence provider is supposed
|
||||||
* to use for accessing the database. This is an alternative to keeping the
|
* to use for accessing the database. This is an alternative to keeping the
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ import javax.persistence.Embeddable;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
|
import javax.persistence.SharedCacheMode;
|
||||||
|
import javax.persistence.ValidationMode;
|
||||||
import javax.persistence.spi.PersistenceUnitInfo;
|
import javax.persistence.spi.PersistenceUnitInfo;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
|
@ -68,6 +70,9 @@ import org.springframework.util.ResourceUtils;
|
||||||
* DataSource names are by default interpreted as JNDI names, and no load time weaving
|
* DataSource names are by default interpreted as JNDI names, and no load time weaving
|
||||||
* is available (which requires weaving to be turned off in the persistence provider).
|
* is available (which requires weaving to be turned off in the persistence provider).
|
||||||
*
|
*
|
||||||
|
* <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.
|
||||||
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
* @see #setPersistenceXmlLocations
|
* @see #setPersistenceXmlLocations
|
||||||
|
|
@ -124,6 +129,10 @@ public class DefaultPersistenceUnitManager
|
||||||
|
|
||||||
private String[] mappingResources;
|
private String[] mappingResources;
|
||||||
|
|
||||||
|
private SharedCacheMode sharedCacheMode;
|
||||||
|
|
||||||
|
private ValidationMode validationMode;
|
||||||
|
|
||||||
private DataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
|
private DataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
|
||||||
|
|
||||||
private DataSource defaultDataSource;
|
private DataSource defaultDataSource;
|
||||||
|
|
@ -210,6 +219,24 @@ public class DefaultPersistenceUnitManager
|
||||||
this.mappingResources = mappingResources;
|
this.mappingResources = mappingResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the JPA 2.0 shared cache mode for all of this manager's persistence
|
||||||
|
* units, overriding any value in {@code persistence.xml} if set.
|
||||||
|
* @see javax.persistence.spi.PersistenceUnitInfo#getSharedCacheMode()
|
||||||
|
*/
|
||||||
|
public void setSharedCacheMode(SharedCacheMode sharedCacheMode) {
|
||||||
|
this.sharedCacheMode = sharedCacheMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the JPA 2.0 validation mode for all of this manager's persistence
|
||||||
|
* units, overriding any value in {@code persistence.xml} if set.
|
||||||
|
* @see javax.persistence.spi.PersistenceUnitInfo#getValidationMode()
|
||||||
|
*/
|
||||||
|
public void setValidationMode(ValidationMode validationMode) {
|
||||||
|
this.validationMode = validationMode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the JDBC DataSources that the JPA persistence provider is supposed
|
* Specify the JDBC DataSources that the JPA persistence provider is supposed
|
||||||
* to use for accessing the database, resolving data source names in
|
* to use for accessing the database, resolving data source names in
|
||||||
|
|
@ -324,9 +351,6 @@ public class DefaultPersistenceUnitManager
|
||||||
* VM agent specified on JVM startup, and ReflectiveLoadTimeWeaver, which interacts
|
* VM agent specified on JVM startup, and ReflectiveLoadTimeWeaver, which interacts
|
||||||
* with an underlying ClassLoader based on specific extended methods being available
|
* with an underlying ClassLoader based on specific extended methods being available
|
||||||
* on it (for example, interacting with Spring's TomcatInstrumentableClassLoader).
|
* on it (for example, interacting with Spring's TomcatInstrumentableClassLoader).
|
||||||
* <p><b>NOTE:</b> As of Spring 2.5, the context's default LoadTimeWeaver (defined
|
|
||||||
* as bean with name "loadTimeWeaver") will be picked up automatically, if available,
|
|
||||||
* removing the need for LoadTimeWeaver configuration on each affected target bean.</b>
|
|
||||||
* Consider using the {@code context:load-time-weaver} XML tag for creating
|
* Consider using the {@code context:load-time-weaver} XML tag for creating
|
||||||
* such a shared LoadTimeWeaver (autodetecting the environment by default).
|
* such a shared LoadTimeWeaver (autodetecting the environment by default).
|
||||||
* @see org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver
|
* @see org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver
|
||||||
|
|
@ -383,6 +407,12 @@ public class DefaultPersistenceUnitManager
|
||||||
if (pui.getNonJtaDataSource() == null) {
|
if (pui.getNonJtaDataSource() == null) {
|
||||||
pui.setNonJtaDataSource(this.defaultDataSource);
|
pui.setNonJtaDataSource(this.defaultDataSource);
|
||||||
}
|
}
|
||||||
|
if (this.sharedCacheMode != null) {
|
||||||
|
pui.setSharedCacheMode(this.sharedCacheMode);
|
||||||
|
}
|
||||||
|
if (this.validationMode != null) {
|
||||||
|
pui.setValidationMode(this.validationMode);
|
||||||
|
}
|
||||||
if (this.loadTimeWeaver != null) {
|
if (this.loadTimeWeaver != null) {
|
||||||
pui.init(this.loadTimeWeaver);
|
pui.init(this.loadTimeWeaver);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue