openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r524921 - in /incubator/openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/ openjpa-persistence/src/main/java/org/apache/o...
Date Mon, 02 Apr 2007 21:14:48 GMT
Author: mikedd
Date: Mon Apr  2 14:14:48 2007
New Revision: 524921

URL: http://svn.apache.org/viewvc?view=rev&rev=524921
Log:
OpenJPA-185 allow optional to be overriden by xml descriptor.

Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java
  (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideEntity.java
  (with props)
Modified:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java?view=auto&rev=524921
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java
Mon Apr  2 14:14:48 2007
@@ -0,0 +1,49 @@
+package org.apache.openjpa.persistence.xml;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.InvalidStateException;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestXmlOverrideEntity extends SingleEMFTestCase {
+
+    public void setUp() {
+        setUp(XmlOverrideEntity.class);
+    }
+
+    /**
+     * Tests that the optional attribute on a basic field can be overrided by
+     * an xml descriptor. 
+     * 
+     * XmlOverrideEntity.name is annotated with optional=false
+     * XmlOverrideEntity.description is annotated with optional=true. 
+     * 
+     * The optional attributes are reversed in orm.xml. 
+     */
+    public void testOptionalAttributeOverride() {
+        EntityManager em = emf.createEntityManager();
+
+        XmlOverrideEntity optional = new XmlOverrideEntity();
+
+        optional.setName(null);
+        optional.setDescription("description");
+
+        em.getTransaction().begin();
+        em.persist(optional);
+        em.getTransaction().commit();
+
+        try {
+            em.getTransaction().begin();
+            optional.setDescription(null);
+            em.getTransaction().commit();
+            fail("XmlOrverrideEntity.description should not be optional. "
+                    + "Expecting an InvalidStateException.");
+        } catch (InvalidStateException e) {
+        }
+
+        em.getTransaction().begin();
+        em.remove(em.find(XmlOverrideEntity.class, optional.getId()));
+        em.getTransaction().commit();
+    }
+}
+

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

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideEntity.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideEntity.java?view=auto&rev=524921
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideEntity.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideEntity.java
Mon Apr  2 14:14:48 2007
@@ -0,0 +1,45 @@
+package org.apache.openjpa.persistence.xml;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class XmlOverrideEntity {
+
+    @Id
+    @GeneratedValue
+    int id;
+    
+    @Basic(optional=false)
+    String name;
+    
+    @Basic(optional=true)
+    String description;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    } 
+}
+

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

Modified: 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=diff&rev=524921&r1=524920&r2=524921
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
Mon Apr  2 14:14:48 2007
@@ -20,4 +20,11 @@
             <version name="version"/>
         </attributes>
     </entity>
-</entity-mappings>
\ No newline at end of file
+    <entity name="XmlOverride" class="XmlOverrideEntity">
+    	<attributes>
+	    <basic name="name" optional="true"></basic>
+	    <basic name="description" optional="false"></basic>
+    	</attributes>
+    </entity>
+</entity-mappings>
+

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=524921&r1=524920&r2=524921
==============================================================================
--- 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
Mon Apr  2 14:14:48 2007
@@ -1196,6 +1196,12 @@
         val = attrs.getValue("optional");
         if ("false".equals(val))
             fmd.setNullValue(FieldMetaData.NULL_EXCEPTION);
+        else if ("true".equals(val)
+                && fmd.getNullValue() == FieldMetaData.NULL_EXCEPTION) {
+            // Reset value if the field was annotated with optional=false. 
+            // Otherwise leave it alone.
+            fmd.setNullValue(FieldMetaData.NULL_UNSET);
+        }
         if (isMappingOverrideMode()) {
             val = attrs.getValue("mapped-by");
             if (val != null)



Mime
View raw message