Search in sources :

Example 91 with Artist

use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.

the class SelectQueryIT method testSelectLikeCaseSensitive.

/**
 * SQL Server failure:
 * http://stackoverflow.com/questions/14962419/is-the-like-operator-case-sensitive-with-ms-sql-server
 */
@Test
public void testSelectLikeCaseSensitive() throws Exception {
    if (!accessStackAdapter.supportsCaseSensitiveLike()) {
        return;
    }
    createArtistsDataSet();
    SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
    Expression qual = ExpressionFactory.likeExp("artistName", "aRtIsT%");
    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 92 with Artist

use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.

the class SelectQueryIT method testSelectEmptyIn.

@Test
public void testSelectEmptyIn() throws Exception {
    createArtistsDataSet();
    SelectQuery<Artist> query = new SelectQuery<>(Artist.class);
    Expression qual = ExpressionFactory.inExp("artistName");
    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 93 with Artist

use of org.apache.cayenne.testdo.testmap.Artist 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 94 with Artist

use of org.apache.cayenne.testdo.testmap.Artist 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 95 with Artist

use of org.apache.cayenne.testdo.testmap.Artist 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)

Aggregations

Artist (org.apache.cayenne.testdo.testmap.Artist)490 Test (org.junit.Test)481 Painting (org.apache.cayenne.testdo.testmap.Painting)145 SelectQuery (org.apache.cayenne.query.SelectQuery)126 Expression (org.apache.cayenne.exp.Expression)67 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)47 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)39 List (java.util.List)36 ObjectContext (org.apache.cayenne.ObjectContext)30 SQLTemplate (org.apache.cayenne.query.SQLTemplate)26 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)26 DataRow (org.apache.cayenne.DataRow)21 ArrayList (java.util.ArrayList)20 ValueHolder (org.apache.cayenne.ValueHolder)18 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)16 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)15 ObjectId (org.apache.cayenne.ObjectId)14 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)13 Gallery (org.apache.cayenne.testdo.testmap.Gallery)12 ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)12