use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryIT method testRouteQueryWithPrefetchesNoReverse.
/**
* Tests that all queries specified in prefetch are executed in a more
* complex prefetch scenario with no reverse obj relationships.
*/
@Test
public void testRouteQueryWithPrefetchesNoReverse() {
EntityResolver resolver = context.getEntityResolver();
ObjEntity paintingEntity = resolver.getObjEntity(Painting.class);
ObjEntity galleryEntity = resolver.getObjEntity(Gallery.class);
ObjEntity artistExhibitEntity = resolver.getObjEntity(ArtistExhibit.class);
ObjEntity exhibitEntity = resolver.getObjEntity(Exhibit.class);
ObjRelationship paintingToArtistRel = paintingEntity.getRelationship("toArtist");
paintingEntity.removeRelationship("toArtist");
ObjRelationship galleryToPaintingRel = galleryEntity.getRelationship("paintingArray");
galleryEntity.removeRelationship("paintingArray");
ObjRelationship artistExhibitToArtistRel = artistExhibitEntity.getRelationship("toArtist");
artistExhibitEntity.removeRelationship("toArtist");
ObjRelationship exhibitToArtistExhibitRel = exhibitEntity.getRelationship("artistExhibitArray");
exhibitEntity.removeRelationship("artistExhibitArray");
Expression e = ExpressionFactory.matchExp("artistName", "artist1");
SelectQuery<Artist> q = new SelectQuery<>(Artist.class, e);
q.addPrefetch("paintingArray");
q.addPrefetch("paintingArray.toGallery");
q.addPrefetch("artistExhibitArray.toExhibit");
try {
MockQueryRouter router = new MockQueryRouter();
q.route(router, resolver, null);
assertEquals(4, router.getQueryCount());
} finally {
paintingEntity.addRelationship(paintingToArtistRel);
galleryEntity.addRelationship(galleryToPaintingRel);
artistExhibitEntity.addRelationship(artistExhibitToArtistRel);
exhibitEntity.addRelationship(exhibitToArtistExhibitRel);
}
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryIT method testSelectBooleanTrue.
@Test
public void testSelectBooleanTrue() throws Exception {
createArtistsDataSet();
SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
Expression qual = ExpressionFactory.expTrue();
qual = qual.andExp(ExpressionFactory.matchExp("artistName", "artist1"));
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 testSelectBooleanFalseOr.
@Test
public void testSelectBooleanFalseOr() throws Exception {
createArtistsDataSet();
SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
Expression qual = ExpressionFactory.expFalse();
qual = qual.orExp(ExpressionFactory.matchExp("artistName", "artist1"));
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 testSelectBooleanFalse.
@Test
public void testSelectBooleanFalse() throws Exception {
createArtistsDataSet();
SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
Expression qual = ExpressionFactory.expFalse();
qual = qual.andExp(ExpressionFactory.matchExp("artistName", "artist1"));
query.setQualifier(qual);
List<?> objects = context.performQuery(query);
assertEquals(0, objects.size());
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class SelectQueryIT method testSelectParameterizedEmptyNotIn.
@Test
public void testSelectParameterizedEmptyNotIn() throws Exception {
createArtistsDataSet();
SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
Expression qual = ExpressionFactory.exp("artistName not in $list");
query.setQualifier(qual);
query = query.queryWithParameters(Collections.singletonMap("list", new Object[] {}));
List<?> objects = context.performQuery(query);
assertEquals(20, objects.size());
}
Aggregations