use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DeleteObjectIT method testDeleteHollow.
@Test
public void testDeleteHollow() throws Exception {
createHollowDataSet();
List<Painting> paintings = context.performQuery(new SelectQuery(Painting.class));
Painting p = paintings.get(0);
Artist a = p.getToArtist();
assertEquals(PersistenceState.HOLLOW, a.getPersistenceState());
context.deleteObjects(a);
assertEquals(PersistenceState.DELETED, a.getPersistenceState());
}
use of org.apache.cayenne.testdo.testmap.Painting 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.testdo.testmap.Painting in project cayenne by apache.
the class JointPrefetchIT method testJointPrefetchSQLTemplate.
@Test
public void testJointPrefetchSQLTemplate() throws Exception {
createJointPrefetchDataSet();
// correctly naming columns is the key..
SQLTemplate q = new SQLTemplate(Artist.class, "SELECT distinct " + "#result('ESTIMATED_PRICE' 'BigDecimal' '' 'paintingArray.ESTIMATED_PRICE'), " + "#result('PAINTING_TITLE' 'String' '' 'paintingArray.PAINTING_TITLE'), " + "#result('GALLERY_ID' 'int' '' 'paintingArray.GALLERY_ID'), " + "#result('PAINTING_ID' 'int' '' 'paintingArray.PAINTING_ID'), " + "#result('ARTIST_NAME' 'String'), " + "#result('DATE_OF_BIRTH' 'java.util.Date'), " + "#result('t0.ARTIST_ID' 'int' '' 'ARTIST_ID') " + "FROM ARTIST t0, PAINTING t1 " + "WHERE t0.ARTIST_ID = t1.ARTIST_ID");
q.addPrefetch(Artist.PAINTING_ARRAY.joint());
q.setFetchingDataRows(false);
@SuppressWarnings("unchecked") final List<Artist> objects = (List<Artist>) context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(() -> {
// without OUTER join we will get fewer objects...
assertEquals(2, objects.size());
for (Artist a : objects) {
List<Painting> list = a.getPaintingArray();
assertNotNull(list);
assertFalse(((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (Painting p : list) {
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
// make sure properties are not null..
assertNotNull(p.getPaintingTitle());
}
}
});
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class JointPrefetchIT method testJointPrefetchSQLSelectToMany.
@Test
public void testJointPrefetchSQLSelectToMany() throws Exception {
createJointPrefetchDataSet();
@SuppressWarnings("unchecked") final List<Artist> objects = SQLSelect.query(Artist.class, "SELECT " + "#result('PAINTING_ID' 'int' '' 'paintingArray.PAINTING_ID'), " + "#result('ARTIST_NAME' 'String'), " + "#result('DATE_OF_BIRTH' 'java.util.Date'), " + "#result('t0.ARTIST_ID' 'int' '' 'ARTIST_ID') " + "FROM ARTIST t0, PAINTING t1 " + "WHERE t0.ARTIST_ID = t1.ARTIST_ID").addPrefetch(Artist.PAINTING_ARRAY.joint()).select(context);
queryInterceptor.runWithQueriesBlocked(() -> {
assertNotNull(objects);
assertEquals(2, objects.size());
for (Artist artist : objects) {
List<Painting> paintings = artist.getPaintingArray();
assertTrue(paintings.size() > 0);
for (Painting painting : paintings) {
assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
}
}
});
}
use of org.apache.cayenne.testdo.testmap.Painting 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());
}
});
}
Aggregations