openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r516682 - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/ openjpa-persistence-jdbc/src/test/resources/META-INF/ openjpa-persistenc...
Date Sat, 10 Mar 2007 11:14:50 GMT
Author: pcl
Date: Sat Mar 10 03:14:44 2007
New Revision: 516682

URL: http://svn.apache.org/viewvc?view=rev&rev=516682
Log:
OPENJPA-142: read entity names specified in XML. Also added comment clarifying that ClassMetaData.setTypeAlias()
is only used at enhance time.

Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
  (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
  (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
  (with props)
Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?view=diff&rev=516682&r1=516681&r2=516682
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Sat Mar 10 03:14:44 2007
@@ -588,7 +588,8 @@
     /**
      * Sets the alias for the described type. The alias can be
      * any arbitrary string that the implementation can later use to
-     * refer to the class.
+     * refer to the class. Note that at runtime, only the alias
+     * computed when the persistent type was enhanced is used.
      *
      * @param alias the alias name to apply to the described type
      */

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java?view=auto&rev=516682
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
Sat Mar 10 03:14:44 2007
@@ -0,0 +1,16 @@
+package org.apache.openjpa.persistence.xml;
+
+public class SimpleXmlEntity {
+
+    private long id;
+    private int version;
+    private String stringField;
+
+    public String getStringField() {
+        return stringField;
+    }
+
+    public void setStringField(String stringField) {
+        this.stringField = stringField;
+    }
+}

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

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java?view=auto&rev=516682
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
Sat Mar 10 03:14:44 2007
@@ -0,0 +1,55 @@
+package org.apache.openjpa.persistence.xml;
+
+import java.util.Map;
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SingleEMTest;
+import org.apache.openjpa.persistence.ArgumentException;
+
+public class TestSimpleXmlEntity
+    extends SingleEMTest {
+
+    public TestSimpleXmlEntity() {
+        super(SimpleXmlEntity.class);
+    }
+
+    protected void setEMFProps(Map props) {
+        super.setEMFProps(props);
+    }
+
+    public void testNamedQueryInXmlNamedEntity() {
+        EntityManager em = emf.createEntityManager();
+        em.createNamedQuery("SimpleXml.findAll").getResultList();
+        em.close();
+    }
+
+    public void testNamedQueryInXmlUsingShortClassName() {
+        EntityManager em = emf.createEntityManager();
+        try {
+            em.createNamedQuery("SimpleXmlEntity.findAll").getResultList();
+            fail("should not be able to execute query using short class name " +
+                "for entity that has an entity name specified");
+        } catch (ArgumentException ae) {
+            // expected
+        }
+        em.close();
+    }
+
+    public void testNamedEntityInDynamicQuery() {
+        EntityManager em = emf.createEntityManager();
+        em.createQuery("select o from SimpleXml o").getResultList();
+        em.close();
+    }
+
+    public void testShortClassNameInDynamicQuery() {
+        EntityManager em = emf.createEntityManager();
+        try {
+            em.createQuery("select o from SimpleXmlEntity o").getResultList();
+            fail("should not be able to execute query using short class name " +
+                "for entity that has an entity name specified");
+        } catch (ArgumentException ae) {
+            // expected
+        }
+        em.close();
+    }
+}

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

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?view=diff&rev=516682&r1=516681&r2=516682
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
Sat Mar 10 03:14:44 2007
@@ -24,6 +24,13 @@
             org.apache.openjpa.persistence.PersistenceProviderImpl
         </provider>
         -->
+        <!--
+            This needs to be listed because the OpenJPA test framework
+            does not provide any other means to incrementally enhance classes
+            for particular test cases, and the XML data must be available at
+            enhance time for XML data to get incorporated into PCRegistry
+        -->
+        <mapping-file>org/apache/openjpa/persistence/xml/orm.xml</mapping-file>
         <properties>
             <!--
             These properties are instead passed via System properties

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml?view=auto&rev=516682
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
Sat Mar 10 03:14:44 2007
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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_1_0.xsd"
+    version="1.0">
+    <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"/>
+            <basic name="stringField"/>
+            <version name="version"/>
+        </attributes>
+    </entity>
+</entity-mappings>
\ No newline at end of file

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

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?view=diff&rev=516682&r1=516681&r2=516682
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Sat Mar 10 03:14:44 2007
@@ -61,6 +61,7 @@
 import static org.apache.openjpa.persistence.PersistenceStrategy.*;
 import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.UnsupportedException;
+import serp.util.Strings;
 
 /**
  * Custom SAX parser used by the system to quickly parse persistence i
@@ -721,7 +722,8 @@
         // query mode only?
         _cls = classForName(currentClassName());
         if (_mode == MODE_QUERY) {
-            if (_parser != null && !"true".equals(attrs.getValue("metadata-complete")))
+            if (_parser != null &&
+                !"true".equals(attrs.getValue("metadata-complete")))
                 _parser.parse(_cls);
             return true;
         }
@@ -759,7 +761,8 @@
             meta.setSourceMode(MODE_NONE);
 
             // parse annotations first so XML overrides them
-            if (_parser != null && !"true".equals(attrs.getValue("metadata-complete")))
+            if (_parser != null &&
+                !"true".equals(attrs.getValue("metadata-complete")))
                 _parser.parse(_cls);
         }
 
@@ -768,6 +771,9 @@
             meta.setSource(getSourceFile(), meta.SRC_XML);
             meta.setSourceMode(MODE_META, true);
             meta.setListingIndex(_clsPos);
+            String name = attrs.getValue("name");
+            if (!StringUtils.isEmpty(name))
+                meta.setTypeAlias(name);
             meta.setEmbeddedOnly(mappedSuper || "embeddable".equals(elem));
             if (mappedSuper)
                 meta.setIdentityType(meta.ID_UNKNOWN);



Mime
View raw message