Search in sources :

Example 6 with FlattenedTest1

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

the class FlattenedArcKeyIT method testEquals.

@Test
public void testEquals() {
    ObjectId src = new ObjectId("X");
    ObjectId target = new ObjectId("Y");
    ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(FlattenedTest3.TO_FT1.getName());
    FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
    FlattenedArcKey update1 = new FlattenedArcKey(target, src, r1.getReverseRelationship());
    ObjRelationship r3 = entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(FlattenedTest1.FT3OVER_COMPLEX.getName());
    FlattenedArcKey update2 = new FlattenedArcKey(target, src, r3);
    assertTrue(update.equals(update1));
    assertFalse(update.equals(update2));
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) ObjRelationship(org.apache.cayenne.map.ObjRelationship) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 7 with FlattenedTest1

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

the class FlattenedRelationshipsIT method testUnsetJoinWithPK.

@Test
public void testUnsetJoinWithPK() throws Exception {
    createCircularJoinDataSet();
    SQLTemplate joinSelect = new SQLTemplate(FlattenedTest1.class, "SELECT * FROM COMPLEX_JOIN");
    joinSelect.setFetchingDataRows(true);
    assertEquals(3, context.performQuery(joinSelect).size());
    FlattenedTest1 ft1 = Cayenne.objectForPK(context, FlattenedTest1.class, 2);
    assertEquals("ft12", ft1.getName());
    List<FlattenedTest3> related = ft1.getFt3OverComplex();
    assertTrue(((ValueHolder) related).isFault());
    assertEquals(2, related.size());
    FlattenedTest3 ft3 = Cayenne.objectForPK(context, FlattenedTest3.class, 3);
    assertTrue(related.contains(ft3));
    ft1.removeFromFt3OverComplex(ft3);
    assertFalse(related.contains(ft3));
    context.commitChanges();
    // the thing here is that there are two join records between
    // FT1 and FT3 (emulating invalid data or extras in the join table that
    // are ignored in the object model).. all (2) joins must be deleted
    assertEquals(1, context.performQuery(joinSelect).size());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) Test(org.junit.Test)

Example 8 with FlattenedTest1

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1 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)

Example 9 with FlattenedTest1

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

the class DataContextEJBQLFlattenedRelationshipsIT method testCollectionInnerJoin.

@Test
public void testCollectionInnerJoin() throws Exception {
    createFt123();
    String ejbql = "SELECT ft FROM FlattenedTest1 ft INNER JOIN ft.ft3Array f WHERE ft = :ft";
    FlattenedTest1 ft = Cayenne.objectForPK(context, FlattenedTest1.class, 1);
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("ft", ft);
    List<?> objects = context.performQuery(query);
    assertNotNull(objects);
    assertFalse(objects.isEmpty());
    assertEquals(1, objects.size());
    Set<Object> ids = new HashSet<Object>();
    Iterator<?> it = objects.iterator();
    while (it.hasNext()) {
        Object id = Cayenne.pkForObject((Persistent) it.next());
        ids.add(id);
    }
    assertTrue(ids.contains(new Integer(1)));
}
Also used : FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with FlattenedTest1

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

the class DataContextEJBQLFlattenedRelationshipsIT method testAssociationFieldSelect.

@Test
public void testAssociationFieldSelect() throws Exception {
    createFt123();
    String ejbql = "SELECT ft3.toFT1 FROM FlattenedTest3 ft3 WHERE ft3.toFT1 = :ft";
    FlattenedTest1 ft = Cayenne.objectForPK(context, FlattenedTest1.class, 1);
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("ft", ft);
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    Set<Object> ids = new HashSet<Object>();
    Iterator<?> it = objects.iterator();
    while (it.hasNext()) {
        Object id = Cayenne.pkForObject((Persistent) it.next());
        ids.add(id);
    }
    assertTrue(ids.contains(new Integer(1)));
}
Also used : FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FlattenedTest1 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1)13 Test (org.junit.Test)13 HashSet (java.util.HashSet)6 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)6 FlattenedTest3 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3)6 ObjectId (org.apache.cayenne.ObjectId)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 FlattenedTest2 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2)2 Expression (org.apache.cayenne.exp.Expression)1 SQLTemplate (org.apache.cayenne.query.SQLTemplate)1 FlattenedTest5 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest5)1