use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextCayenneIT method testObjectForPK.
@Test
public void testObjectForPK() throws Exception {
context.performGenericQuery(new SQLTemplate(ClientMtTable1.class, "insert into MT_TABLE1 " + "(TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) " + "values (1, 'g1', 's1')"));
ClientMtTable1 o = Cayenne.objectForPK(context, ClientMtTable1.class, 1);
assertNotNull(o);
assertEquals("g1", o.getGlobalAttribute1());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 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.ClientMtTable1 in project cayenne by apache.
the class CayenneContextClientChannelEventsIT method testSyncNewDeletedObject.
@Test
public void testSyncNewDeletedObject() throws Exception {
CayenneContext c1 = (CayenneContext) runtime.newContext();
CayenneContext c2 = (CayenneContext) runtime.newContext();
assertNotSame(c1, c2);
// insert, then delete - this shouldn't propagate via an event.
ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1("X");
c1.deleteObjects(o1);
// introduce some other change so that commit can go ahead...
ClientMtTable1 o1x = c1.newObject(ClientMtTable1.class);
o1x.setGlobalAttribute1("Y");
c1.commitChanges();
ClientMtTable1 o2 = (ClientMtTable1) c2.getGraphManager().getNode(o1.getObjectId());
assertNull(o2);
assertFalse(c1.internalGraphManager().hasChanges());
assertFalse(c2.internalGraphManager().hasChanges());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 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.ClientMtTable1 in project cayenne by apache.
the class CayenneContextClientChannelEventsIT method testSyncNewObject.
@Test
public void testSyncNewObject() throws Exception {
CayenneContext c1 = (CayenneContext) runtime.newContext();
CayenneContext c2 = (CayenneContext) runtime.newContext();
assertNotSame(c1, c2);
ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1("X");
c1.commitChanges();
ClientMtTable1 o2 = (ClientMtTable1) c2.getGraphManager().getNode(o1.getObjectId());
assertNull(o2);
// now fetch it fresh
o2 = (ClientMtTable1) c2.performQuery(new ObjectIdQuery(o1.getObjectId())).get(0);
assertNotNull(o2);
assertEquals("X", o2.getGlobalAttribute1());
assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
assertFalse(c1.internalGraphManager().hasChanges());
assertFalse(c2.internalGraphManager().hasChanges());
}
Aggregations