Search in sources :

Example 86 with EJBQLQuery

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

the class DataContextEJBQLOrderByIT method testOrderByQualified.

@Test
public void testOrderByQualified() throws Exception {
    createThreePaintings();
    String ejbql1 = "SELECT p FROM Painting p WHERE p.estimatedPrice > 1000 ORDER BY p.paintingTitle ASC";
    EJBQLQuery query1 = new EJBQLQuery(ejbql1);
    List<?> results1 = context.performQuery(query1);
    assertEquals(2, results1.size());
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(0)));
    assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(1)));
    String ejbql2 = "SELECT p FROM Painting p WHERE p.estimatedPrice > 1000 ORDER BY p.estimatedPrice ASC";
    EJBQLQuery query2 = new EJBQLQuery(ejbql2);
    List<?> results2 = context.performQuery(query2);
    assertEquals(2, results2.size());
    assertEquals(33002, Cayenne.intPKForObject((Persistent) results2.get(0)));
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results2.get(1)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 87 with EJBQLQuery

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

the class DataContextEJBQLOrderByIT method testOrderByDefault.

@Test
public void testOrderByDefault() throws Exception {
    createThreePaintings();
    String ejbql1 = "SELECT p FROM Painting p ORDER BY p.paintingTitle";
    EJBQLQuery query1 = new EJBQLQuery(ejbql1);
    List<?> results1 = context.performQuery(query1);
    assertEquals(3, results1.size());
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(0)));
    assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(1)));
    assertEquals(33003, Cayenne.intPKForObject((Persistent) results1.get(2)));
    String ejbql2 = "SELECT p FROM Painting p ORDER BY p.estimatedPrice";
    EJBQLQuery query2 = new EJBQLQuery(ejbql2);
    List<?> results2 = context.performQuery(query2);
    assertEquals(3, results2.size());
    assertEquals(33003, Cayenne.intPKForObject((Persistent) results2.get(0)));
    assertEquals(33002, Cayenne.intPKForObject((Persistent) results2.get(1)));
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results2.get(2)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 88 with EJBQLQuery

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

the class DataContextEJBQLQueryCompoundIT method testSelectFromWhereMatchOnMultiColumnObjectReverse.

@Test
public void testSelectFromWhereMatchOnMultiColumnObjectReverse() throws Exception {
    if (!accessStackAdapter.supportsReverseComparison()) {
        return;
    }
    createTwoCompoundPKTwoFK();
    Map<String, String> key1 = new HashMap<>();
    key1.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "b1");
    key1.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "b2");
    CompoundPkTestEntity a = Cayenne.objectForPK(context, CompoundPkTestEntity.class, key1);
    String ejbql = "select e from CompoundFkTestEntity e WHERE :param = e.toCompoundPk";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("param", a);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    CompoundFkTestEntity o1 = (CompoundFkTestEntity) ps.get(0);
    assertEquals(33002, Cayenne.intPKForObject(o1));
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) HashMap(java.util.HashMap) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 89 with EJBQLQuery

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

the class DataContextEJBQLQueryCompoundIT method testSelectFromWhereNoMatchOnMultiColumnObject.

@Test
public void testSelectFromWhereNoMatchOnMultiColumnObject() throws Exception {
    createTwoCompoundPKTwoFK();
    Map<String, String> key1 = new HashMap<>();
    key1.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "b1");
    key1.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "b2");
    CompoundPkTestEntity a = Cayenne.objectForPK(context, CompoundPkTestEntity.class, key1);
    String ejbql = "select e from CompoundFkTestEntity e WHERE e.toCompoundPk <> :param";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("param", a);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    CompoundFkTestEntity o1 = (CompoundFkTestEntity) ps.get(0);
    assertEquals(33001, Cayenne.intPKForObject(o1));
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) HashMap(java.util.HashMap) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 90 with EJBQLQuery

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

the class CayenneIT method testEjbql.

@Test
public void testEjbql() throws Exception {
    createOneArtist();
    List<?> objects = context.performQuery(new EJBQLQuery("select a from Artist a"));
    assertEquals(1, objects.size());
    Artist object = (Artist) objects.get(0);
    assertEquals(new Long(33002), Cayenne.pkForObject(object));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) 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