Search in sources :

Example 96 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testFetchLimit.

@Test
public void testFetchLimit() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select a FROM Artist a";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setFetchLimit(2);
    List<?> artists = context.performQuery(query);
    assertEquals(2, artists.size());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 97 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereGreaterOrEqual.

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

Example 98 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereGreater.

@Test
public void testSelectFromWhereGreater() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.estimatedPrice > 3000";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals("P2", p.getPaintingTitle());
    assertEquals(5000d, p.getEstimatedPrice().doubleValue(), 0.00001);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 99 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectDbPath_Relationship.

@Test
public void testSelectDbPath_Relationship() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select db:p.toArtist " + "from Painting p order by p.estimatedPrice";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> data = context.performQuery(query);
    assertEquals(2, data.size());
    assertTrue(data.get(0) instanceof Artist);
    assertEquals(33001, Cayenne.intPKForObject((Artist) data.get(0)));
    assertTrue(data.get(1) instanceof Artist);
    assertEquals(33002, Cayenne.intPKForObject((Artist) data.get(1)));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 100 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereEqual.

@Test
public void testSelectFromWhereEqual() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select a from Artist a where a.artistName = 'AA2'";
    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)

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