use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class DataContextRefreshQueryIT method testRefreshSingleObject.
@Test
public void testRefreshSingleObject() throws Exception {
createRefreshCollectionDataSet();
SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
q.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING);
List<?> artists = context.performQuery(q);
Artist a1 = (Artist) artists.get(0);
assertEquals(2, a1.getPaintingArray().size());
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(a1.getObjectId()));
RefreshQuery refresh = new RefreshQuery(a1);
context.performQuery(refresh);
assertNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(a1.getObjectId()));
assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
assertTrue(((ValueHolder) a1.readProperty(Artist.PAINTING_ARRAY.getName())).isFault());
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class DataContextRefreshQueryIT method testRefreshAll.
@Test
public void testRefreshAll() throws Exception {
createRefreshCollectionDataSet();
SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
q.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING);
List<?> artists = context.performQuery(q);
Artist a1 = (Artist) artists.get(0);
Artist a2 = (Artist) artists.get(1);
Painting p1 = a1.getPaintingArray().get(0);
Painting p2 = a1.getPaintingArray().get(0);
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(a1.getObjectId()));
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(a2.getObjectId()));
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p1.getObjectId()));
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p2.getObjectId()));
RefreshQuery refresh = new RefreshQuery();
context.performQuery(refresh);
assertNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(a1.getObjectId()));
assertNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(a2.getObjectId()));
assertNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p1.getObjectId()));
assertNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p2.getObjectId()));
assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
assertEquals(PersistenceState.HOLLOW, a2.getPersistenceState());
assertEquals(PersistenceState.HOLLOW, p1.getPersistenceState());
assertEquals(PersistenceState.HOLLOW, p2.getPersistenceState());
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class DataDomainCallbacksIT method testPostLoad.
@Test
public void testPostLoad() throws Exception {
LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
registry.addCallback(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
MockCallingBackListener listener = new MockCallingBackListener();
registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, listener, "publicCallback");
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XX");
context.commitChanges();
assertEquals(0, a1.getPostLoaded());
assertNull(listener.getPublicCalledbackEntity());
SelectQuery q = new SelectQuery(Artist.class);
context.performQuery(q);
assertEquals(1, a1.getPostLoaded());
assertSame(a1, listener.getPublicCalledbackEntity());
a1.resetCallbackFlags();
listener.reset();
// post load must be called on rollback...
a1.resetCallbackFlags();
listener.reset();
context.rollbackChanges();
assertEquals(0, a1.getPostLoaded());
assertNull(listener.getPublicCalledbackEntity());
// now change and rollback the artist - postLoad must be called
a1.setArtistName("YY");
context.rollbackChanges();
assertEquals(1, a1.getPostLoaded());
assertSame(a1, listener.getPublicCalledbackEntity());
// test invalidated
a1.resetCallbackFlags();
listener.reset();
assertEquals(0, a1.getPostLoaded());
assertNull(listener.getPublicCalledbackEntity());
context.performQuery(new RefreshQuery(a1));
assertEquals(0, a1.getPostLoaded());
assertNull(listener.getPublicCalledbackEntity());
a1.getArtistName();
assertEquals(1, a1.getPostLoaded());
assertSame(a1, listener.getPublicCalledbackEntity());
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class CDOSetRelationshipIT method testRemoveToMany.
@Test
public void testRemoveToMany() throws Exception {
createTestDataSet();
SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
Set targets = o1.getTargets();
assertEquals(3, targets.size());
SetToManyTarget target = Cayenne.objectForPK(o1.getObjectContext(), SetToManyTarget.class, 2);
o1.removeFromTargets(target);
assertEquals(2, targets.size());
assertFalse(o1.getTargets().contains(target));
assertNull(target.getSetToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(2, o1.getTargets().size());
assertFalse(o1.getTargets().contains(target));
}
use of org.apache.cayenne.query.RefreshQuery in project cayenne by apache.
the class CDOSetRelationshipIT method testAddToManyViaReverse.
@Test
public void testAddToManyViaReverse() throws Exception {
createTestDataSet();
SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
Set targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
SetToManyTarget newTarget = o1.getObjectContext().newObject(SetToManyTarget.class);
newTarget.setSetToMany(o1);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getSetToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
Aggregations