|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager
public class DefaultPersistenceUnitManager
Default implementation of the PersistenceUnitManager
interface.
Used as internal default by
LocalContainerEntityManagerFactoryBean
.
Supports standard JPA scanning for persistence.xml
files,
with configurable file locations, JDBC DataSource lookup and load-time weaving.
The default XML file location is classpath:META-INF/persistence.xml
,
scanning for all matching files in the class path (as defined in the JPA specification).
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).
setPersistenceXmlLocations(java.lang.String[])
,
setDataSourceLookup(org.springframework.jdbc.datasource.lookup.DataSourceLookup)
,
setLoadTimeWeaver(org.springframework.instrument.classloading.LoadTimeWeaver)
,
LocalContainerEntityManagerFactoryBean.setPersistenceUnitManager(org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager)
Field Summary | |
---|---|
static String |
DEFAULT_PERSISTENCE_XML_LOCATION
Default location of the persistence.xml file:
"classpath*:META-INF/persistence.xml". |
static String |
ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION
Default location for the persistence unit root URL: "classpath:", indicating the root of the class path. |
Constructor Summary | |
---|---|
DefaultPersistenceUnitManager()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
DataSourceLookup |
getDataSourceLookup()
Return the JDBC DataSourceLookup that provides DataSources for the persistence provider, resolving data source names in persistence.xml
against Spring-managed DataSource instances. |
DataSource |
getDefaultDataSource()
Return the JDBC DataSource that the JPA persistence provider is supposed to use for accessing the database if none has been specified in persistence.xml . |
LoadTimeWeaver |
getLoadTimeWeaver()
Return the Spring LoadTimeWeaver to use for class instrumentation according to the JPA class transformer contract. |
protected MutablePersistenceUnitInfo |
getPersistenceUnitInfo(String persistenceUnitName)
Return the specified PersistenceUnitInfo from this manager's cache of processed persistence units, keeping it in the cache (i.e. not 'obtaining' it for use but rather just accessing it for post-processing). |
PersistenceUnitPostProcessor[] |
getPersistenceUnitPostProcessors()
Return the PersistenceUnitPostProcessors to be applied to each PersistenceUnitInfo that has been parsed by this manager. |
javax.persistence.spi.PersistenceUnitInfo |
obtainDefaultPersistenceUnitInfo()
Obtain the default PersistenceUnitInfo from this manager. |
javax.persistence.spi.PersistenceUnitInfo |
obtainPersistenceUnitInfo(String persistenceUnitName)
Obtain the specified PersistenceUnitInfo from this manager. |
protected void |
postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui)
Hook method allowing subclasses to customize each PersistenceUnitInfo. |
void |
preparePersistenceUnitInfos()
Prepare the PersistenceUnitInfos according to the configuration of this manager: scanning for persistence.xml files,
parsing all matching files, configurating and post-processing them. |
void |
setDataSourceLookup(DataSourceLookup dataSourceLookup)
Specify the JDBC DataSourceLookup that provides DataSources for the persistence provider, resolving data source names in persistence.xml
against Spring-managed DataSource instances. |
void |
setDataSources(Map<String,DataSource> dataSources)
Specify the JDBC DataSources that the JPA persistence provider is supposed to use for accessing the database, resolving data source names in persistence.xml against Spring-managed DataSources. |
void |
setDefaultDataSource(DataSource defaultDataSource)
Specify the JDBC DataSource that the JPA persistence provider is supposed to use for accessing the database if none has been specified in persistence.xml . |
void |
setDefaultPersistenceUnitRootLocation(String defaultPersistenceUnitRootLocation)
Set the default persistence unit root location, to be applied if no unit-specific persistence unit root could be determined. |
void |
setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver)
Specify the Spring LoadTimeWeaver to use for class instrumentation according to the JPA class transformer contract. |
void |
setPersistenceUnitPostProcessors(PersistenceUnitPostProcessor[] postProcessors)
Set the PersistenceUnitPostProcessors to be applied to each PersistenceUnitInfo that has been parsed by this manager. |
void |
setPersistenceXmlLocations(String[] persistenceXmlLocations)
Set the locations of the persistence.xml files to load. |
void |
setResourceLoader(ResourceLoader resourceLoader)
Set the ResourceLoader that this object runs in. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_PERSISTENCE_XML_LOCATION
persistence.xml
file:
"classpath*:META-INF/persistence.xml".
public static final String ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION
Constructor Detail |
---|
public DefaultPersistenceUnitManager()
Method Detail |
---|
public void setPersistenceXmlLocations(String[] persistenceXmlLocations)
persistence.xml
files to load.
These can be specified as Spring resource locations and/or location patterns.
Default is "classpath*:META-INF/persistence.xml".
persistenceXmlLocations
- an array of Spring resource Strings
identifying the location of the persistence.xml
files to readpublic void setDefaultPersistenceUnitRootLocation(String defaultPersistenceUnitRootLocation)
Default is "classpath:", that is, the root of the current class path (nearest root directory). To be overridden if unit-specific resolution does not work and the class path root is not appropriate either.
public void setDataSources(Map<String,DataSource> dataSources)
persistence.xml
against Spring-managed DataSources.
The specified Map needs to define data source names for specific DataSource
objects, matching the data source names used in persistence.xml
.
If not specified, data source names will be resolved as JNDI names instead
(as defined by standard JPA).
MapDataSourceLookup
public void setDataSourceLookup(DataSourceLookup dataSourceLookup)
persistence.xml
against Spring-managed DataSource instances.
Default is JndiDataSourceLookup, which resolves DataSource names as JNDI names (as defined by standard JPA). Specify a BeanFactoryDataSourceLookup instance if you want DataSource names to be resolved against Spring bean names.
Alternatively, consider passing in a map from names to DataSource instances
via the "dataSources" property. If the persistence.xml
file
does not define DataSource names at all, specify a default DataSource
via the "defaultDataSource" property.
public DataSourceLookup getDataSourceLookup()
persistence.xml
against Spring-managed DataSource instances.
public void setDefaultDataSource(DataSource defaultDataSource)
persistence.xml
.
In JPA speak, a DataSource passed in here will be uses as "nonJtaDataSource" on the PersistenceUnitInfo passed to the PersistenceProvider, provided that none has been registered before.
PersistenceUnitInfo.getNonJtaDataSource()
public DataSource getDefaultDataSource()
persistence.xml
.
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver)
It is not required to specify a LoadTimeWeaver: Most providers will be able to provide a subset of their functionality without class instrumentation as well, or operate with their VM agent specified on JVM startup.
In terms of Spring-provided weaving options, the most important ones are InstrumentationLoadTimeWeaver, which requires a Spring-specific (but very general) VM agent specified on JVM startup, and ReflectiveLoadTimeWeaver, which interacts with an underlying ClassLoader based on specific extended methods being available on it (for example, interacting with Spring's TomcatInstrumentableClassLoader).
public LoadTimeWeaver getLoadTimeWeaver()
public void setPersistenceUnitPostProcessors(PersistenceUnitPostProcessor[] postProcessors)
Such post-processors can, for example, register further entity
classes and jar files, in addition to the metadata read in from
persistence.xml
.
public PersistenceUnitPostProcessor[] getPersistenceUnitPostProcessors()
public void setResourceLoader(ResourceLoader resourceLoader)
ResourceLoaderAware
This might be a ResourcePatternResolver, which can be checked
through instanceof ResourcePatternResolver
. See also the
ResourcePatternUtils.getResourcePatternResolver
method.
Invoked after population of normal bean properties but before an init callback
like InitializingBean's afterPropertiesSet
or a custom init-method.
Invoked before ApplicationContextAware's setApplicationContext
.
setResourceLoader
in interface ResourceLoaderAware
resourceLoader
- ResourceLoader object to be used by this objectResourcePatternResolver
,
ResourcePatternUtils.getResourcePatternResolver(org.springframework.core.io.ResourceLoader)
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
public void preparePersistenceUnitInfos()
persistence.xml
files,
parsing all matching files, configurating and post-processing them.
PersistenceUnitInfos cannot be obtained before this preparation method has been invoked.
protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName)
This can be used in postProcessPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo)
implementations,
detecting existing persistence units of the same name and potentially merging them.
persistenceUnitName
- the name of the desired persistence unit
null
if not availableprotected void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui)
Default implementation delegates to all registered PersistenceUnitPostProcessors. It is usually preferable to register further entity classes, jar files etc there rather than in a subclass of this manager, to be able to reuse the post-processors.
pui
- the chosen PersistenceUnitInfo, as read from persistence.xml
.
Passed in as MutablePersistenceUnitInfo.setPersistenceUnitPostProcessors(org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor[])
public javax.persistence.spi.PersistenceUnitInfo obtainDefaultPersistenceUnitInfo()
PersistenceUnitManager
obtainDefaultPersistenceUnitInfo
in interface PersistenceUnitManager
null
)public javax.persistence.spi.PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName)
PersistenceUnitManager
obtainPersistenceUnitInfo
in interface PersistenceUnitManager
persistenceUnitName
- the name of the desired persistence unit
null
)
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |