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());
}
}
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);
}
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());
}
}
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 = ?)");
}
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 (?, ?, ?)");
}
Aggregations