Search in sources :

Example 16 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereBetween.

@Test
public void testSelectFromWhereBetween() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.estimatedPrice BETWEEN 2000 AND 3500";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals("P1", p.getPaintingTitle());
    assertEquals(3000d, 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 17 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectEntityPathsArrayResult.

@Test
public void testSelectEntityPathsArrayResult() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select p.estimatedPrice, p.toArtist.artistName " + "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 Object[]);
    Object[] row0 = (Object[]) data.get(0);
    assertEquals(2, row0.length);
    assertEquals(3000d, ((BigDecimal) row0[0]).doubleValue(), 0.00001);
    assertEquals("AA1", row0[1]);
    assertTrue(data.get(1) instanceof Object[]);
    Object[] row1 = (Object[]) data.get(1);
    assertEquals(2, row1.length);
    assertEquals(5000d, ((BigDecimal) row1[0]).doubleValue(), 0.00001);
    assertEquals("AA2", row1[1]);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 18 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereAndEqual.

@Test
public void testSelectFromWhereAndEqual() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P where P.paintingTitle = 'P1' " + "AND p.estimatedPrice = 3000";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals("P1", p.getPaintingTitle());
    assertEquals(3000d, 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 19 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereNotEquals.

@Test
public void testSelectFromWhereNotEquals() 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(3, artists.size());
    Iterator<?> it = artists.iterator();
    while (it.hasNext()) {
        Artist a = (Artist) it.next();
        assertFalse("AA2".equals(a.getArtistName()));
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 20 with EJBQLQuery

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

the class DataContextEJBQLQueryIT method testSelectFromWhereDecimalNumber.

@Test
public void testSelectFromWhereDecimalNumber() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.estimatedPrice <= 5000.00";
    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)

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