compatibility with OpenJPA 2.0 (support for persistence.xml versioning; SPR-6975)
This commit is contained in:
parent
a0e40a5610
commit
7da13e7ad1
|
|
@ -51,6 +51,8 @@ import org.springframework.util.xml.SimpleSaxErrorHandler;
|
||||||
*/
|
*/
|
||||||
class PersistenceUnitReader {
|
class PersistenceUnitReader {
|
||||||
|
|
||||||
|
private static final String PERSISTENCE_VERSION = "version";
|
||||||
|
|
||||||
private static final String PERSISTENCE_UNIT = "persistence-unit";
|
private static final String PERSISTENCE_UNIT = "persistence-unit";
|
||||||
|
|
||||||
private static final String UNIT_NAME = "name";
|
private static final String UNIT_NAME = "name";
|
||||||
|
|
@ -170,10 +172,11 @@ class PersistenceUnitReader {
|
||||||
Resource resource, Document document, List<SpringPersistenceUnitInfo> infos) throws IOException {
|
Resource resource, Document document, List<SpringPersistenceUnitInfo> infos) throws IOException {
|
||||||
|
|
||||||
Element persistence = document.getDocumentElement();
|
Element persistence = document.getDocumentElement();
|
||||||
|
String version = persistence.getAttribute(PERSISTENCE_VERSION);
|
||||||
URL unitRootURL = determinePersistenceUnitRootUrl(resource);
|
URL unitRootURL = determinePersistenceUnitRootUrl(resource);
|
||||||
List<Element> units = DomUtils.getChildElementsByTagName(persistence, PERSISTENCE_UNIT);
|
List<Element> units = DomUtils.getChildElementsByTagName(persistence, PERSISTENCE_UNIT);
|
||||||
for (Element unit : units) {
|
for (Element unit : units) {
|
||||||
SpringPersistenceUnitInfo info = parsePersistenceUnitInfo(unit);
|
SpringPersistenceUnitInfo info = parsePersistenceUnitInfo(unit, version);
|
||||||
info.setPersistenceUnitRootUrl(unitRootURL);
|
info.setPersistenceUnitRootUrl(unitRootURL);
|
||||||
infos.add(info);
|
infos.add(info);
|
||||||
}
|
}
|
||||||
|
|
@ -224,9 +227,12 @@ class PersistenceUnitReader {
|
||||||
/**
|
/**
|
||||||
* Parse the unit info DOM element.
|
* Parse the unit info DOM element.
|
||||||
*/
|
*/
|
||||||
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit) throws IOException {
|
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version) throws IOException { // JC: Changed
|
||||||
SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();
|
SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();
|
||||||
|
|
||||||
|
// set JPA version (1.0 or 2.0)
|
||||||
|
unitInfo.setPersistenceXMLSchemaVersion(version);
|
||||||
|
|
||||||
// set unit name
|
// set unit name
|
||||||
unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());
|
unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue