Search in sources :

Example 36 with Expression

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);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) Expression(org.apache.cayenne.exp.Expression) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 37 with Expression

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());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 38 with Expression

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());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 39 with Expression

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());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 40 with Expression

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());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Aggregations

Expression (org.apache.cayenne.exp.Expression)298 Test (org.junit.Test)265 Artist (org.apache.cayenne.testdo.testmap.Artist)69 SelectQuery (org.apache.cayenne.query.SelectQuery)47 Painting (org.apache.cayenne.testdo.testmap.Painting)29 BigDecimal (java.math.BigDecimal)23 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)16 ObjEntity (org.apache.cayenne.map.ObjEntity)13 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 DbEntity (org.apache.cayenne.map.DbEntity)10 List (java.util.List)9 HashMap (java.util.HashMap)8 DataRow (org.apache.cayenne.DataRow)8 DbAttribute (org.apache.cayenne.map.DbAttribute)8 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)7 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ObjAttribute (org.apache.cayenne.map.ObjAttribute)6 ObjRelationship (org.apache.cayenne.map.ObjRelationship)6 Gallery (org.apache.cayenne.testdo.testmap.Gallery)6