Search in sources :

Example 46 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLConditionsIT method testLikeEscape.

@Test
public void testLikeEscape() throws Exception {
    createLikeDataSet();
    String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'X_DDDD' ESCAPE 'X'";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    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(33005)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLConditionsIT method testCollectionNotMemberOfParameter.

@Test
public void testCollectionNotMemberOfParameter() throws Exception {
    createCollectionDataSet();
    String ejbql = "SELECT a FROM Artist a WHERE :x NOT MEMBER a.paintingArray";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("x", Cayenne.objectForPK(context, Painting.class, 33010));
    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(33002l));
    assertTrue(ids.contains(33003l));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 48 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLConditionsIT method testCollectionEmpty.

@Test
public void testCollectionEmpty() throws Exception {
    createCollectionDataSet();
    String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray IS EMPTY";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    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 Long(33003)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 49 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLConditionsIT method testInSubquery.

@Test
public void testInSubquery() throws Exception {
    createInSubqueryDataSet();
    String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle IN (" + "SELECT p1.paintingTitle FROM Painting p1 WHERE p1.paintingTitle = 'C'" + ")";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    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(new Integer(33012)));
    assertTrue(ids.contains(new Integer(33014)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLConditionsPeopleIT method testCollectionNotMemberOfToOne.

@Test
public void testCollectionNotMemberOfToOne() throws Exception {
    // need a better test ... this query returns zero rows by definition
    String ejbql = "SELECT a" + " FROM Address a JOIN a.toEmployee m JOIN m.toDepartment d" + " WHERE m NOT MEMBER d.employees";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> objects = context.performQuery(query);
    assertEquals(0, objects.size());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Aggregations

EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)160 Test (org.junit.Test)158 Artist (org.apache.cayenne.testdo.testmap.Artist)39 HashSet (java.util.HashSet)35 Painting (org.apache.cayenne.testdo.testmap.Painting)15 QueryResponse (org.apache.cayenne.QueryResponse)12 BigDecimal (java.math.BigDecimal)10 Persistent (org.apache.cayenne.Persistent)10 List (java.util.List)9 ArrayList (java.util.ArrayList)7 FlattenedTest1 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1)6 CompoundPainting (org.apache.cayenne.testdo.testmap.CompoundPainting)5 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)5 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 ValueHolder (org.apache.cayenne.ValueHolder)4 CompoundPkTestEntity (org.apache.cayenne.testdo.compound.CompoundPkTestEntity)4 Gallery (org.apache.cayenne.testdo.testmap.Gallery)4 Calendar (java.util.Calendar)3 EJBQLCompiledExpression (org.apache.cayenne.ejbql.EJBQLCompiledExpression)3