openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1097517 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/ openjpa-persistence-jdbc/src/test/resources/META-INF/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/ o...
Date Thu, 28 Apr 2011 16:00:58 GMT
Author: curtisr7
Date: Thu Apr 28 16:00:58 2011
New Revision: 1097517

URL: http://svn.apache.org/viewvc?rev=1097517&view=rev
Log:
OPENJPA-1989: Fix *ToOne xml fetch attribute to honor LAZY.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestToOneLazyXmlOverride.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideToOneEntity.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/toone-orm.xml
  (with props)
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestToOneLazyXmlOverride.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestToOneLazyXmlOverride.java?rev=1097517&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestToOneLazyXmlOverride.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestToOneLazyXmlOverride.java
Thu Apr 28 16:00:58 2011
@@ -0,0 +1,63 @@
+/*
+ * 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 javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestToOneLazyXmlOverride extends SQLListenerTestCase {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp(CLEAR_TABLES, XmlOverrideToOneEntity.class);
+    }
+
+    @Override
+    protected String getPersistenceUnitName() {
+        return "to-one-xml-override";
+    }
+
+    public void testToManyLazyOverride() {
+        EntityManager em = emf.createEntityManager();
+        try{
+        em.getTransaction().begin();
+        XmlOverrideToOneEntity x = new XmlOverrideToOneEntity();
+        x.setOtherM2O(x);
+        x.setOtherO2O(x);
+        em.persist(x);
+        em.getTransaction().commit();
+
+        em.clear();
+        resetSQL();
+
+        em.find(XmlOverrideToOneEntity.class, x.getId());
+        for (String lastSql : sql) {
+            // Make sure we don't have any joins!
+            assertFalse("Shouldn't have found any instances of join or JOIN in last sql,
but did. Last SQL = "
+                + lastSql, lastSql.contains("join") || lastSql.contains("JOIN"));
+        }
+        }finally{
+            if(em.getTransaction().isActive()){
+                em.getTransaction().rollback();
+            }
+            em.close();
+            }
+        }
+    }
+}

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

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideToOneEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideToOneEntity.java?rev=1097517&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideToOneEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/XmlOverrideToOneEntity.java
Thu Apr 28 16:00:58 2011
@@ -0,0 +1,61 @@
+
+/*
+ * 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 javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
+
+@Entity
+public class XmlOverrideToOneEntity {
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    int id;
+
+    @OneToOne 
+    XmlOverrideToOneEntity otherO2O;
+
+    @ManyToOne
+    XmlOverrideToOneEntity otherM2O;
+
+    public long getId() {
+        return id;
+    }
+
+    public XmlOverrideToOneEntity getOtherO2O() {
+        return otherO2O;
+    }
+
+    public void setOtherO2O(XmlOverrideToOneEntity otherO2O) {
+        this.otherO2O = otherO2O;
+    }
+
+    public XmlOverrideToOneEntity getOtherM2O() {
+        return otherM2O;
+    }
+
+    public void setOtherM2O(XmlOverrideToOneEntity otherM2O) {
+        this.otherM2O = otherM2O;
+    }
+
+}

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

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=1097517&r1=1097516&r2=1097517&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Thu
Apr 28 16:00:58 2011
@@ -385,4 +385,11 @@
             <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
         </properties>
     </persistence-unit>
+	<persistence-unit name="to-one-xml-override">
+		<mapping-file>org/apache/openjpa/persistence/xml/toone-orm.xml
+		</mapping-file>
+		<properties>
+			<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"
/>
+		</properties>
+	</persistence-unit>
 </persistence>

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/toone-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/toone-orm.xml?rev=1097517&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/toone-orm.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/toone-orm.xml
Thu Apr 28 16:00:58 2011
@@ -0,0 +1,33 @@
+<?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">
+	<package> org.apache.openjpa.persistence.xml </package>
+	<entity name="XmlOverrideToOneEntity" class="XmlOverrideToOneEntity">
+		<attributes>
+			<many-to-one name="otherM2O" fetch="LAZY">
+			</many-to-one>
+			<one-to-one name="otherO2O" fetch="LAZY">
+			</one-to-one>
+		</attributes>
+	</entity>
+</entity-mappings>

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

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=1097517&r1=1097516&r2=1097517&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
Thu Apr 28 16:00:58 2011
@@ -1463,8 +1463,10 @@ public class XMLPersistenceMetaDataParse
     protected void parseOneToOne(FieldMetaData fmd, Attributes attrs)
         throws SAXException {
         String val = attrs.getValue("fetch");
-        if (val == null || "EAGER".equals(val)) {
+        if (val == null) {
             fmd.setInDefaultFetchGroup(true);
+        } else {
+            fmd.setInDefaultFetchGroup("EAGER".equals(val));
         }
         val = attrs.getValue("target-entity");
         if (val != null)
@@ -1485,8 +1487,10 @@ public class XMLPersistenceMetaDataParse
     protected void parseManyToOne(FieldMetaData fmd, Attributes attrs)
         throws SAXException {
         String val = attrs.getValue("fetch");
-        if (val == null || "EAGER".equals(val)) {
+        if (val == null) {
             fmd.setInDefaultFetchGroup(true);
+        } else {
+            fmd.setInDefaultFetchGroup("EAGER".equals(val));
         }
         val = attrs.getValue("target-entity");
         if (val != null)



Mime
View raw message