use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryIT method testSelectLikeSingle_WildcardMatch.
@Test
public void testSelectLikeSingle_WildcardMatch() throws Exception {
createArtistsDataSet();
SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
Expression qual = ExpressionFactory.likeExp("artistName", "artist11%");
query.setQualifier(qual);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryIT method testSelectOne.
@Test
public void testSelectOne() throws Exception {
createArtistsDataSet();
SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
Expression qual = ExpressionFactory.matchExp("artistName", "artist1");
query.setQualifier(qual);
Artist artist = (Artist) query.selectOne(context);
assertEquals("artist1", artist.getArtistName());
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryIT method testRouteQueryWithPrefetchesPrefetchExpressionPath.
/**
* Test prefetching with qualifier on the root query being the path to the
* prefetch.
*/
@Test
public void testRouteQueryWithPrefetchesPrefetchExpressionPath() {
// find the painting not matching the artist (this is the case where
// such prefetch
// at least makes sense)
Expression exp = ExpressionFactory.noMatchExp("toArtist", new Object());
SelectQuery<Painting> q = new SelectQuery<>(Painting.class, exp);
q.addPrefetch("toArtist");
// test how prefetches are resolved in this case - this was a stumbling
// block for
// a while
EntityResolver resolver = context.getEntityResolver();
MockQueryRouter router = new MockQueryRouter();
q.route(router, resolver, null);
assertEquals(2, router.getQueryCount());
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryIT method testSelectParameterizedEmptyIn.
@Test
public void testSelectParameterizedEmptyIn() throws Exception {
createArtistsDataSet();
SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
Expression qual = ExpressionFactory.exp("artistName in $list");
query.setQualifier(qual);
query = query.queryWithParameters(Collections.singletonMap("list", new Object[] {}));
List<?> objects = context.performQuery(query);
assertEquals(0, objects.size());
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryReturnTypesIT method testSelectBitwiseXor.
@Test
public void testSelectBitwiseXor() throws Exception {
if (!accessStackAdapter.supportsBitwiseOps()) {
return;
}
createNumericsDataSet();
// to simplify result checking, do double NOT
Expression left = new ASTBitwiseXor(new Object[] { new ASTObjPath(ReturnTypesMap1.INTEGER_COLUMN.getName()), new ASTScalar(1) });
Expression right = new ASTScalar(5);
Expression equal = new ASTEqual();
equal.setOperand(0, left);
equal.setOperand(1, right);
SelectQuery query = new SelectQuery(ReturnTypesMap1.class);
query.setQualifier(equal);
List<ReturnTypesMap1> objects = context.performQuery(query);
assertEquals(1, objects.size());
assertEquals(4, objects.get(0).getIntegerColumn().intValue());
}
Aggregations