Search in sources :

Example 11 with FlattenedTest1

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

the class DataContextEJBQLFlattenedRelationshipsIT method testCollectionMemberOfThetaJoin.

@Test
public void testCollectionMemberOfThetaJoin() throws Exception {
    createFt123();
    String ejbql = "SELECT f FROM FlattenedTest3 f, FlattenedTest1 ft " + "WHERE f MEMBER OF ft.ft3Array AND ft = :ft";
    FlattenedTest1 ft = Cayenne.objectForPK(context, FlattenedTest1.class, 2);
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("ft", ft);
    List<?> objects = context.performQuery(query);
    assertEquals(2, 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(2));
    assertTrue(ids.contains(3));
}
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 12 with FlattenedTest1

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

the class DataContextEJBQLFlattenedRelationshipsIT method testCollectionAsInnerJoin.

@Test
public void testCollectionAsInnerJoin() throws Exception {
    createFt123();
    // this query is equivalent to the previous INNER JOIN example
    String ejbql = "SELECT OBJECT(ft) FROM FlattenedTest1 ft, IN(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 13 with FlattenedTest1

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

the class DataContextEJBQLFlattenedRelationshipsIT method testCollectionIdentificationVariable.

@Test
public void testCollectionIdentificationVariable() throws Exception {
    createFt123();
    String ejbql = "SELECT ft.ft3Array FROM FlattenedTest1 ft WHERE ft = :ft";
    FlattenedTest1 ft = Cayenne.objectForPK(context, FlattenedTest1.class, 2);
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("ft", ft);
    List<?> objects = context.performQuery(query);
    assertNotNull(objects);
    assertFalse(objects.isEmpty());
    assertEquals(2, 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(2)));
    assertTrue(ids.contains(new Integer(3)));
}
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