use of org.apache.cayenne.query.SelectQuery 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());
});
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class JointPrefetchIT method testJointPrefetchToOne.
@Test
public void testJointPrefetchToOne() throws Exception {
createJointPrefetchDataSet();
// query with to-many joint prefetches
SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING);
q.addPrefetch(Painting.TO_ARTIST.joint());
final List<Painting> objects = q.select(context);
queryInterceptor.runWithQueriesBlocked(() -> {
assertEquals(3, objects.size());
for (Painting p : objects) {
Artist target = p.getToArtist();
assertNotNull(target);
assertEquals(PersistenceState.COMMITTED, target.getPersistenceState());
}
});
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class JointPrefetchIT method testJointPrefetch_ToOne_FetchLimit.
@Test
public void testJointPrefetch_ToOne_FetchLimit() throws Exception {
createJointPrefetchDataSet();
SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
q.setFetchLimit(2);
q.setFetchOffset(0);
q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING);
q.addPrefetch(Painting.TO_ARTIST.joint());
final List<Painting> objects = q.select(context);
queryInterceptor.runWithQueriesBlocked(() -> {
assertEquals(2, objects.size());
for (Painting p : objects) {
Artist target = p.getToArtist();
assertNotNull(target);
assertEquals(PersistenceState.COMMITTED, target.getPersistenceState());
}
});
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class MiscTypesIT method testByteArray.
@Test
public void testByteArray() {
ArraysEntity test = context.newObject(ArraysEntity.class);
byte[] a = new byte[] { 1, 2, 3 };
test.setByteArray(a);
context.commitChanges();
SelectQuery q = new SelectQuery(ArraysEntity.class);
ArraysEntity testRead = (ArraysEntity) context.performQuery(q).get(0);
assertNotNull(testRead.getByteArray());
assertArraysEqual(a, testRead.getByteArray());
test.setByteArray(null);
context.commitChanges();
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class MiscTypesIT method testByteWrapperArray.
@Test
public void testByteWrapperArray() {
ArraysEntity test = context.newObject(ArraysEntity.class);
Byte[] a = new Byte[] { new Byte((byte) 1), new Byte((byte) 2), new Byte((byte) 3) };
test.setByteWrapperArray(a);
context.commitChanges();
SelectQuery q = new SelectQuery(ArraysEntity.class);
ArraysEntity testRead = (ArraysEntity) context.performQuery(q).get(0);
assertNotNull(testRead.getByteWrapperArray());
assertArraysEqual(a, testRead.getByteWrapperArray());
test.setByteWrapperArray(null);
context.commitChanges();
}
Aggregations