use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextIteratedQueryIT method testPerformIteratedQuery_CommitWithinIterator.
@Test
public void testPerformIteratedQuery_CommitWithinIterator() throws Exception {
createArtistsAndPaintingsDataSet();
assertEquals(7, tPainting.getRowCount());
try (ResultIterator<?> it = context.performIteratedQuery(SelectQuery.query(Artist.class))) {
while (it.hasNextRow()) {
DataRow row = (DataRow) it.nextRow();
Artist artist = context.objectFromDataRow(Artist.class, row);
Painting painting = context.newObject(Painting.class);
painting.setPaintingTitle("P_" + artist.getArtistName());
painting.setToArtist(artist);
context.commitChanges();
}
}
assertEquals(14, tPainting.getRowCount());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextIteratedQueryIT method testPerformIteratedQuery_resolve.
@Test
public void testPerformIteratedQuery_resolve() throws Exception {
createArtistsAndPaintingsDataSet();
try (ResultIterator<?> it = context.performIteratedQuery(SelectQuery.query(Artist.class))) {
while (it.hasNextRow()) {
DataRow row = (DataRow) it.nextRow();
// try instantiating an object and fetching its relationships
Artist artist = context.objectFromDataRow(Artist.class, row);
List<Painting> paintings = artist.getPaintingArray();
assertNotNull(paintings);
assertEquals("Expected one painting for artist: " + artist, 1, paintings.size());
}
}
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextPerformQueryAPIIT method testNonSelectingQueryString.
@Test
public void testNonSelectingQueryString() throws Exception {
int[] counts = context.performNonSelectingQuery("NonSelectingQuery");
assertNotNull(counts);
assertEquals(1, counts.length);
assertEquals(1, counts[0]);
Painting p = Cayenne.objectForPK(context, Painting.class, 512);
assertEquals("No Painting Like This", p.getPaintingTitle());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchToOneWithBackRelationship.
@Test
public void testPrefetchToOneWithBackRelationship() throws Exception {
createArtistWithTwoPaintingsAndTwoInfosDataSet();
SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
query.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
query.addPrefetch(Painting.TO_PAINTING_INFO.dot(PaintingInfo.PAINTING).disjoint());
final List<Painting> results = context.select(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
Painting p0 = results.get(0);
PaintingInfo pi0 = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
assertNotNull(pi0);
assertNotNull(pi0.readPropertyDirectly(PaintingInfo.PAINTING.getName()));
}
});
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_ToOneWithQualifierOverlappingPrefetchPath.
@Test
public void testPrefetch_ToOneWithQualifierOverlappingPrefetchPath() throws Exception {
createTwoArtistsAndTwoPaintingsDataSet();
Expression exp = ExpressionFactory.matchExp("toArtist.artistName", "artist3");
SelectQuery q = new SelectQuery(Painting.class, exp);
q.addPrefetch(Painting.TO_ARTIST.disjoint());
final List<Painting> results = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
Painting painting = results.get(0);
// The parent must be fully fetched, not just HOLLOW (a fault)
assertEquals(PersistenceState.COMMITTED, painting.getToArtist().getPersistenceState());
}
});
}
Aggregations