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