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);
}
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]);
}
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);
}
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()));
}
}
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());
}
Aggregations