Top Description Fields Constructors Methods
org.springframework.orm.jpa.persistenceunit

pack-priv final Class PersistenceUnitReader

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URL, java.util.ArrayList, .List, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, .ParserConfigurationException, jakarta.persistence.SharedCacheMode, .ValidationMode, jakarta.persistence.spi.PersistenceUnitTransactionType, org.apache.commons.logging.Log, .LogFactory, org.w3c.dom.Document, .Element, org.xml.sax.ErrorHandler, .SAXException, org.springframework.core.io.Resource, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.jdbc.datasource.lookup.DataSourceLookup, org.springframework.lang.Nullable, org.springframework.util.Assert, .ResourceUtils, .StringUtils, org.springframework.util.xml.DomUtils, .SimpleSaxErrorHandler

Internal helper class for reading JPA-compliant persistence.xml files.
Authors
Costin Leau, Juergen Hoeller
Since
2.0

Field Summary

Modifier and TypeField and Description
private final DataSourceLookup
private static final String
private static final String
private static final String
private static final Log
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private final ResourcePatternResolver
private static final String
private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
PersistenceUnitReader(ResourcePatternResolver
the ResourcePatternResolver to use for loading resources
resourcePatternResolver
,
DataSourceLookup
the DataSourceLookup to resolve DataSource names in persistence.xml files against
dataSourceLookup
)

Create a new PersistenceUnitReader.

Method Summary

Modifier and TypeMethod and Description
protected Document
buildDocument(ErrorHandler handler, InputStream stream)

Validate the given stream and return a valid DOM document for parsing.

pack-priv static URL

Returns:

the corresponding persistence unit root URL
determinePersistenceUnitRootUrl
(Resource
the resource to check
resource
)

Determine the persistence unit root URL based on the given resource (which points to the persistence.xml file we're reading).

protected List<SpringPersistenceUnitInfo>
parseDocument(Resource resource, Document document, List<SpringPersistenceUnitInfo> infos)

Parse the validated document and add entries to the given unit info list.

protected void
parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)

Parse the jar-file XML elements.

protected void
parseManagedClasses(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)

Parse the class XML elements.

protected void
parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)

Parse the mapping-file XML elements.

protected SpringPersistenceUnitInfo
parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl)

Parse the unit info DOM element.

protected void
parseProperties(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)

Parse the property XML elements.

public SpringPersistenceUnitInfo[]

Returns:

the resulting PersistenceUnitInfo instances
readPersistenceUnitInfos
(String
the resource location (can be a pattern)
persistenceXmlLocation
)

Parse and build all persistence unit infos defined in the specified XML file(s).

public SpringPersistenceUnitInfo[]

Returns:

the resulting PersistenceUnitInfo instances
readPersistenceUnitInfos
(String[]
the resource locations (can be patterns)
persistenceXmlLocations
)

Parse and build all persistence unit infos defined in the given XML files.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataSourceLookupback to summary
private final DataSourceLookup dataSourceLookup
EXCLUDE_UNLISTED_CLASSESback to summary
private static final String EXCLUDE_UNLISTED_CLASSES
JAR_FILE_URLback to summary
private static final String JAR_FILE_URL
JTA_DATA_SOURCEback to summary
private static final String JTA_DATA_SOURCE
loggerback to summary
private static final Log logger
MANAGED_CLASS_NAMEback to summary
private static final String MANAGED_CLASS_NAME
MAPPING_FILE_NAMEback to summary
private static final String MAPPING_FILE_NAME
META_INFback to summary
private static final String META_INF
NON_JTA_DATA_SOURCEback to summary
private static final String NON_JTA_DATA_SOURCE
PERSISTENCE_UNITback to summary
private static final String PERSISTENCE_UNIT
PERSISTENCE_VERSIONback to summary
private static final String PERSISTENCE_VERSION
PROPERTIESback to summary
private static final String PROPERTIES
PROVIDERback to summary
private static final String PROVIDER
resourcePatternResolverback to summary
private final ResourcePatternResolver resourcePatternResolver
SHARED_CACHE_MODEback to summary
private static final String SHARED_CACHE_MODE
TRANSACTION_TYPEback to summary
private static final String TRANSACTION_TYPE
UNIT_NAMEback to summary
private static final String UNIT_NAME
VALIDATION_MODEback to summary
private static final String VALIDATION_MODE

Constructor Detail

PersistenceUnitReaderback to summary
public PersistenceUnitReader(ResourcePatternResolver resourcePatternResolver, DataSourceLookup dataSourceLookup)

Create a new PersistenceUnitReader.

Parameters
resourcePatternResolver:ResourcePatternResolver

the ResourcePatternResolver to use for loading resources

dataSourceLookup:DataSourceLookup

the DataSourceLookup to resolve DataSource names in persistence.xml files against

Method Detail

buildDocumentback to summary
protected Document buildDocument(ErrorHandler handler, InputStream stream) throws ParserConfigurationException, SAXException, IOException

Validate the given stream and return a valid DOM document for parsing.

determinePersistenceUnitRootUrlback to summary
pack-priv static URL determinePersistenceUnitRootUrl(Resource resource) throws IOException

Determine the persistence unit root URL based on the given resource (which points to the persistence.xml file we're reading).

Parameters
resource:Resource

the resource to check

Returns:URL

the corresponding persistence unit root URL

Annotations
@Nullable
Exceptions
IOException:
if the checking failed
parseDocumentback to summary
protected List<SpringPersistenceUnitInfo> parseDocument(Resource resource, Document document, List<SpringPersistenceUnitInfo> infos) throws IOException

Parse the validated document and add entries to the given unit info list.

parseJarFilesback to summary
protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) throws IOException

Parse the jar-file XML elements.

parseManagedClassesback to summary
protected void parseManagedClasses(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)

Parse the class XML elements.

parseMappingFilesback to summary
protected void parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)

Parse the mapping-file XML elements.

parsePersistenceUnitInfoback to summary
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl) throws IOException

Parse the unit info DOM element.

parsePropertiesback to summary
protected void parseProperties(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)

Parse the property XML elements.

readPersistenceUnitInfosback to summary
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String persistenceXmlLocation)

Parse and build all persistence unit infos defined in the specified XML file(s).

Parameters
persistenceXmlLocation:String

the resource location (can be a pattern)

Returns:SpringPersistenceUnitInfo[]

the resulting PersistenceUnitInfo instances

readPersistenceUnitInfosback to summary
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations)

Parse and build all persistence unit infos defined in the given XML files.

Parameters
persistenceXmlLocations:String[]

the resource locations (can be patterns)

Returns:SpringPersistenceUnitInfo[]

the resulting PersistenceUnitInfo instances