Search in sources :

Example 41 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testCollectionMemberOfThetaJoin.

@Test
public void testCollectionMemberOfThetaJoin() throws Exception {
    createCollectionDataSet();
    String ejbql = "SELECT p FROM Painting p, Artist a " + "WHERE p MEMBER OF a.paintingArray AND a.artistName = 'B'";
    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(33009)));
    assertTrue(ids.contains(new Integer(33010)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 42 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testDateParameter.

@Test
public void testDateParameter() throws Exception {
    createCollectionDataSet();
    SelectQuery q = new SelectQuery(Artist.class);
    List<Artist> allArtists = context.performQuery(q);
    Date dob = new Date();
    allArtists.get(0).setDateOfBirth(dob);
    context.commitChanges();
    String ejbql = "SELECT a FROM Artist a WHERE a.dateOfBirth = :x";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("x", dob);
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    assertSame(allArtists.get(0), objects.get(0));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Date(java.util.Date) Test(org.junit.Test)

Example 43 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testLessOrEquals.

@Test
public void testLessOrEquals() throws Exception {
    createGreaterThanDataSet();
    String ejbql = "SELECT p FROM Painting p WHERE p.estimatedPrice <= :estimatedPrice";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("estimatedPrice", new BigDecimal(4000));
    List<?> objects = context.performQuery(query);
    assertEquals(2, objects.size());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 44 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testCollectionNotEmpty.

@Test
public void testCollectionNotEmpty() throws Exception {
    createCollectionDataSet();
    String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray IS NOT EMPTY";
    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(33001l));
    assertTrue(ids.contains(33002l));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 45 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testNotLike.

@Test
public void testNotLike() throws Exception {
    createLikeDataSet();
    String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle NOT LIKE 'A%C'";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> objects = context.performQuery(query);
    assertEquals(4, 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);
    }
    assertFalse(ids.contains(new Integer(33001)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) 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