use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextClientChannelEventsIT method testSyncToManyRelationship1.
@Test
public void testSyncToManyRelationship1() throws Exception {
tMtTable1.insert(1, "g1", "s1");
tMtTable2.insert(1, 1, "g1");
CayenneContext c1 = (CayenneContext) runtime.newContext();
CayenneContext c2 = (CayenneContext) runtime.newContext();
ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
// do not resolve objects in question in the second context and see if the merge
// causes any issues...
assertEquals(1, o1.getTable2Array().size());
ClientMtTable2 o1r = c1.newObject(ClientMtTable2.class);
o1r.setGlobalAttribute("X");
o1.addToTable2Array(o1r);
c1.commitChanges();
assertEquals(2, o1.getTable2Array().size());
assertFalse(c1.internalGraphManager().hasChanges());
assertFalse(c2.internalGraphManager().hasChanges());
ClientMtTable1 o2 = (ClientMtTable1) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
assertEquals(2, o2.getTable2Array().size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextClientChannelEventsIT method testSyncToOneRelationship.
@Test
public void testSyncToOneRelationship() throws Exception {
tMtTable1.insert(1, "g1", "s1");
tMtTable1.insert(2, "g2", "s2");
tMtTable2.insert(1, 1, "g1");
CayenneContext c1 = (CayenneContext) runtime.newContext();
CayenneContext c2 = (CayenneContext) runtime.newContext();
ClientMtTable2 o1 = (ClientMtTable2) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable2", "TABLE2_ID", 1)));
ClientMtTable2 o2 = (ClientMtTable2) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable2", "TABLE2_ID", 1)));
assertEquals("g1", o1.getTable1().getGlobalAttribute1());
assertEquals("g1", o2.getTable1().getGlobalAttribute1());
ClientMtTable1 o1r = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 2)));
o1.setTable1(o1r);
c1.commitChanges();
// let the events propagate to peers
Thread.sleep(500);
assertEquals("g2", o2.getTable1().getGlobalAttribute1());
assertEquals(o1r.getObjectId(), o2.getTable1().getObjectId());
assertFalse(c1.internalGraphManager().hasChanges());
assertFalse(c2.internalGraphManager().hasChanges());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextGraphDiffCompressorIT method testComplimentaryArcs.
@Test
public void testComplimentaryArcs() {
ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
o2.setTable1(o1);
o2.setTable1(null);
DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {
public void execute() {
context.commitChanges();
}
});
assertEquals(0, stats.nodePropertiesChanged);
assertEquals(2, stats.nodesCreated);
assertEquals(0, stats.arcsCreated);
assertEquals(0, stats.arcsDeleted);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextRelationshipsIT method testLostUncommittedToOneModifications_Client.
@Test
public void testLostUncommittedToOneModifications_Client() throws Exception {
tMtTable1.insert(1, "G1", "S1");
tMtTable1.insert(2, "G2", "S2");
tMtTable2.insert(33, 1, "GX");
ClientMtTable2 o = Cayenne.objectForPK(context, ClientMtTable2.class, 33);
ClientMtTable1 r2 = Cayenne.objectForPK(context, ClientMtTable1.class, 2);
ClientMtTable1 r1 = o.getTable1();
o.setTable1(r2);
assertSame(r2, o.getTable1());
// see CAY-1757 - this used to reset our changes
assertFalse(r1.getTable2Array().contains(o));
assertSame(r2, o.getTable1());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextServerDiffsIT method testReturnDiffServerArcChanges.
@Test
public void testReturnDiffServerArcChanges() {
LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersistAddRelationship");
ClientMtTable1 o = context.newObject(ClientMtTable1.class);
ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
o.addToTable2Array(o1);
context.commitChanges();
assertFalse(o.getObjectId().isTemporary());
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertEquals(2, o.getTable2Array().size());
} finally {
callbackRegistry.clear();
}
}
Aggregations