use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testChangeRel.
@Test
public void testChangeRel() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 a = child.newObject(ClientMtTable1.class);
ClientMtTable2 b = child.newObject(ClientMtTable2.class);
child.commitChanges();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
a.addToTable2Array(b);
assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());
child.commitChangesToParent();
ClientMtTable1 parentA = (ClientMtTable1) clientContext.getGraphManager().getNode(a.getObjectId());
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
assertEquals(1, parentA.getTable2Array().size());
clientContext.commitChanges();
assertEquals(PersistenceState.COMMITTED, parentA.getPersistenceState());
a.removeFromTable2Array(b);
assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());
child.commitChangesToParent();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
assertEquals(0, parentA.getTable2Array().size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testCommitChangesToParentOneToMany.
@Test
public void testCommitChangesToParentOneToMany() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 master = child.newObject(ClientMtTable1.class);
ClientMtTable2 dep = child.newObject(ClientMtTable2.class);
master.addToTable2Array(dep);
child.commitChangesToParent();
ClientMtTable1 masterParent = (ClientMtTable1) clientContext.getGraphManager().getNode(master.getObjectId());
ClientMtTable2 depParent = (ClientMtTable2) clientContext.getGraphManager().getNode(dep.getObjectId());
assertNotNull(masterParent);
assertNotNull(depParent);
assertSame(masterParent, depParent.getTable1());
assertTrue(masterParent.getTable2Array().contains(depParent));
// check that arc changes got recorded in the parent context
GraphDiff diffs = clientContext.internalGraphManager().getDiffs();
final int[] arcDiffs = new int[1];
final int[] newNodes = new int[1];
diffs.apply(new GraphChangeHandler() {
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
arcDiffs[0]++;
}
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
arcDiffs[0]--;
}
public void nodeCreated(Object nodeId) {
newNodes[0]++;
}
public void nodeIdChanged(Object nodeId, Object newId) {
}
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
}
public void nodeRemoved(Object nodeId) {
newNodes[0]--;
}
});
assertEquals(2, newNodes[0]);
assertEquals(2, arcDiffs[0]);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testCAY1183.
@Test
public void testCAY1183() throws Exception {
ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
clientContext.commitChanges();
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(child, parentMt.getObjectId());
childMt.setGlobalAttribute1("1183");
ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
childMt2.setGlobalAttribute("1183");
childMt2.setTable1(childMt);
child.commitChangesToParent();
// fetching other relationship... this fails per CAY-1183
childMt2.getTable3();
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testCAY1194.
@Test
public void testCAY1194() throws Exception {
ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
childMt2.setGlobalAttribute("222");
ClientMtTable1 localParentMt = child.localObject(parentMt);
assertEquals(0, parentMt.getTable2Array().size());
assertEquals(0, localParentMt.getTable2Array().size());
childMt2.setTable1(localParentMt);
assertEquals(0, parentMt.getTable2Array().size());
assertEquals(1, localParentMt.getTable2Array().size());
assertEquals(localParentMt.getTable2Array().get(0).getObjectContext(), child);
child.commitChangesToParent();
assertEquals(1, parentMt.getTable2Array().size());
assertEquals(parentMt.getTable2Array().get(0).getObjectContext(), clientContext);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testQueriesOnTemporaryObject.
/**
* CAY1714
*/
@Test
public void testQueriesOnTemporaryObject() throws Exception {
ObjectContext clientContext = runtime.newContext((DataChannel) this.clientContext);
ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
ObjectContext childContext = runtime.newContext((DataChannel) clientContext);
ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(childContext, parentMt.getObjectId());
childMt.setGlobalAttribute1("1183");
ClientMtTable2 childMt2 = childContext.newObject(ClientMtTable2.class);
childMt2.setGlobalAttribute("1183");
childMt2.setTable1(childMt);
childContext.commitChangesToParent();
assertNull(childMt2.getTable3());
}
Aggregations