mirror of https://github.com/apache/openjpa.git
OPENJPA-628. Revert changes from revision 610922 and add testcase.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@682821 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aba5ddc7fb
commit
e41e1dd976
|
@ -38,10 +38,6 @@ public class ProxyCollections
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue