use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextMaxIdQualifierIT method testDisjointByIdPrefetch.
@Test
public void testDisjointByIdPrefetch() throws Exception {
insertData();
runtime.getDataDomain().setMaxIdQualifierSize(10);
final SelectQuery query = new SelectQuery(Artist.class);
query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
context.performQuery(query);
}
});
assertEquals(11, queriesCount);
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextMaxIdQualifierIT method testDisjointByIdPrefetch_Zero.
@Test
public void testDisjointByIdPrefetch_Zero() throws Exception {
insertData();
runtime.getDataDomain().setMaxIdQualifierSize(0);
final SelectQuery query = new SelectQuery(Artist.class);
query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
context.performQuery(query);
}
});
assertEquals(2, queriesCount);
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextDisjointByIdPrefetchIT method testFetchLimit.
@Test
public void testFetchLimit() throws Exception {
createThreeArtistsWithPlentyOfPaintingsDataSet();
final SelectQuery query = new SelectQuery(Artist.class);
query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
query.addOrdering("db:" + Artist.ARTIST_ID_PK_COLUMN, SortOrder.ASCENDING);
query.setFetchLimit(2);
// There will be only 2 bags in a result. The first bag has 5 boxes and
// the second has 2. So we are expecting exactly 9 snapshots in the data
// row store after performing the query.
final List<Artist> bags = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, bags.size());
assertEquals(5, bags.get(0).getPaintingArray().size());
assertEquals(2, bags.get(1).getPaintingArray().size());
for (Artist b : bags) {
b.getArtistName();
for (Painting bx : b.getPaintingArray()) {
bx.getPaintingTitle();
}
}
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextDisjointByIdPrefetchIT method testOneToOneRelationship.
@Test
public void testOneToOneRelationship() throws Exception {
createTwoPaintingsWithInfosDataSet();
SelectQuery query = new SelectQuery(Painting.class);
query.addPrefetch(Painting.TO_PAINTING_INFO.disjointById());
final List<Painting> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
List<String> boxColors = new ArrayList<String>();
for (Painting box : result) {
PaintingInfo info = (PaintingInfo) box.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
assertNotNull(info);
boxColors.add(info.getTextReview());
assertEquals(PersistenceState.COMMITTED, info.getPersistenceState());
}
assertTrue(boxColors.containsAll(Arrays.asList("red", "green")));
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextDisjointByIdPrefetchIT method testManyToOne.
@Test
public void testManyToOne() throws Exception {
createArtistWithTwoPaintingsDataSet();
SelectQuery query = new SelectQuery(Painting.class);
query.addPrefetch(Painting.TO_ARTIST.disjointById());
final List<Painting> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Painting b1 = result.get(0);
assertNotNull(b1.getToArtist());
assertEquals(PersistenceState.COMMITTED, b1.getToArtist().getPersistenceState());
assertEquals("X", b1.getToArtist().getArtistName());
}
});
}
Aggregations