use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SQLSelectIT method test_Iterator.
@Test
public void test_Iterator() throws Exception {
createPaintingsDataSet();
try (ResultIterator<Painting> it = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING").columnNameCaps(CapsStrategy.UPPER).iterator(context)) {
int count = 0;
for (Painting p : it) {
count++;
}
assertEquals(20, count);
}
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SQLSelectIT method test_DataRows_ClassRoot_Parameters.
@Test
public void test_DataRows_ClassRoot_Parameters() throws Exception {
createPaintingsDataSet();
SQLSelect<Painting> q1 = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING WHERE PAINTING_TITLE = #bind($a)");
q1.params("a", "painting3").columnNameCaps(CapsStrategy.UPPER);
assertFalse(q1.isFetchingDataRows());
Painting a = context.selectOne(q1);
assertEquals("painting3", a.getPaintingTitle());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SQLTemplateIT method testSQLTemplateWithDisjointByIdPrefetch.
@Test
public void testSQLTemplateWithDisjointByIdPrefetch() throws Exception {
tArtist.insert(1, "artist1");
tArtist.insert(2, "artist2");
tPainting.insert(1, 1, "p1", 10);
tPainting.insert(2, 2, "p2", 20);
String sql = "SELECT p.* FROM PAINTING p";
SQLTemplate q1 = new SQLTemplate(Painting.class, sql);
q1.addPrefetch(Painting.TO_ARTIST.disjointById());
q1.setColumnNamesCapitalization(CapsStrategy.UPPER);
@SuppressWarnings("unchecked") List<Painting> paintings = context.performQuery(q1);
queryInterceptor.runWithQueriesBlocked(() -> {
for (Painting painting : paintings) {
assertEquals(PersistenceState.COMMITTED, painting.getToArtist().getPersistenceState());
}
});
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SelectQueryIT method testMatchByRelatedObject.
@Test
public void testMatchByRelatedObject() {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("a1");
Artist a2 = context.newObject(Artist.class);
a2.setArtistName("a2");
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("p1");
p1.setToArtist(a1);
Painting p2 = context.newObject(Painting.class);
p2.setPaintingTitle("p2");
p2.setToArtist(a2);
context.commitChanges();
SelectQuery<Painting> query = new SelectQuery<>(Painting.class);
query.setQualifier(ExpressionFactory.matchExp("toArtist", a1));
assertSame(p1, query.selectOne(context));
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SelectQueryIT method testRouteQueryWithPrefetchesPrefetchExpressionPath.
/**
* Test prefetching with qualifier on the root query being the path to the
* prefetch.
*/
@Test
public void testRouteQueryWithPrefetchesPrefetchExpressionPath() {
// find the painting not matching the artist (this is the case where
// such prefetch
// at least makes sense)
Expression exp = ExpressionFactory.noMatchExp("toArtist", new Object());
SelectQuery<Painting> q = new SelectQuery<>(Painting.class, exp);
q.addPrefetch("toArtist");
// test how prefetches are resolved in this case - this was a stumbling
// block for
// a while
EntityResolver resolver = context.getEntityResolver();
MockQueryRouter router = new MockQueryRouter();
q.route(router, resolver, null);
assertEquals(2, router.getQueryCount());
}
Aggregations