q.setCachePolicy(QueryMetadata.LOCAL_CACHE);
q.setCacheGroups("X");
List paints = context.performQuery(q);
// fetch P1 separately from cached query
Painting p1 = DataObjectUtils.objectForPK(context, Painting.class, 33001);
Painting p2 = (Painting) paints.get(0);
Artist a1 = p2.getToArtist();
assertSame(a1, p1.getToArtist());
assertNotNull(context
.getParentDataDomain()
.getSharedSnapshotCache()
.getCachedSnapshot(p1.getObjectId()));
assertNotNull(context
.getParentDataDomain()
.getSharedSnapshotCache()
.getCachedSnapshot(p2.getObjectId()));
createTestData("testRefreshCollectionToOneUpdate");
// results are served from cache and therefore are not refreshed
context.performQuery(q);
assertSame(a1, p1.getToArtist());
assertSame(a1, p2.getToArtist());
assertEquals("c", p1.getToArtist().getArtistName());
assertEquals("c", p2.getToArtist().getArtistName());
RefreshQuery refresh = new RefreshQuery("X");
// this should invalidate results for the next query run
context.performQuery(refresh);
// this should force a refresh
context.performQuery(q);
assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, p2.getPersistenceState());
assertSame(a1, p1.getToArtist());
assertNotSame(a1, p2.getToArtist());
assertEquals("c", p1.getToArtist().getArtistName());
assertEquals("b", p2.getToArtist().getArtistName());
}