You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2008/08/05 19:38:17 UTC
svn commit: r682822 - in /openjpa/branches/1.2.x:
openjpa-kernel/src/main/java/org/apache/openjpa/util/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/
Author: mikedd
Date: Tue Aug 5 10:38:17 2008
New Revision: 682822
URL: http://svn.apache.org/viewvc?rev=682822&view=rev
Log:
OPENJPA-628. Revert changes from revision 610922 and add testcase.
Added:
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/Node.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveRelationships.java (with props)
Modified:
openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java
Modified: openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java?rev=682822&r1=682821&r2=682822&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java (original)
+++ openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyCollections.java Tue Aug 5 10:38:17 2008
@@ -38,11 +38,7 @@
*/
public static void beforeAdd(ProxyCollection coll, int index, Object value){
assertAllowedType(value, coll.getElementType());
- if (index == coll.size())
- // optimize for adding to the end
- beforeAdd(coll, value);
- else
- dirty(coll, true);
+ dirty(coll, true);
}
/**
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/Node.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/Node.java?rev=682822&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/Node.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/Node.java Tue Aug 5 10:38:17 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.recursive;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Version;
+
+@Entity
+public class Node {
+
+ @Id
+ @GeneratedValue
+ private int id;
+ @Version
+ private int version;
+
+ @OneToMany
+ private List<Node> nodes = new ArrayList<Node>();
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ public List<Node> getNodes() {
+ return nodes;
+ }
+
+ public void setNodes(List<Node> nodes) {
+ this.nodes = nodes;
+ }
+
+}
\ No newline at end of file
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/Node.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveRelationships.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveRelationships.java?rev=682822&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveRelationships.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveRelationships.java Tue Aug 5 10:38:17 2008
@@ -0,0 +1,81 @@
+/*
+ * 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.recursive;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestRecursiveRelationships extends SingleEMFTestCase {
+ private int _l1Nodes = 3;
+ private int _l2Nodes = 3;
+
+ public void setUp() {
+ setUp(Node.class);
+ }
+
+ public void testRecursiveNodes() {
+ EntityManager em = emf.createEntityManager();
+
+ // set up initial tree
+ em.getTransaction().begin();
+ Node root = new Node();
+ for (int i = 0; i < _l1Nodes; i++) {
+ Node n1 = new Node();
+ root.getNodes().add(n1);
+ em.persist(n1);
+ }
+ em.persist(root);
+ em.getTransaction().commit();
+
+ // clear PC
+ em.refresh(root);
+ int rootId = root.getId();
+ em.clear();
+ em.close();
+ em = emf.createEntityManager();
+
+ // add new nodes
+ em.getTransaction().begin();
+ root = em.getReference(Node.class, rootId);
+ assertNotNull(root);
+ assertNotNull(root.getNodes());
+ for (Node n : root.getNodes()) {
+ for (int j = 0; j < _l2Nodes; j++) {
+ Node n2 = new Node();
+ n.getNodes().add(n.getNodes().size(), n2);
+ em.persist(n2);
+ }
+ }
+ em.getTransaction().commit();
+ em.clear();
+ em.close();
+ em = emf.createEntityManager();
+
+ // ensure count is correct.
+ root = em.getReference(Node.class, rootId);
+ assertNotNull(root);
+ assertNotNull(root.getNodes());
+ assertEquals(_l1Nodes, root.getNodes().size());
+ for (Node n : root.getNodes()) {
+ assertEquals(_l2Nodes, n.getNodes().size());
+ }
+ em.close();
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveRelationships.java
------------------------------------------------------------------------------
svn:eol-style = native