Search in sources :

Example 91 with EJBQLQuery

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

the class EJBQLQueryDescriptor method buildQuery.

@Override
public EJBQLQuery buildQuery() {
    EJBQLQuery ejbqlQuery = new EJBQLQuery(this.getEjbql());
    ejbqlQuery.initWithProperties(this.getProperties());
    return ejbqlQuery;
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery)

Example 92 with EJBQLQuery

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

the class CayenneContextEJBQLIT method testEJBQLSelect.

@Test
public void testEJBQLSelect() throws Exception {
    createTwoRecords();
    EJBQLQuery query = new EJBQLQuery("SELECT a FROM MtTable1 a");
    List<ClientMtTable1> results = context.performQuery(query);
    assertEquals(2, results.size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 93 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereMatchOnObject.

@Test
public void testSelectFromWhereMatchOnObject() throws Exception {
    createFourArtistsTwoPaintings();
    Artist a = Cayenne.objectForPK(context, Artist.class, 33002);
    String ejbql = "select P from Painting P WHERE p.toArtist = :param";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("param", a);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals(33002, Cayenne.intPKForObject(p));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 94 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectDbPath.

@Test
public void testSelectDbPath() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select db:p.ESTIMATED_PRICE " + "from Painting p order by p.estimatedPrice";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> data = context.performQuery(query);
    assertEquals(2, data.size());
    assertEquals(3000d, ((BigDecimal) data.get(0)).doubleValue(), 0.00001);
    assertEquals(5000d, ((BigDecimal) data.get(1)).doubleValue(), 0.00001);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 95 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSimpleSelect.

@Test
public void testSimpleSelect() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select a FROM Artist a";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> artists = context.performQuery(query);
    assertEquals(4, artists.size());
    assertTrue(artists.get(0) instanceof Artist);
    assertTrue(((Artist) artists.get(0)).getPersistenceState() == PersistenceState.COMMITTED);
}
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