use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextParentPeerEventsIT method testPeerObjectUpdatedSimpleProperty.
@Test
public void testPeerObjectUpdatedSimpleProperty() throws Exception {
Master a = parentContext1.newObject(Master.class);
a.setName("X");
parentContext1.commitChanges();
Master a1 = parentContext2.localObject(a);
final ObjectContext child = runtime.newContext(parentContext1);
final Master a2 = child.localObject(a);
a1.setName("Y");
assertEquals("X", a2.getName());
parentContext2.commitChangesToParent();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals("Y", a2.getName());
assertFalse("Peer data context became dirty on event processing", child.hasChanges());
}
}.runTest(2000);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedToManyRelationship.
@Test
public void testPeerObjectUpdatedToManyRelationship() throws Exception {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
Painting px = context.newObject(Painting.class);
px.setToArtist(a);
px.setPaintingTitle("PX");
Painting py = context.newObject(Painting.class);
py.setPaintingTitle("PY");
context.commitChanges();
// pause to let the context events propagate
Thread.sleep(500);
ObjectContext peer1 = runtime.newContext(context);
Painting py1 = peer1.localObject(py);
Artist a1 = peer1.localObject(a);
final ObjectContext peer2 = runtime.newContext(context);
final Painting py2 = peer2.localObject(py);
final Artist a2 = peer2.localObject(a);
a1.addToPaintingArray(py1);
assertEquals(1, a2.getPaintingArray().size());
assertFalse(a2.getPaintingArray().contains(py2));
peer1.commitChangesToParent();
// pause to let the context events propagate
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals(2, a2.getPaintingArray().size());
assertTrue(a2.getPaintingArray().contains(py2));
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
}.runTest(2000);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedSimpleProperty.
@Test
public void testPeerObjectUpdatedSimpleProperty() throws Exception {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
context.commitChanges();
ObjectContext peer1 = runtime.newContext(context);
Artist a1 = peer1.localObject(a);
final ObjectContext peer2 = runtime.newContext(context);
final Artist a2 = peer2.localObject(a);
a1.setArtistName("Y");
assertEquals("X", a2.getArtistName());
peer1.commitChangesToParent();
// pause to let the context events propagate
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals("Y", a2.getArtistName());
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
}.runTest(2000);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedTempOID.
@Test
public void testPeerObjectUpdatedTempOID() throws Exception {
ObjectContext peer1 = runtime.newContext(context);
final Artist a1 = peer1.newObject(Artist.class);
a1.setArtistName("Y");
ObjectId a1TempId = a1.getObjectId();
assertTrue(a1TempId.isTemporary());
ObjectContext peer2 = runtime.newContext(context);
final Artist a2 = peer2.localObject(a1);
assertEquals(a1TempId, a2.getObjectId());
peer1.commitChanges();
// pause to let the context events propagate
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertFalse(a1.getObjectId().isTemporary());
assertFalse(a2.getObjectId().isTemporary());
assertEquals(a2.getObjectId(), a1.getObjectId());
}
}.runTest(2000);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextReadIT method testCreateChildDataContext.
@Test
public void testCreateChildDataContext() {
context.setValidatingObjectsOnCommit(true);
ObjectContext child1 = runtime.newContext(context);
assertNotNull(child1);
assertSame(context, child1.getChannel());
assertTrue(((DataContext) child1).isValidatingObjectsOnCommit());
context.setValidatingObjectsOnCommit(false);
ObjectContext child2 = runtime.newContext(context);
assertNotNull(child2);
assertSame(context, child2.getChannel());
assertFalse(((DataContext) child2).isValidatingObjectsOnCommit());
// second level of nesting
ObjectContext child21 = runtime.newContext(child2);
assertNotNull(child21);
assertSame(child2, child21.getChannel());
assertFalse(((DataContext) child2).isValidatingObjectsOnCommit());
}
Aggregations