Search in sources :

Example 11 with EJBQLQuery

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

the class DataContextEJBQLQueryCompoundIT method testSelectFromWhereMatchOnMultiColumnObject.

@Test
public void testSelectFromWhereMatchOnMultiColumnObject() 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(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 12 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereEqualReverseOrder.

@Test
public void testSelectFromWhereEqualReverseOrder() throws Exception {
    if (!accessStackAdapter.supportsReverseComparison()) {
        return;
    }
    createFourArtistsTwoPaintings();
    String ejbql = "select a from Artist a where 'AA2' = a.artistName";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> artists = context.performQuery(query);
    assertEquals(1, artists.size());
    assertEquals("AA2", ((Artist) artists.get(0)).getArtistName());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 13 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectEntityPathsScalarResult.

@Test
public void testSelectEntityPathsScalarResult() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select p.paintingTitle" + " from Painting p order by p.paintingTitle DESC";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> data = context.performQuery(query);
    assertEquals(2, data.size());
    assertEquals("P2", data.get(0));
    assertEquals("P1", data.get(1));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 14 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereDecimalNumberNamed.

@Test
public void testSelectFromWhereDecimalNumberNamed() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.estimatedPrice <= :param";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("param", new BigDecimal(5000.00));
    List<?> ps = context.performQuery(query);
    assertEquals(2, ps.size());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 15 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereDecimalNumberPositional.

@Test
public void testSelectFromWhereDecimalNumberPositional() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.estimatedPrice <= ?1";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter(1, new BigDecimal(5000.00));
    List<?> ps = context.performQuery(query);
    assertEquals(2, ps.size());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BigDecimal(java.math.BigDecimal) 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