use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextReadIT method testPrefetchingToMany.
@Test
public void testPrefetchingToMany() throws Exception {
createPrefetchingDataSet();
final ObjectContext child = runtime.newContext(context);
final List<Artist> results = ObjectSelect.query(Artist.class).orderBy(Artist.ARTIST_NAME.asc()).prefetch(Artist.PAINTING_ARRAY.disjoint()).select(child);
queryInterceptor.runWithQueriesBlocked(() -> {
Artist o1 = results.get(0);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(child, o1.getObjectContext());
List<Painting> children1 = o1.getPaintingArray();
assertEquals(ToManyList.class, children1.getClass());
assertEquals(2, children1.size());
for (Painting o : children1) {
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(child, o.getObjectContext());
assertEquals(o1, o.getToArtist());
}
Artist o2 = results.get(1);
assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
assertSame(child, o2.getObjectContext());
List<Painting> children2 = o2.getPaintingArray();
assertEquals(0, children2.size());
});
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextReadIT method testPageableSelect.
@Test
public void testPageableSelect() throws Exception {
createArtistsDataSet();
ObjectContext child = runtime.newContext(context);
@SuppressWarnings("unchecked") IncrementalFaultList<Artist> records = (IncrementalFaultList) ObjectSelect.query(Artist.class).orderBy(Artist.ARTIST_NAME.desc()).pageSize(1).select(child);
assertEquals(4, records.size());
assertEquals(1, records.getPageSize());
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextParentEventsIT method testParentUpdatedId.
@Test
public void testParentUpdatedId() throws Exception {
ObjectContext child1 = runtime.newContext(context);
final Artist ac = child1.newObject(Artist.class);
ac.setArtistName("X");
child1.commitChangesToParent();
final Artist ap = (Artist) context.getGraphManager().getNode(ac.getObjectId());
assertNotNull(ap);
assertTrue(ap.getObjectId().isTemporary());
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertFalse(ap.getObjectId().isTemporary());
assertEquals(ap.getObjectId(), ac.getObjectId());
}
}.runTest(1000);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedDataContextPeerEventsIT method testPeerObjectUpdatedToOneRelationship.
@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
Artist a = context.newObject(Artist.class);
Artist altA = context.newObject(Artist.class);
Painting p = context.newObject(Painting.class);
p.setToArtist(a);
p.setPaintingTitle("PPP");
a.setArtistName("X");
altA.setArtistName("Y");
context.commitChanges();
ObjectContext peer1 = runtime.newContext(context);
Painting p1 = peer1.localObject(p);
Artist altA1 = peer1.localObject(altA);
final ObjectContext peer2 = runtime.newContext(context);
final Painting p2 = peer2.localObject(p);
final Artist altA2 = peer2.localObject(altA);
Artist a2 = peer2.localObject(a);
p1.setToArtist(altA1);
assertSame(a2, p2.getToArtist());
peer1.commitChangesToParent();
// pause to let the context events propagate
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals(altA2, p2.getToArtist());
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 NestedDataContextRollbackIT method testRollbackChanges.
@Test
public void testRollbackChanges() {
ObjectContext child1 = runtime.newContext(context);
assertFalse(context.hasChanges());
assertFalse(child1.hasChanges());
context.newObject(Artist.class);
child1.newObject(Artist.class);
assertTrue(context.hasChanges());
assertTrue(child1.hasChanges());
child1.rollbackChanges();
assertFalse(context.hasChanges());
assertFalse(child1.hasChanges());
}
Aggregations