use of org.apache.cayenne.ejbql.EJBQLParser 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.ejbql.EJBQLParser 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)"));
}
use of org.apache.cayenne.ejbql.EJBQLParser in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testEqualsNullParameter.
// if parameter value is null (in this test x := null) we will generate
// "IS NULL"
@Test
public void testEqualsNullParameter() {
String ejbql = "select p from Painting p WHERE p.toArtist=:x";
EJBQLParser parser = EJBQLParserFactory.getParser();
EJBQLCompiledExpression select = parser.compile(ejbql, runtime.getDataDomain().getEntityResolver());
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("x", null);
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"));
}
Aggregations