use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedObjectContextParentEventsIT method testParentUpdatedId.
@Test
public void testParentUpdatedId() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 ac = child.newObject(ClientMtTable1.class);
ac.setGlobalAttribute1("X");
child.commitChangesToParent();
ClientMtTable1 ap = (ClientMtTable1) clientContext.getGraphManager().getNode(ac.getObjectId());
assertNotNull(ap);
assertTrue(ap.getObjectId().isTemporary());
clientContext.commitChanges();
assertFalse(ap.getObjectId().isTemporary());
assertEquals(ap.getObjectId(), ac.getObjectId());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedSimpleProperty.
@Test
public void testPeerObjectUpdatedSimpleProperty() throws Exception {
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
a.setGlobalAttribute1("X");
clientContext.commitChanges();
ObjectContext peer1 = runtime.newContext(clientContext);
ClientMtTable1 a1 = peer1.localObject(a);
ObjectContext peer2 = runtime.newContext(clientContext);
ClientMtTable1 a2 = peer2.localObject(a);
a1.setGlobalAttribute1("Y");
assertEquals("X", a2.getGlobalAttribute1());
peer1.commitChangesToParent();
assertEquals("Y", a2.getGlobalAttribute1());
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedTempOID.
@Test
public void testPeerObjectUpdatedTempOID() throws Exception {
ObjectContext peer1 = runtime.newContext(clientContext);
ClientMtTable1 a1 = peer1.newObject(ClientMtTable1.class);
a1.setGlobalAttribute1("Y");
ObjectId a1TempId = a1.getObjectId();
ObjectContext peer2 = runtime.newContext(clientContext);
ClientMtTable1 a2 = peer2.localObject(a1);
assertEquals(a1TempId, a2.getObjectId());
peer1.commitChanges();
assertFalse(a1.getObjectId().isTemporary());
assertFalse(a2.getObjectId().isTemporary());
assertEquals(a2.getObjectId(), a1.getObjectId());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedToOneRelationship.
@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
ClientMtTable1 altA = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 p = clientContext.newObject(ClientMtTable2.class);
p.setTable1(a);
p.setGlobalAttribute("PPP");
a.setGlobalAttribute1("X");
altA.setGlobalAttribute1("Y");
clientContext.commitChanges();
ObjectContext peer1 = runtime.newContext(clientContext);
ClientMtTable2 p1 = peer1.localObject(p);
ClientMtTable1 altA1 = peer1.localObject(altA);
ObjectContext peer2 = runtime.newContext(clientContext);
ClientMtTable2 p2 = peer2.localObject(p);
ClientMtTable1 altA2 = peer2.localObject(altA);
ClientMtTable1 a2 = peer2.localObject(a);
p1.setTable1(altA1);
assertSame(a2, p2.getTable1());
peer1.commitChangesToParent();
assertEquals(altA2, p2.getTable1());
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedObjectContextRollbackIT method testRollbackChangesLocally.
@Test
public void testRollbackChangesLocally() {
ObjectContext child1 = runtime.newContext(clientContext);
assertFalse(clientContext.hasChanges());
assertFalse(child1.hasChanges());
clientContext.newObject(ClientMtTable1.class);
child1.newObject(ClientMtTable1.class);
assertTrue(clientContext.hasChanges());
assertTrue(child1.hasChanges());
child1.rollbackChangesLocally();
assertTrue(clientContext.hasChanges());
assertFalse(child1.hasChanges());
clientContext.rollbackChanges();
}
Aggregations