use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class CDOSetRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
createTestDataSet();
SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
Set targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
SetToManyTarget newTarget = o1.getObjectContext().newObject(SetToManyTarget.class);
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getSetToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class CDOCollectionRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
Collection<?> targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
CollectionToManyTarget newTarget = o1.getObjectContext().newObject(CollectionToManyTarget.class);
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getCollectionToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class CDOMapRelationshipIT method testRemoveToMany.
@Test
public void testRemoveToMany() throws Exception {
createTestDataSet();
MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
Map targets = o1.getTargets();
assertEquals(3, targets.size());
MapToManyTarget target = (MapToManyTarget) targets.get("B");
o1.removeFromTargets(target);
assertEquals(2, targets.size());
assertNull(o1.getTargets().get("B"));
assertNull(target.getMapToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(2, o1.getTargets().size());
assertNotNull(o1.getTargets().get("A"));
assertNotNull(o1.getTargets().get("C"));
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class CDOMapRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
createTestDataSet();
MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
Map targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
MapToManyTarget newTarget = o1.getObjectContext().newObject(MapToManyTarget.class);
newTarget.setName("X");
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertSame(newTarget, o1.getTargets().get("X"));
assertSame(o1, newTarget.getMapToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class CDOMapRelationshipIT method testAddToManyViaReverse.
@Test
public void testAddToManyViaReverse() throws Exception {
createTestDataSet();
MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
Map targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
MapToManyTarget newTarget = o1.getObjectContext().newObject(MapToManyTarget.class);
newTarget.setName("X");
newTarget.setMapToMany(o1);
assertSame(o1, newTarget.getMapToMany());
assertEquals(4, targets.size());
assertSame(newTarget, o1.getTargets().get("X"));
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
Aggregations