use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class NestedCayenneContextIT method testNullifyToOne.
/**
* A test case for CAY-698 bug.
*/
@Test
public void testNullifyToOne() {
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 b = clientContext.newObject(ClientMtTable2.class);
a.addToTable2Array(b);
clientContext.commitChanges();
ObjectContext child = runtime.newContext(clientContext);
ObjectContext childPeer = runtime.newContext(clientContext);
ClientMtTable2 childP1 = SelectById.query(ClientMtTable2.class, b.getObjectId()).selectOne(child);
// trigger object creation in the peer nested DC
Cayenne.objectForPK(childPeer, b.getObjectId());
childP1.setTable1(null);
queryInterceptor.runWithQueriesBlocked(() -> {
child.commitChangesToParent();
assertEquals(PersistenceState.COMMITTED, childP1.getPersistenceState());
ClientMtTable2 parentP1 = (ClientMtTable2) clientContext.getGraphManager().getNode(childP1.getObjectId());
assertNotNull(parentP1);
assertEquals(PersistenceState.MODIFIED, parentP1.getPersistenceState());
assertNull(parentP1.getTable1());
// check that arc changes got recorded in the parent context
GraphDiff diffs = clientContext.internalGraphManager().getDiffs();
final int[] arcDiffs = new int[1];
diffs.apply(new GraphChangeHandler() {
@Override
public void arcCreated(Object nodeId, Object targetNodeId, ArcId arcId) {
arcDiffs[0]++;
}
@Override
public void arcDeleted(Object nodeId, Object targetNodeId, ArcId arcId) {
arcDiffs[0]--;
}
@Override
public void nodeCreated(Object nodeId) {
}
@Override
public void nodeIdChanged(Object nodeId, Object newId) {
}
@Override
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
}
@Override
public void nodeRemoved(Object nodeId) {
}
});
assertEquals(-2, arcDiffs[0]);
});
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class DataContext method rollbackChangesLocally.
/**
* If the parent channel is a DataContext, reverts local changes to make
* this context look like the parent, if the parent channel is a DataDomain,
* reverts all changes.
*
* @since 1.2
*/
@Override
public void rollbackChangesLocally() {
if (objectStore.hasChanges()) {
GraphDiff diff = getObjectStore().getChanges();
getObjectStore().objectsRolledBack();
fireDataChannelRolledback(this, diff);
}
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class CayenneContextGraphManager method graphReverted.
void graphReverted() {
GraphDiff diff = changeLog.getDiffs();
diff.undo(new RollbackChangeHandler());
stateLog.graphReverted();
reset();
if (lifecycleEventsEnabled) {
context.fireDataChannelRolledback(context, diff);
}
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class DataContextCommitIT method testFlushToParent_NewNoAttributes.
@Test
public void testFlushToParent_NewNoAttributes() {
// commit new object with uninitialized attributes
context.newObject(NullTestEntity.class);
assertTrue(context.hasChanges());
GraphDiff diff3 = context.flushToParent(true);
assertNotNull(diff3);
assertFalse(context.hasChanges());
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class DataContextCommitIT method testFlushToParent_Commit_Mix.
@Test
public void testFlushToParent_Commit_Mix() {
Artist a = context.newObject(Artist.class);
a.setArtistName("Test");
context.flushToParent(true);
// commit a mix of new and modified
Painting p = context.newObject(Painting.class);
p.setPaintingTitle("PT");
p.setToArtist(a);
a.setArtistName("Test_");
ObjectId beforeId = p.getObjectId();
GraphDiff diff = context.flushToParent(true);
ObjectId afterId = p.getObjectId();
assertNotNull(diff);
assertFalse(context.hasChanges());
GraphChangeHandler diffChecker = mock(GraphChangeHandler.class);
diff.apply(diffChecker);
verify(diffChecker).nodeIdChanged(beforeId, afterId);
verifyZeroInteractions(diffChecker);
}
Aggregations