Skip to content

Commit

Permalink
[OPENJPA-2928] Add xsd schemas for offline processing (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
guewin authored Sep 30, 2024
1 parent 4279df5 commit c16c834
Show file tree
Hide file tree
Showing 14 changed files with 2,781 additions and 3 deletions.
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ openjpa-persistence -
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd)
orm_2_2-xsd.rsrc - Eclipse Public License v1.0 - included in the openjpa jar, taken from:
http://xmlns.jcp.org/xml/ns/persistence/orm_2_2.xsd)
orm_3_0-xsd.rsrc - Eclipse Public License v2.0 - included in the openjpa jar, taken from:
https://jakarta.ee/xml/ns/persistence/orm/orm_3_0.xsd
persistence-xsd.rsrc - CDDL 1.0 - included in the openjpa jar, taken from:
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd)
persistence_2_0-xsd.rsrc - CDDL 1.0 - included in the openjpa jar, taken from:
Expand All @@ -259,6 +261,8 @@ openjpa-persistence -
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd).
persistence_2_2-xsd.rsrc - Eclipse Public License v1.0 - included in the openjpa jar, taken from:
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd).
persistence_3_0-xsd.rsrc - Eclipse Public License v2.0 - included in the openjpa jar, taken from:
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd
===========================

COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
Expand Down
4 changes: 4 additions & 0 deletions openjpa-all/src/main/appended-resources/META-INF/LICENSE.vm
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ openjpa-persistence -
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd)
orm_2_2-xsd.rsrc - Eclipse Public License v1.0 - included in the openjpa jar, taken from:
http://xmlns.jcp.org/xml/ns/persistence/orm_2_2.xsd)
orm_3_0-xsd.rsrc - Eclipse Public License v2.0 - included in the openjpa jar, taken from:
https://jakarta.ee/xml/ns/persistence/orm/orm_3_0.xsd
persistence-xsd.rsrc - CDDL 1.0 - included in the openjpa jar, taken from:
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd)
persistence_2_0-xsd.rsrc - CDDL 1.0 - included in the openjpa jar, taken from:
Expand All @@ -250,6 +252,8 @@ openjpa-persistence -
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd).
persistence_2_2-xsd.rsrc - Eclipse Public License v1.0 - included in the openjpa jar, taken from:
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd).
persistence_3_0-xsd.rsrc - Eclipse Public License v2.0 - included in the openjpa jar, taken from:
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd
===========================

COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class XMLVersionParser extends XMLMetaDataParser {
public static final String VERSION_2_0 = "2.0";
public static final String VERSION_2_1 = "2.1";
public static final String VERSION_2_2 = "2.2";
public static final String VERSION_3_0 = "3.0";

static private final String VERSION_ATTR = "version";
static private final String XSI_NS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public void testOffline2_1Persistence2_2OrmXml() {
doCreateEmf("XSDTest", "offline_persistence-2_1-orm-2_2.xml");
}

@Test
public void testOffline3_0Persistence3_0OrmXml() {
doCreateEmf("XSDTest", "offline_persistence-3_0-orm-3_0.xml");
}

private void doCreateEmf(String name, String xml) {
doCreateEmf(name, xml, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<entity-mappings xmlns="https://jakarta.ee/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence/orm http://localhost:11666/orm_3_0.xsd"
version="3.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<description> This is an orm 3.0 element</description>
</persistence-unit-defaults>
</persistence-unit-metadata>
<package>
org.apache.openjpa.persistence.xml
</package>
<entity name="SimpleXml" class="SimpleXmlEntity">
<named-query name="SimpleXml.findAll">
<query>select o from SimpleXml o</query>
</named-query>
<named-query name="SimpleXmlEntity.findAll">
<query>select o from SimpleXmlEntity o</query>
</named-query>
<attributes>
<id name="id">
<generated-value generator="uuid-hex"/>
</id>
<basic name="stringField"/>
<version name="version"/>
</attributes>
</entity>
</entity-mappings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<persistence
xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence http://localhost:11666/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="XSDTest" transaction-type="RESOURCE_LOCAL">
<description>PU for schema validation testing</description>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<mapping-file>org/apache/openjpa/persistence/xml/offline_orm_3_0.xml</mapping-file>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ openjpa-persistence -
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd)
orm_2_2-xsd.rsrc - Eclipse Public License v1.0 - included in the openjpa jar, taken from:
http://xmlns.jcp.org/xml/ns/persistence/orm_2_2.xsd)
orm_3_0-xsd.rsrc - Eclipse Public License v2.0 - included in the openjpa jar, taken from:
https://jakarta.ee/xml/ns/persistence/orm/orm_3_0.xsd
persistence-xsd.rsrc - CDDL 1.0 - included in the openjpa jar, taken from:
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd)
persistence_2_0-xsd.rsrc - CDDL 1.0 - included in the openjpa jar, taken from:
Expand All @@ -48,6 +50,8 @@ openjpa-persistence -
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd).
persistence_2_2-xsd.rsrc - Eclipse Public License v1.0 - included in the openjpa jar, taken from:
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd).
persistence_3_0-xsd.rsrc - Eclipse Public License v2.0 - included in the openjpa jar, taken from:
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd
===========================

COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ public static class ConfigurationParser
private static final String PERSISTENCE_XSD_2_0 = "persistence_2_0.xsd";
private static final String PERSISTENCE_XSD_2_1 = "persistence_2_1.xsd";
private static final String PERSISTENCE_XSD_2_2 = "persistence_2_2.xsd";
private static final String PERSISTENCE_XSD_3_0 = "persistence_3_0.xsd";

private static final Localizer _loc = Localizer.forPackage
(ConfigurationParser.class);
Expand Down Expand Up @@ -857,6 +858,10 @@ else if (XMLVersionParser.VERSION_2_2.equals(_persistenceVersion)
|| (_schemaLocation != null && _schemaLocation.indexOf(PERSISTENCE_XSD_2_2) != -1)) {
persistencexsd = "persistence_2_2-xsd.rsrc";
}
else if (XMLVersionParser.VERSION_3_0.equals(_persistenceVersion)
|| (_schemaLocation != null && _schemaLocation.indexOf(PERSISTENCE_XSD_3_0) != -1)) {
persistencexsd = "persistence_3_0-xsd.rsrc";
}

return getClass().getResourceAsStream(persistencexsd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ protected static enum localDBIdentifiers {
private static final String ORM_XSD_2_0 = "orm_2_0.xsd";
private static final String ORM_XSD_2_1 = "orm_2_1.xsd";
private static final String ORM_XSD_2_2 = "orm_2_2.xsd";
private static final String ORM_XSD_3_0 = "orm_3_0.xsd";

/**
* Constructor; supply configuration.
Expand Down Expand Up @@ -590,6 +591,9 @@ protected Object getSchemaSource() {
} else if (XMLVersionParser.VERSION_2_2.equals(_ormVersion)
|| (_schemaLocation != null && _schemaLocation.indexOf(ORM_XSD_2_2) > -1)) {
ormxsd = "orm_2_2.xsd.rsrc";
} else if (XMLVersionParser.VERSION_3_0.equals(_ormVersion)
|| (_schemaLocation != null && _schemaLocation.indexOf(ORM_XSD_3_0) > -1)) {
ormxsd = "orm_3_0-xsd.rsrc";
}

List<InputStream> schema = new ArrayList<>();
Expand Down
Loading

0 comments on commit c16c834

Please sign in to comment.