Search in sources :

Example 1 with FlattenedTest2

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2 in project cayenne by apache.

the class FlattenedRelationshipsIT method testToOneSeriesFlattenedRel.

@Test
public void testToOneSeriesFlattenedRel() {
    FlattenedTest1 ft1 = (FlattenedTest1) context.newObject("FlattenedTest1");
    ft1.setName("FT1Name");
    FlattenedTest2 ft2 = (FlattenedTest2) context.newObject("FlattenedTest2");
    ft2.setName("FT2Name");
    FlattenedTest3 ft3 = (FlattenedTest3) context.newObject("FlattenedTest3");
    ft3.setName("FT3Name");
    ft2.setToFT1(ft1);
    ft2.addToFt3Array(ft3);
    context.commitChanges();
    context.invalidateObjects(ft1, ft2, ft3);
    SelectQuery q = new SelectQuery(FlattenedTest3.class);
    q.setQualifier(ExpressionFactory.matchExp("name", "FT3Name"));
    List<?> results = context1.performQuery(q);
    assertEquals(1, results.size());
    FlattenedTest3 fetchedFT3 = (FlattenedTest3) results.get(0);
    FlattenedTest1 fetchedFT1 = fetchedFT3.getToFT1();
    assertEquals("FT1Name", fetchedFT1.getName());
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) SelectQuery(org.apache.cayenne.query.SelectQuery) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) FlattenedTest2(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2) Test(org.junit.Test)

Example 2 with FlattenedTest2

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2 in project cayenne by apache.

the class FlattenedRelationshipsIT method testQualifyOnToManyFlattened.

@Test
public void testQualifyOnToManyFlattened() throws Exception {
    FlattenedTest1 obj01 = context.newObject(FlattenedTest1.class);
    FlattenedTest2 obj02 = context.newObject(FlattenedTest2.class);
    FlattenedTest3 obj031 = context.newObject(FlattenedTest3.class);
    FlattenedTest3 obj032 = context.newObject(FlattenedTest3.class);
    FlattenedTest1 obj11 = context.newObject(FlattenedTest1.class);
    FlattenedTest2 obj12 = context.newObject(FlattenedTest2.class);
    FlattenedTest3 obj131 = context.newObject(FlattenedTest3.class);
    obj01.setName("t01");
    obj02.setName("t02");
    obj031.setName("t031");
    obj032.setName("t032");
    obj02.setToFT1(obj01);
    obj02.addToFt3Array(obj031);
    obj02.addToFt3Array(obj032);
    obj11.setName("t11");
    obj131.setName("t131");
    obj12.setName("t12");
    obj12.addToFt3Array(obj131);
    obj12.setToFT1(obj11);
    context.commitChanges();
    // test 1: qualify on flattened attribute
    Expression qual1 = ExpressionFactory.matchExp("ft3Array.name", "t031");
    SelectQuery query1 = new SelectQuery(FlattenedTest1.class, qual1);
    List<?> objects1 = context.performQuery(query1);
    assertEquals(1, objects1.size());
    assertSame(obj01, objects1.get(0));
    // test 2: qualify on flattened relationship
    Expression qual2 = ExpressionFactory.matchExp("ft3Array", obj131);
    SelectQuery query2 = new SelectQuery(FlattenedTest1.class, qual2);
    List<?> objects2 = context.performQuery(query2);
    assertEquals(1, objects2.size());
    assertSame(obj11, objects2.get(0));
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) SelectQuery(org.apache.cayenne.query.SelectQuery) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) FlattenedTest2(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Aggregations

SelectQuery (org.apache.cayenne.query.SelectQuery)2 FlattenedTest1 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1)2 FlattenedTest2 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2)2 FlattenedTest3 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3)2 Test (org.junit.Test)2 Expression (org.apache.cayenne.exp.Expression)1