use of org.apache.cayenne.testdo.relationships.ReflexiveAndToOne in project cayenne by apache.
the class CAY_194IT method testQualifyOnToMany.
@Test
public void testQualifyOnToMany() {
ReflexiveAndToOne ox = context.newObject(ReflexiveAndToOne.class);
ox.setName("ox");
ReflexiveAndToOne o1 = context.newObject(ReflexiveAndToOne.class);
o1.setName("o1");
ReflexiveAndToOne o2 = context.newObject(ReflexiveAndToOne.class);
o2.setName("o2");
o2.setToParent(o1);
context.commitChanges();
Expression qualifier = ExpressionFactory.matchExp("children", o2);
List<?> parents = context.performQuery(new SelectQuery(ReflexiveAndToOne.class, qualifier));
assertEquals(1, parents.size());
assertSame(o1, parents.get(0));
qualifier = ExpressionFactory.matchExp("children", o1);
parents = context.performQuery(new SelectQuery(ReflexiveAndToOne.class, qualifier));
assertEquals(0, parents.size());
}
use of org.apache.cayenne.testdo.relationships.ReflexiveAndToOne in project cayenne by apache.
the class CAY_194IT method testQualifyOnToOne.
@Test
public void testQualifyOnToOne() {
ReflexiveAndToOne ox = context.newObject(ReflexiveAndToOne.class);
ox.setName("ox");
ReflexiveAndToOne o1 = context.newObject(ReflexiveAndToOne.class);
o1.setName("o1");
ReflexiveAndToOne o2 = context.newObject(ReflexiveAndToOne.class);
o2.setName("o2");
o2.setToParent(o1);
context.commitChanges();
Expression qualifier = ExpressionFactory.matchExp("toParent", o1);
List<?> children = context.performQuery(new SelectQuery(ReflexiveAndToOne.class, qualifier));
assertEquals(1, children.size());
assertSame(o2, children.get(0));
o2.setToParent(null);
context.commitChanges();
}
use of org.apache.cayenne.testdo.relationships.ReflexiveAndToOne in project cayenne by apache.
the class AshwoodEntitySorter_RelationshipsIT method testSortObjectsForEntityReflexiveWithFaults.
@Test
public void testSortObjectsForEntityReflexiveWithFaults() throws Exception {
tRelationshipHelper.insert(1, "rh1");
tReflexiveAndToOne.insert(1, null, 1, "r1");
tReflexiveAndToOne.insert(2, 1, 1, "r2");
tReflexiveAndToOne.insert(3, 2, 1, "r3");
ObjEntity entity = context.getEntityResolver().getObjEntity(ReflexiveAndToOne.class);
List<?> objects = context.performQuery(new SelectQuery<>(ReflexiveAndToOne.class));
Collections.shuffle(objects);
assertEquals(3, objects.size());
sorter.sortObjectsForEntity(entity, objects, true);
assertEquals("r3", ((ReflexiveAndToOne) objects.get(0)).getName());
assertEquals("r2", ((ReflexiveAndToOne) objects.get(1)).getName());
assertEquals("r1", ((ReflexiveAndToOne) objects.get(2)).getName());
tReflexiveAndToOne.delete().where("PARENT_ID", 2).execute();
tReflexiveAndToOne.delete().where("PARENT_ID", 1).execute();
tReflexiveAndToOne.deleteAll();
}
Aggregations