Search in sources :

Example 36 with EJBQLQuery

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

the class DataContextEJBQLArrayResultIT method testSQLResultSetMappingScalar.

@Test
public void testSQLResultSetMappingScalar() throws Exception {
    String ejbql = "SELECT count(p) FROM Painting p JOIN p.toArtist a";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    Object o1 = objects.get(0);
    assertEquals(new Long(2), o1);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 37 with EJBQLQuery

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

the class DataContextEJBQLArrayResultIT method testSQLResultSetMappingMixed.

@Test
public void testSQLResultSetMappingMixed() throws Exception {
    String ejbql = "SELECT count(p), a, sum(p.estimatedPrice) " + "FROM Artist a LEFT JOIN a.paintingArray p " + "GROUP BY a ORDER BY a.artistName";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> objects = context.performQuery(query);
    assertEquals(4, objects.size());
    Object o1 = objects.get(0);
    assertTrue("Expected Object[]: " + o1, o1 instanceof Object[]);
    Object[] array1 = (Object[]) o1;
    assertEquals(3, array1.length);
    assertEquals(new Long(1), array1[0]);
    assertTrue("Expected Artist, got: " + array1[1], array1[1] instanceof Artist);
    assertEquals(0, new BigDecimal(3000).compareTo((BigDecimal) array1[2]));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 38 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testLike1.

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

Example 39 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testNotIn.

@Test
public void testNotIn() throws Exception {
    createInDataSet();
    String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle NOT IN ('A', 'B')";
    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(33008)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with EJBQLQuery

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

the class DataContextEJBQLConditionsIT method testLikeEscape_LikeParameter.

@Test
public void testLikeEscape_LikeParameter() throws Exception {
    createLikeDataSet();
    // test for CAY-1426
    String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE ?1 ESCAPE 'X'";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter(1, "X_DDDD");
    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)

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