Search in sources :

Example 21 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SimpleIdIncrementalFaultListPrefetchIT method testPrefetch3.

/**
 * Test that a to-many relationship is initialized.
 */
@Test
public void testPrefetch3() throws Exception {
    createArtistsAndPaintingsDataSet();
    Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
    SelectQuery q = new SelectQuery("Artist", e);
    q.addPrefetch("paintingArray");
    q.setPageSize(3);
    IncrementalFaultList result = (IncrementalFaultList) context.performQuery(q);
    assertEquals(6, result.size());
    // currently queries with prefetch do not resolve their first page
    assertEquals(result.size(), result.getUnfetchedObjects());
    // go through the second page objects and check their to many
    for (int i = 3; i < 6; i++) {
        Artist a = (Artist) result.get(i);
        List paintings = a.getPaintingArray();
        assertFalse(((ValueHolder) paintings).isFault());
        assertEquals(1, paintings.size());
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) List(java.util.List) Test(org.junit.Test)

Example 22 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SimpleIdIncrementalFaultListPrefetchIT method testPrefetch1.

/**
 * Test that all queries specified in prefetch are executed with a single prefetch
 * path.
 */
@Test
public void testPrefetch1() throws Exception {
    createArtistsAndPaintingsDataSet();
    Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
    SelectQuery q = new SelectQuery("Artist", e);
    q.addPrefetch("paintingArray");
    q.setPageSize(3);
    final IncrementalFaultList<?> result = (IncrementalFaultList) context.performQuery(q);
    assertEquals(6, result.size());
    // currently queries with prefetch do not resolve their first page
    assertEquals(result.size(), result.getUnfetchedObjects());
    int count = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            // go through the second page objects and count queries
            for (int i = 3; i < 6; i++) {
                result.get(i);
            }
        }
    });
    // within the same page only one query should've been executed
    assertEquals(1, count);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 23 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class SelectActionIT method testFetchLimit_DistinctResultIterator.

@Test
public void testFetchLimit_DistinctResultIterator() throws Exception {
    if (accessStackAdapter.supportsLobs()) {
        insertClobDb();
        Expression qual = ExpressionFactory.exp("clobValue.value = 100");
        SelectQuery select = new SelectQuery(ClobTestEntity.class, qual);
        select.setFetchLimit(25);
        List<DataRow> resultRows = context.performQuery(select);
        assertNotNull(resultRows);
        assertEquals(25, resultRows.size());
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 24 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class QualifierTranslatorIT method testExtras.

@Test
public void testExtras() throws Exception {
    ObjectId oid1 = new ObjectId("Gallery", "GALLERY_ID", 1);
    ObjectId oid2 = new ObjectId("Gallery", "GALLERY_ID", 2);
    Gallery g1 = new Gallery();
    Gallery g2 = new Gallery();
    g1.setObjectId(oid1);
    g2.setObjectId(oid2);
    Expression e1 = ExpressionFactory.matchExp("toGallery", g1);
    Expression e2 = e1.orExp(ExpressionFactory.matchExp("toGallery", g2));
    doExpressionTest(Exhibit.class, e2, "(ta.GALLERY_ID = ?) OR (ta.GALLERY_ID = ?)");
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Expression(org.apache.cayenne.exp.Expression) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Test(org.junit.Test)

Example 25 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class QualifierTranslatorIT method testBinary_In3.

@Test
public void testBinary_In3() throws Exception {
    Expression exp = ExpressionFactory.inExp("toGallery.galleryName", new Object[] { "g1", "g2", "g3" });
    doExpressionTest(Exhibit.class, exp, "ta.GALLERY_NAME IN (?, ?, ?)");
}
Also used : 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