openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r726144 [1/2] - in /openjpa/trunk: openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/...
Date Fri, 12 Dec 2008 22:36:31 GMT
Author: jrbauer
Date: Fri Dec 12 14:36:30 2008
New Revision: 726144

URL: http://svn.apache.org/viewvc?rev=726144&view=rev
Log:
OPENJPA-823 Added new 2.0 schemas and updated persistence and metadata parsers to use per-version
schema validation

Added:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLVersionParser.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSchemaVersionValidation.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm_2_0.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-1_0-orm-2_0.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-no-pu.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-1_0.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-2_0.xml
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0.xml
  (with props)
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/orm_2_0-xsd.rsrc
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/persistence_2_0-xsd.rsrc
Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties

Added: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLVersionParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLVersionParser.java?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLVersionParser.java
(added)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLVersionParser.java
Fri Dec 12 14:36:30 2008
@@ -0,0 +1,85 @@
+/*
+ * 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.    
+ */
+package org.apache.openjpa.lib.meta;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * Custom non-validating SAX parser which can be used to get the version and
+ * schema location attributes from the root node.
+ *
+ * @author Jeremy Bauer
+ * @nojavadoc
+ */
+public class XMLVersionParser extends XMLMetaDataParser {
+
+    public static final String VERSION_1_0 = "1.0";
+    public static final String VERSION_2_0 = "2.0";
+
+    static private final String VERSION_ATTR = "version";
+    static private final String XSI_NS =
+        "http://www.w3.org/2001/XMLSchema-instance";
+    static private final String SCHEMA_LOCATION = "schemaLocation";
+
+    private String _rootElement;
+    private String _version;
+    private String _schemaLocation;
+    
+    public XMLVersionParser(String rootElement) {
+        _rootElement = rootElement;
+        setCaching(false);
+        setValidating(false);
+        setParseText(false);
+    }
+
+    @Override
+    protected void endElement(String name) throws SAXException {
+
+    }
+
+    @Override
+    protected boolean startElement(String name, Attributes attrs)
+            throws SAXException {
+        if (name.equals(_rootElement)) {
+            // save the version and schema location attributes
+            _version = attrs.getValue("", VERSION_ATTR);
+            _schemaLocation = attrs.getValue(XSI_NS, SCHEMA_LOCATION);
+            // ignore remaining content
+            ignoreContent(true);
+        }
+        return false;
+    }
+
+    /**
+     * Get the string value of the version attribute on the root element
+     * @return doc version
+     */
+    public String getVersion() {
+        return _version;
+    }
+    
+    /**
+     * Get the string value of the schema location attribute on the root element
+     * @return doc schema location
+     */
+    public String getSchemaLocation() {
+        return _schemaLocation;
+    }
+}

Propchange: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLVersionParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSchemaVersionValidation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSchemaVersionValidation.java?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSchemaVersionValidation.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSchemaVersionValidation.java
Fri Dec 12 14:36:30 2008
@@ -0,0 +1,100 @@
+/*
+ * 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.    
+ */
+package org.apache.openjpa.persistence.xml;
+
+import junit.framework.TestCase;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+public class TestSchemaVersionValidation extends TestCase {
+    
+    /**
+     * Verify a pu can be created with a version 2.0 persistence.xml
+     */
+    public void test2_0PersistenceXml() {        
+        OpenJPAEntityManagerFactory emf = OpenJPAPersistence.
+            createEntityManagerFactory("XSDTest", 
+                "org/apache/openjpa/persistence/xml/persistence-2_0.xml");
+        emf.close();
+    }
+
+    /**
+     * Verify schema validation will fail when using a 2.0 
+     * persistence.xml that does not contain a persistence unit
+     * (the 2.0 spec made it a requirement for the persistence file
+     * to contain at least one pu.)
+     */
+    public void testBad2_0PersistenceXml() {
+        try {
+            OpenJPAEntityManagerFactory emf = OpenJPAPersistence.
+                createEntityManagerFactory(null, 
+                "org/apache/openjpa/persistence/xml/persistence-2_0-no-pu.xml");
+            emf.close();
+            fail();
+        } catch (Exception e) {
+            assert(!e.getMessage().contains("SAXException"));
+        }        
+    }
+    
+    /**
+     * Verify a version 2.0 persistence.xml can reference and the provider
+     * can parse a version 1.0 orm.xml 
+     */
+    public void test2_0Persistence1_0OrmXml() {
+        OpenJPAEntityManagerFactory emf = OpenJPAPersistence.
+            createEntityManagerFactory("XSDTest", 
+            "org/apache/openjpa/persistence/xml/" +
+            "persistence-2_0-orm-1_0.xml");
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.close();
+        emf.close();
+    }
+    
+    /**
+     * Verify a version 2.0 persistence.xml can reference and the provider can
+     * parse a version 2.0 orm.xml
+     */
+    public void test2_0Persistence2_0OrmXml() {
+        OpenJPAEntityManagerFactory emf = OpenJPAPersistence.
+            createEntityManagerFactory("XSDTest", 
+            "org/apache/openjpa/persistence/xml/" +
+            "persistence-2_0-orm-2_0.xml");
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.close();
+        emf.close();
+    }
+    
+
+    
+    /**
+     * Verify a 1.0 persistence.xml can include a 2.0 orm.xml
+     */
+    public void test1_0Persistence2_0OrmXml() {
+        OpenJPAEntityManagerFactory emf = OpenJPAPersistence.
+            createEntityManagerFactory("XSDTest", 
+            "org/apache/openjpa/persistence/xml/" +
+            "persistence-2_0-orm-1_0.xml");
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.close();
+        emf.close();
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSchemaVersionValidation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm_2_0.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm_2_0.xml?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm_2_0.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm_2_0.xml
Fri Dec 12 14:36:30 2008
@@ -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="http://java.sun.com/xml/ns/persistence/orm"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
+    version="2.0">
+    <persistence-unit-metadata>
+        <persistence-unit-defaults/>
+            <description> This is an orm 2.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>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm_2_0.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-1_0-orm-2_0.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-1_0-orm-2_0.xml?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-1_0-orm-2_0.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-1_0-orm-2_0.xml
Fri Dec 12 14:36:30 2008
@@ -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="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+    version="1.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/orm_2_0.xml</mapping-file>
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-1_0-orm-2_0.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-no-pu.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-no-pu.xml?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-no-pu.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-no-pu.xml
Fri Dec 12 14:36:30 2008
@@ -0,0 +1,26 @@
+<?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="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.0" >
+    <!-- The 2.0 schema requires a persistence unit to be defined.  Schema validation
should fail. -->
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-no-pu.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-1_0.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-1_0.xml?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-1_0.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-1_0.xml
Fri Dec 12 14:36:30 2008
@@ -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="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.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/orm.xml</mapping-file>
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-1_0.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-2_0.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-2_0.xml?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-2_0.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-2_0.xml
Fri Dec 12 14:36:30 2008
@@ -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="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.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/orm_2_0.xml</mapping-file>
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0-orm-2_0.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0.xml?rev=726144&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0.xml
Fri Dec 12 14:36:30 2008
@@ -0,0 +1,29 @@
+<?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="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.0" >
+    <persistence-unit name="XSDTest" transaction-type="RESOURCE_LOCAL">
+        <description>PU for schema validation testing</description>
+        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/persistence-2_0.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=726144&r1=726143&r2=726144&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Fri Dec 12 14:36:30 2008
@@ -45,6 +45,7 @@
 import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.meta.XMLMetaDataParser;
+import org.apache.openjpa.lib.meta.XMLVersionParser;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.xml.sax.Attributes;
@@ -491,9 +492,17 @@
     public static class ConfigurationParser
         extends XMLMetaDataParser {
 
+        private static final String PERSISTENCE_XSD_1_0 = "persistence_1_0.xsd";
+        private static final String PERSISTENCE_XSD_2_0 = "persistence_2_0.xsd";
+
+        private static final Localizer _loc = Localizer.forPackage
+            (ConfigurationParser.class);
+
         private final Map _map;
         private PersistenceUnitInfoImpl _info = null;
         private URL _source = null;
+        private String _persistenceVersion;
+        private String _schemaLocation;
 
         public ConfigurationParser(Map map) {
             _map = map;
@@ -506,6 +515,17 @@
         public void parse(URL url)
             throws IOException {
             _source = url;
+
+            // peek at the doc to determine the version
+            XMLVersionParser vp = new XMLVersionParser("persistence");
+            try {
+                vp.parse(url);
+                _persistenceVersion = vp.getVersion();
+                _schemaLocation = vp.getSchemaLocation();
+            } catch (Throwable t) {
+                    log(_loc.get("version-check-error", 
+                        _source.toString()).toString());
+            }            
             super.parse(url);
         }
 
@@ -518,12 +538,36 @@
             } catch (PrivilegedActionException pae) {
                 throw (MalformedURLException) pae.getException();
             }
+            // peek at the doc to determine the version
+            XMLVersionParser vp = new XMLVersionParser("persistence");
+            try {
+                vp.parse(file);
+                _persistenceVersion = vp.getVersion();
+                _schemaLocation = vp.getSchemaLocation();                
+            } catch (Throwable t) {
+                    log(_loc.get("version-check-error", 
+                        _source.toString()).toString());
+            }            
             super.parse(file);
         }
 
         @Override
         protected Object getSchemaSource() {
-            return getClass().getResourceAsStream("persistence-xsd.rsrc");
+            // use the version 1 schema by default.  non-versioned docs will 
+            // continue to parse with the old xml if they do not contain a 
+            // persistence-unit.  that is currently the only signficant change
+            // to the schema.  if more significant changes are made in the 
+            // future, the 2.0 schema may be preferable.
+            String persistencexsd = "persistence-xsd.rsrc";
+            // if the version and/or schema location is for 1.0, use the 1.0 
+            // schema
+            if (_persistenceVersion != null &&
+                _persistenceVersion.equals(XMLVersionParser.VERSION_2_0) ||
+                (_schemaLocation != null && 
+                _schemaLocation.indexOf(PERSISTENCE_XSD_2_0) != -1)) {
+                persistencexsd = "persistence_2_0-xsd.rsrc";
+            }
+            return getClass().getResourceAsStream(persistencexsd);
         }
 
         @Override

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=726144&r1=726143&r2=726144&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Fri Dec 12 14:36:30 2008
@@ -18,9 +18,12 @@
  */
 package org.apache.openjpa.persistence;
 
+import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.util.ArrayList;
@@ -31,7 +34,6 @@
 import java.util.Set;
 import java.util.Stack;
 import javax.persistence.CascadeType;
-import javax.persistence.FetchType;
 import javax.persistence.GenerationType;
 import static javax.persistence.CascadeType.*;
 
@@ -50,6 +52,7 @@
 import org.apache.openjpa.lib.conf.Configurations;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.meta.CFMetaDataParser;
+import org.apache.openjpa.lib.meta.XMLVersionParser;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
@@ -68,8 +71,6 @@
 import static org.apache.openjpa.persistence.MetaDataTag.*;
 import static org.apache.openjpa.persistence.PersistenceStrategy.*;
 import org.apache.openjpa.util.ImplHelper;
-import org.apache.openjpa.util.MetaDataException;
-
 import serp.util.Numbers;
 
 /**
@@ -182,6 +183,12 @@
     private int[] _highs = null;
     private boolean _isXMLMappingMetaDataComplete = false;
 
+    private String _ormVersion;
+    private String _schemaLocation;
+    
+    private static final String ORM_XSD_1_0 = "orm_1_0.xsd";
+    private static final String ORM_XSD_2_0 = "orm_2_0.xsd";
+    
     /**
      * Constructor; supply configuration.
      */
@@ -311,6 +318,37 @@
             _parser.setMode(mode);
     }
 
+    public void parse(URL url) throws IOException {
+        // peek at the doc to determine the version
+        XMLVersionParser vp = new XMLVersionParser("entity-mappings");
+        try {
+            vp.parse(url);
+            _ormVersion = vp.getVersion();
+            _schemaLocation = vp.getSchemaLocation();
+        } catch (Throwable t) {
+                Log log = getLog();
+                if (log.isInfoEnabled())
+                    log.trace(_loc.get("version-check-error", 
+                        url.toString()));
+        }       
+        super.parse(url);
+    }
+
+    public void parse(File file) throws IOException {        
+        // peek at the doc to determine the version
+        XMLVersionParser vp = new XMLVersionParser("entity-mappings");
+        try {
+            vp.parse(file);
+            _ormVersion = vp.getVersion();
+            _schemaLocation = vp.getSchemaLocation();
+        } catch (Throwable t) {
+                Log log = getLog();
+                if (log.isInfoEnabled())
+                    log.trace(_loc.get("version-check-error", 
+                        file.toString()));
+        }       
+        super.parse(file);
+    }
     /**
      * Convenience method for interpreting {@link #getMode}.
      */
@@ -400,9 +438,19 @@
     }
 
     @Override
-    protected Object getSchemaSource() {
-        return XMLPersistenceMetaDataParser.class.getResourceAsStream
-            ("orm-xsd.rsrc");
+    protected Object getSchemaSource() {        
+        // use the latest schema by default.  'unknown' docs should parse
+        // with the latest schema.
+        String ormxsd = "orm_2_0-xsd.rsrc";
+        // if the version and/or schema location is for 1.0, use the 1.0 
+        // schema
+        if (_ormVersion != null &&
+            _ormVersion.equals(XMLVersionParser.VERSION_1_0) ||
+            (_schemaLocation != null && 
+            _schemaLocation.indexOf(ORM_XSD_1_0) != -1)) {
+            ormxsd = "orm-xsd.rsrc";
+        }        
+        return XMLPersistenceMetaDataParser.class.getResourceAsStream(ormxsd);
     }
 
     @Override

Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=726144&r1=726143&r2=726144&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
Fri Dec 12 14:36:30 2008
@@ -161,4 +161,6 @@
 	"{2}" of type "{3}", but this parameter is bound to a field of type "{4}".
 param-type-null: Parameter "{0}" declared in "{1}" is set to null, \
 	but this parameter is bound to a field of primitive type "{2}".
+version-check-error: An error occurred while attempting to determine the \
+    version of "{0}".
 	
\ No newline at end of file



Mime
View raw message