Search in sources :

Example 1 with ReflexiveAndToOne

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReflexiveAndToOne(org.apache.cayenne.testdo.relationships.ReflexiveAndToOne) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 2 with ReflexiveAndToOne

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();
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ReflexiveAndToOne(org.apache.cayenne.testdo.relationships.ReflexiveAndToOne) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 3 with ReflexiveAndToOne

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();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ReflexiveAndToOne(org.apache.cayenne.testdo.relationships.ReflexiveAndToOne) Test(org.junit.Test)

Aggregations

ReflexiveAndToOne (org.apache.cayenne.testdo.relationships.ReflexiveAndToOne)3 Test (org.junit.Test)3 Expression (org.apache.cayenne.exp.Expression)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 ObjEntity (org.apache.cayenne.map.ObjEntity)1