Search in sources :

Example 1 with GrandChild

use of com.orientechnologies.orient.test.domain.cycle.GrandChild in project orientdb by orientechnologies.

the class ObjectDetachingTest method testDetachAllWithCycles.

public void testDetachAllWithCycles() {
    database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.cycle");
    CycleParent parent = new CycleParent();
    parent.setName("parent");
    CycleChild cycleChild1 = new CycleChild();
    cycleChild1.setParent(parent);
    cycleChild1.setName("child1");
    parent.getChildren().add(cycleChild1);
    CycleChild cycleChild2 = new CycleChild();
    cycleChild2.setName("child2");
    cycleChild2.setParent(parent);
    parent.getChildren().add(cycleChild2);
    GrandChild grandChild = new GrandChild();
    grandChild.setName("grandchild");
    grandChild.setGrandParent(parent);
    cycleChild1.getGrandChildren().add(grandChild);
    CycleParent attached = database.save(parent);
    CycleParent detachedParent = database.detachAll(attached, true);
    Assert.assertEquals(detachedParent.getName(), parent.getName());
    Assert.assertEquals(detachedParent.getChildren().getClass(), ArrayList.class);
    CycleChild detachedCycleChild1 = detachedParent.getChildren().get(0);
    CycleChild detachedCycleChild2 = detachedParent.getChildren().get(1);
    Assert.assertEquals(detachedCycleChild1.getName(), cycleChild1.getName());
    Assert.assertEquals(detachedCycleChild2.getName(), cycleChild2.getName());
    Assert.assertEquals(detachedCycleChild1.getGrandChildren().getClass(), HashSet.class);
    GrandChild detachedGrandChild = detachedCycleChild1.getGrandChildren().iterator().next();
    Assert.assertEquals(detachedGrandChild.getName(), grandChild.getName());
    Assert.assertSame(detachedGrandChild.getGrandParent(), detachedParent);
}
Also used : CycleChild(com.orientechnologies.orient.test.domain.cycle.CycleChild) CycleParent(com.orientechnologies.orient.test.domain.cycle.CycleParent) GrandChild(com.orientechnologies.orient.test.domain.cycle.GrandChild)

Aggregations

CycleChild (com.orientechnologies.orient.test.domain.cycle.CycleChild)1 CycleParent (com.orientechnologies.orient.test.domain.cycle.CycleParent)1 GrandChild (com.orientechnologies.orient.test.domain.cycle.GrandChild)1