use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class CayenneContextEJBQLIT method testEJBQLSelectMixed.
@Test
public void testEJBQLSelectMixed() throws Exception {
createTwoRecords();
EJBQLQuery query = new EJBQLQuery("SELECT COUNT(a), a, a.serverAttribute1 FROM MtTable1 a Group By a ORDER BY a.serverAttribute1");
List<Object[]> results = context.performQuery(query);
assertEquals(2, results.size());
assertEquals(Long.valueOf(1), results.get(0)[0]);
assertTrue(results.get(0)[1] instanceof ClientMtTable1);
assertEquals("s1", results.get(0)[2]);
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class CayenneContextEJBQLIT method testEJBQLSelectScalar.
@Test
public void testEJBQLSelectScalar() throws Exception {
createTwoRecords();
EJBQLQuery query = new EJBQLQuery("SELECT COUNT(a) FROM MtTable1 a");
List<Long> results = context.performQuery(query);
assertEquals(Long.valueOf(2), results.get(0));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class VerticalInheritanceIT method testCountEjbqlQuery.
@Test
public void testCountEjbqlQuery() throws Exception {
TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
ivSub1Table.setColumns("ID", "SUB1_NAME");
TableHelper ivSub2Table = new TableHelper(dbHelper, "IV_SUB2");
ivSub2Table.setColumns("ID", "SUB2_ATTR", "SUB2_NAME");
// Root, IvSub1, IvSub2
ivRootTable.insert(1, "root1", "");
ivRootTable.insert(2, "sub11", "IvSub1");
ivSub1Table.insert(2, "sub_name1_1");
ivRootTable.insert(3, "sub21", "IvSub2");
ivRootTable.insert(4, "sub22", "IvSub2");
ivSub2Table.insert(3, "attr1", "sub_name2_1");
ivSub2Table.insert(4, "attr2", "sub_name2_2");
EJBQLQuery query1 = new EJBQLQuery("SELECT COUNT(a) FROM IvRoot a");
assertEquals(Collections.singletonList(4L), context.performQuery(query1));
EJBQLQuery query2 = new EJBQLQuery("SELECT COUNT(a) FROM IvSub1 a");
assertEquals(Collections.singletonList(1L), context.performQuery(query2));
EJBQLQuery query3 = new EJBQLQuery("SELECT COUNT(a) FROM IvSub2 a");
assertEquals(Collections.singletonList(2L), context.performQuery(query3));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class EJBQLSelectTranslatorIT method translateSelect.
private SQLTemplate translateSelect(String ejbql, final Map<Integer, Object> queryParameters) {
EJBQLParser parser = EJBQLParserFactory.getParser();
EJBQLCompiledExpression select = parser.compile(ejbql, runtime.getDataDomain().getEntityResolver());
EJBQLQuery query = new EJBQLQuery(ejbql) {
@Override
public Map<Integer, Object> getPositionalParameters() {
return queryParameters;
}
};
EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime.getDataDomain().getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory(), adapter.getQuotingStrategy());
select.getExpression().visit(new EJBQLSelectTranslator(tr));
return tr.getQuery();
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testEqualsNullAndNotNullParameter.
// if parameter value is null and more than one parameter in query
@Test
public void testEqualsNullAndNotNullParameter() {
String ejbql = "select p from Painting p WHERE p.toArtist=:x OR p.toArtist.artistName=:b";
EJBQLParser parser = EJBQLParserFactory.getParser();
EJBQLCompiledExpression select = parser.compile(ejbql, runtime.getDataDomain().getEntityResolver());
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("x", null);
query.setParameter("b", "Y");
EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime.getDataDomain().getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory(), adapter.getQuotingStrategy());
select.getExpression().visit(new EJBQLSelectTranslator(tr));
String sql = tr.getQuery().getDefaultTemplate();
assertTrue(sql, sql.endsWith("t0.ARTIST_ID IS NULL OR t1.ARTIST_NAME = #bind($id0)"));
}
Aggregations