openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1324759 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/
Date Wed, 11 Apr 2012 13:40:54 GMT
Author: curtisr7
Date: Wed Apr 11 13:40:53 2012
New Revision: 1324759

URL: http://svn.apache.org/viewvc?rev=1324759&view=rev
Log:
OPENJPA-2110: Create correct proxy type when type is defined in an abstract class.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/AbstractEntity.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/ConcreteEntity.java
  (with props)
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java?rev=1324759&r1=1324758&r2=1324759&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java
Wed Apr 11 13:40:53 2012
@@ -19,6 +19,7 @@
 package org.apache.openjpa.meta;
 
 import java.io.ObjectOutput;
+import java.lang.reflect.Modifier;
 import java.util.Calendar;
 import java.util.SortedMap;
 import java.util.SortedSet;
@@ -46,9 +47,9 @@ class ProxySetupStateManager
     public void setProxyData(PersistenceCapable pc, ClassMetaData meta) {
         FieldMetaData[] fmds = meta.getFields();
         for (int i = 0; i < fmds.length; i++) {
-            if (fmds[i].getDefiningMetaData() != meta)
-                continue;
-
+            // This method only gets called for concrete types. We need to do this processing
for fields that might 
+            // not be owned by pc. 
+            
             switch (fmds[i].getDeclaredTypeCode()) {
                 case JavaTypes.CALENDAR:
                     pc.pcProvideField(fmds[i].getIndex());

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/AbstractEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/AbstractEntity.java?rev=1324759&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/AbstractEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/AbstractEntity.java
Wed Apr 11 13:40:53 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.proxy;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.OneToMany;
+import javax.persistence.Version;
+
+@MappedSuperclass
+public abstract class AbstractEntity {
+    @Id
+    @GeneratedValue
+    private int id;
+
+    @Version
+    int version;
+
+    @OneToMany(cascade = CascadeType.ALL)
+    private Set<ConcreteEntity> items = new LinkedHashSet<ConcreteEntity>();
+
+    public int getId() {
+        return id;
+    }
+
+    public Set<ConcreteEntity> getItems() {
+        return items;
+    }
+
+    public void addItem(ConcreteEntity ce) {
+        if (items == null)
+            items = new LinkedHashSet<ConcreteEntity>();
+        items.add(ce);
+    }
+}

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

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/ConcreteEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/ConcreteEntity.java?rev=1324759&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/ConcreteEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/ConcreteEntity.java
Wed Apr 11 13:40:53 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.proxy;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+
+@Entity
+public class ConcreteEntity extends AbstractEntity {
+    @Basic
+    int field;
+}

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

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java?rev=1324759&r1=1324758&r2=1324759&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java
Wed Apr 11 13:40:53 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.openjpa.persistence.proxy;
 
+import java.util.LinkedHashSet;
+
 import javax.persistence.EntityManager;
 
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -36,7 +38,7 @@ import org.apache.openjpa.util.ProxyColl
  */
 public class TestProxyCollection extends SingleEMFTestCase {
 	public void setUp() {
-		super.setUp(CLEAR_TABLES, TreeNode.class);
+		super.setUp(CLEAR_TABLES, TreeNode.class, ConcreteEntity.class, AbstractEntity.class);
 	}
 	/**
 	 * Tests that a uniform tree is created with expected fan outs at each 
@@ -103,6 +105,24 @@ public class TestProxyCollection extends
 		int[] modifier = {1,2,3}; // remove 1 from each Level 
 		createModifyAndMerge(original, modifier);
 	}
+	
+    public void testCreateCorrectType() {
+        ConcreteEntity ce = new ConcreteEntity();
+        ce.addItem(ce);
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+
+        em.persist(ce);
+        em.getTransaction().commit();
+        em.clear();
+
+        ce = em.find(ConcreteEntity.class, ce.getId());
+        assertNotNull(ce);
+        Class<?> proxyCls = ce.getItems().getClass();
+        assertTrue(proxyCls + " is not assignableFrom " + LinkedHashSet.class,
+            LinkedHashSet.class.isAssignableFrom(proxyCls));
+    }
 	/**
 	 * Create a uniform tree with original fanout.
 	 * Persist.



Mime
View raw message