use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class ClientServerChannelIT method testOnQueryPrefetchingToManyEmpty.
@Test
public void testOnQueryPrefetchingToManyEmpty() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class);
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<?> results = clientServerChannel.onQuery(null, q).firstList();
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
assertNull(o2.getObjectContext());
List<?> children2 = o2.getTable2Array();
assertNotNull(children2);
assertFalse(((ValueHolder) children2).isFault());
assertEquals(0, children2.size());
}
});
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryPrefetchToOne.
@Test
public void testSelectQueryPrefetchToOne() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable2.class, ExpressionFactory.exp("globalAttribute = 'g1'"));
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
ClientMtTable2 result = (ClientMtTable2) results.get(0);
ValueHolder holder = result.getTable1Direct();
assertNotNull(holder);
assertTrue(holder instanceof PersistentObjectHolder);
PersistentObjectHolder objectHolder = (PersistentObjectHolder) holder;
assertFalse(objectHolder.isFault());
ClientMtTable1 target = (ClientMtTable1) objectHolder.getValue();
assertNotNull(target);
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class FlattenedPrefetchIT method testJointManyToMany.
@Test
public void testJointManyToMany() throws Exception {
createPrefetchDataSet1();
SelectQuery q = new SelectQuery(Artist.class);
q.addPrefetch(Artist.GROUP_ARRAY.joint());
final List<Artist> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Artist a : objects) {
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class FlattenedPrefetchIT method testJointMultiPrefetch.
@Test
public void testJointMultiPrefetch() throws Exception {
createPrefetchDataSet2();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.joint());
q.addPrefetch(Painting.TO_ARTIST.dot(Artist.GROUP_ARRAY).joint());
final List<Painting> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Painting p : objects) {
Artist a = p.getToArtist();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class JointPrefetchIT method testJointPrefetchMultiStep.
@Test
public void testJointPrefetchMultiStep() throws Exception {
createJointPrefetchDataSet();
// query with to-many joint prefetches
SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
q.addPrefetch(Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).joint());
final DataContext context = this.context;
// make sure phantomly prefetched objects are not deallocated
context.getObjectStore().objectMap = new HashMap<>();
// sanity check...
DataObject g1 = (DataObject) context.getGraphManager().getNode(new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001));
assertNull(g1);
final List<Artist> objects = q.select(context);
queryInterceptor.runWithQueriesBlocked(() -> {
assertEquals(3, objects.size());
for (Artist a : objects) {
ValueHolder list = (ValueHolder) a.getPaintingArray();
assertNotNull(list);
// intermediate relationship is not fetched...
assertTrue(list.isFault());
}
// however both galleries must be in memory...
DataObject g11 = (DataObject) context.getGraphManager().getNode(new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001));
assertNotNull(g11);
assertEquals(PersistenceState.COMMITTED, g11.getPersistenceState());
DataObject g2 = (DataObject) context.getGraphManager().getNode(new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33002));
assertNotNull(g2);
assertEquals(PersistenceState.COMMITTED, g2.getPersistenceState());
});
}
Aggregations