openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1233434 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/rel...
Date Thu, 19 Jan 2012 15:33:02 GMT
Author: curtisr7
Date: Thu Jan 19 15:33:01 2012
New Revision: 1233434

URL: http://svn.apache.org/viewvc?rev=1233434&view=rev
Log:
OPENJPA-2068: Fixing a bug where we were incorrectly removing LRS proxy fields while loading
the proxy.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityA.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityB.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java?rev=1233434&r1=1233433&r2=1233434&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
Thu Jan 19 15:33:01 2012
@@ -40,6 +40,7 @@ import org.apache.openjpa.util.ChangeTra
 import org.apache.openjpa.util.Exceptions;
 import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.InvalidStateException;
+import org.apache.openjpa.util.LRSProxy;
 import org.apache.openjpa.util.MapChangeTracker;
 import org.apache.openjpa.util.ObjectId;
 import org.apache.openjpa.util.Proxies;
@@ -154,7 +155,9 @@ class SingleFieldManager extends Transfe
     }
 
     /**
-     * If the current field is a usable proxy, return it; else return null.
+     * If the current field is a usable proxy and it should be a proxy, return it; else return
null.
+     * 
+     * This method will skim out Calendar instances that were proxied before we knew if they
need to be proxied.
      */
     private Proxy checkProxy(FieldMetaData fmd) {
         if (!(objval instanceof Proxy))
@@ -162,7 +165,8 @@ class SingleFieldManager extends Transfe
 
         Proxy proxy = (Proxy) objval;
         if (proxy.getOwner() == null || Proxies.isOwner(proxy, _sm, field)) {
-            if(fmd.getProxyType().isAssignableFrom(proxy.getClass())){
+            if (fmd.getProxyType().isAssignableFrom(proxy.getClass()) 
+                    || (fmd.isLRS() && (objval instanceof LRSProxy))) {
                 return proxy;
             }
         }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java?rev=1233434&r1=1233433&r2=1233434&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java
Thu Jan 19 15:33:01 2012
@@ -19,11 +19,15 @@
 package org.apache.openjpa.persistence.relations;
 
 import java.util.Iterator;
+
 import javax.persistence.EntityManager;
 
 import junit.textui.TestRunner;
+
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.relations.entity.LrsEntityA;
+import org.apache.openjpa.persistence.relations.entity.LrsEntityB;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
@@ -37,7 +41,7 @@ public class TestLRS
     private long id;
 
     public void setUp() {
-        setUp(LRSEntity.class, BasicEntity.class, CLEAR_TABLES,
+        setUp(LrsEntityA.class, LrsEntityB.class, LRSEntity.class, BasicEntity.class, CLEAR_TABLES,
             "openjpa.Compatibility", "default(copyOnDetach=true," +
             		"cascadeWithDetach=true)");
         
@@ -88,6 +92,20 @@ public class TestLRS
         assertMerge(lrs);
     }
 
+    public void testRelationships(){
+        OpenJPAEntityManager em = emf.createEntityManager();
+        LrsEntityA a = new LrsEntityA("name");
+        LrsEntityB b = new LrsEntityB("name-b", a);
+
+        em.getTransaction().begin();
+        em.persist(a);
+        em.persist(b);
+        em.getTransaction().commit();
+        em.clear();
+        
+        LrsEntityA a1 = em.find(LrsEntityA.class, a.getId());
+        assertEquals(1, a1.getEntitybs().size());
+    }
     private void assertLRS(LRSEntity lrs, String name) {
         assertNotNull(lrs);
         assertEquals(name, lrs.getName());
@@ -113,6 +131,7 @@ public class TestLRS
         em.close();
     }
 
+    
     public static void main(String[] args) {
         TestRunner.run(TestLRS.class);
     }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityA.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityA.java?rev=1233434&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityA.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityA.java
Thu Jan 19 15:33:01 2012
@@ -0,0 +1,105 @@
+/*
+ * 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.relations.entity;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.annotation.Generated;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.LRS;
+import org.apache.openjpa.persistence.jdbc.Index;
+
+@Entity
+@Table(name = "LrsEntityB")
+public class LrsEntityA implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @Index(name = "lrsa_index", unique = true)
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    Integer id;
+
+    @Column(length = 30)
+    String name;
+    @Basic(fetch = FetchType.LAZY)
+    int age;
+
+    @OneToMany(mappedBy = "entitya", cascade = CascadeType.ALL)
+    // if fk creates table need cascadeRemove on inverse
+    @LRS
+    public Collection<LrsEntityB> entitybs;
+
+    public LrsEntityA() {
+        this.name = "none";
+        this.entitybs = new ArrayList<LrsEntityB>();
+    }
+
+    public LrsEntityA(String nam) {
+        this.name = nam;
+        entitybs = new ArrayList<LrsEntityB>();
+    }
+
+    public LrsEntityA(int id, String nam, int age) {
+        this.id = id;
+        this.name = nam;
+        this.age = age;
+        entitybs = new ArrayList<LrsEntityB>();
+    }
+
+    public Collection<LrsEntityB> getEntitybs() {
+        return entitybs;
+    }
+
+    public void setEntitybs(Collection<LrsEntityB> entitybs) {
+        this.entitybs = entitybs;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityB.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityB.java?rev=1233434&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityB.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/entity/LrsEntityB.java
Thu Jan 19 15:33:01 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.relations.entity;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.jdbc.ForeignKey;
+import org.apache.openjpa.persistence.jdbc.ForeignKeyAction;
+import org.apache.openjpa.persistence.jdbc.Index;
+
+@Entity
+@Table(name = "LrsEntityB")
+public class LrsEntityB implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @Index(name = "lrsb_index", unique = true)
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    Integer id;
+
+    @Column(length = 30)
+    String name;
+
+    @ManyToOne()
+    @ForeignKey(deleteAction = ForeignKeyAction.NULL)
+    // needed for native dropandcreatetest
+    LrsEntityA entitya;
+
+    public LrsEntityB() {
+        this.name = "none";
+        this.entitya = null;
+    }
+
+    public LrsEntityB(String nam) {
+        this.name = nam;
+        this.entitya = null;
+    }
+
+    public LrsEntityB(String nam, LrsEntityA entitya) {
+        this.name = nam;
+        this.entitya = entitya;
+        if (entitya != null)
+            entitya.getEntitybs().add(this);
+    }
+
+    public LrsEntityA getEntitya() {
+        return entitya;
+    }
+
+    public void setEntitya(LrsEntityA entitya) {
+        this.entitya = entitya;
+        if (entitya != null)
+            entitya.getEntitybs().add(this);
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}



Mime
View raw message