use of org.apache.cayenne.unit.di.UnitTestClosure 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());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_ToOneWith_OuterJoinFlattenedQualifier.
@Test
public void testPrefetch_ToOneWith_OuterJoinFlattenedQualifier() throws Exception {
tArtGroup.insert(1, "AG");
tArtist.insert(11, "artist2");
tArtist.insert(101, "artist3");
tPainting.insert(6, "p_artist3", 101, 1000, null);
tPainting.insert(7, "p_artist21", 11, 2000, null);
tPainting.insert(8, "p_artist22", 11, 3000, null);
// flattened join matches an object that is NOT the one we are looking
// for
tArtistGroup.insert(101, 1);
// OUTER join part intentionally doesn't match anything
Expression exp = Property.create("groupArray+.name", String.class).eq("XX").orExp(Artist.ARTIST_NAME.eq("artist2"));
SelectQuery<Artist> q = new SelectQuery<Artist>(Artist.class, exp);
q.addPrefetch(Artist.PAINTING_ARRAY.disjoint());
final List<Artist> results = context.select(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
Artist a = results.get(0);
assertEquals("artist2", a.getArtistName());
assertEquals(2, a.getPaintingArray().size());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_ToOne.
@Test
public void testPrefetch_ToOne() throws Exception {
createTwoArtistsAndTwoPaintingsDataSet();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.disjoint());
final List<Painting> result = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Painting p1 = result.get(0);
Object toOnePrefetch = p1.readNestedProperty("toArtist");
assertNotNull(toOnePrefetch);
assertTrue("Expected Artist, got: " + toOnePrefetch.getClass().getName(), toOnePrefetch instanceof Artist);
Artist a1 = (Artist) toOnePrefetch;
assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchWithLocalCache.
/**
* This test and next one is the result of CAY-2349 fix
*/
@Test
public void testPrefetchWithLocalCache() throws Exception {
tArtist.deleteAll();
tGallery.deleteAll();
tPainting.deleteAll();
tArtist.insert(1, "artist1");
tGallery.insert(1, "gallery1");
tPainting.insert(1, "painting1", 1, 100, 1);
List<Painting> paintings = ObjectSelect.query(Painting.class).localCache("g1").select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
paintings = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.joint()).localCache("g1").select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<Painting> paintings = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.joint()).localCache("g1").select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_ReflexiveRelationship.
@Test
public void testPrefetch_ReflexiveRelationship() throws Exception {
ArtGroup parent = (ArtGroup) context.newObject("ArtGroup");
parent.setName("parent");
ArtGroup child = (ArtGroup) context.newObject("ArtGroup");
child.setName("child");
child.setToParentGroup(parent);
context.commitChanges();
SelectQuery q = new SelectQuery("ArtGroup");
q.setQualifier(ExpressionFactory.matchExp("name", "child"));
q.addPrefetch("toParentGroup");
final List<ArtGroup> results = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
ArtGroup fetchedChild = results.get(0);
// The parent must be fully fetched, not just HOLLOW (a fault)
assertEquals(PersistenceState.COMMITTED, fetchedChild.getToParentGroup().getPersistenceState());
}
});
child.setToParentGroup(null);
context.commitChanges();
}
Aggregations