use of org.apache.cayenne.testdo.testmap.Painting 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.testdo.testmap.Painting in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_ToOne_ObjPath.
@Test
public void testPrefetch_ToOne_ObjPath() throws Exception {
createTwoArtistsAndTwoPaintingsDataSet();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.disjoint());
q.andQualifier(ExpressionFactory.matchExp("toArtist.artistName", "artist2"));
List<Painting> results = context.performQuery(q);
assertEquals(1, results.size());
}
use of org.apache.cayenne.testdo.testmap.Painting 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.testdo.testmap.Painting in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchJointAndDisjointByIdTogether.
@Test
public void testPrefetchJointAndDisjointByIdTogether() throws Exception {
createArtistWithTwoPaintingsAndTwoInfosDataSet();
SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
query.addPrefetch(Painting.TO_ARTIST.joint());
query.addPrefetch(Painting.TO_PAINTING_INFO.disjointById());
final List<Painting> results = context.select(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
Painting p0 = results.get(0);
Artist a0 = (Artist) p0.readPropertyDirectly(Painting.TO_ARTIST.getName());
assertNotNull(a0);
PaintingInfo info = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
assertNotNull(info);
}
});
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_OneToOneWithQualifier.
@Test
public void testPrefetch_OneToOneWithQualifier() throws Exception {
createArtistWithTwoPaintingsAndTwoInfosDataSet();
Expression e = ExpressionFactory.likeExp("toArtist.artistName", "a%");
SelectQuery q = new SelectQuery(Painting.class, e);
q.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
q.addOrdering(Painting.PAINTING_TITLE.asc());
final List<Painting> results = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, results.size());
// testing non-null to-one target
Painting p0 = results.get(0);
Object o2 = p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
assertTrue(o2 instanceof PaintingInfo);
PaintingInfo pi2 = (PaintingInfo) o2;
assertEquals(PersistenceState.COMMITTED, pi2.getPersistenceState());
assertEquals(Cayenne.intPKForObject(p0), Cayenne.intPKForObject(pi2));
// testing null to-one target
Painting p1 = results.get(1);
assertNull(p1.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName()));
// there was a bug marking an object as dirty when clearing the
// relationships
assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
}
});
}
Aggregations