use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextPrefetchMultistepIT method testToManyToOne_EmptyToMany.
@Test
public void testToManyToOne_EmptyToMany() throws Exception {
createGalleriesAndArtists();
SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, Gallery.GALLERY_NAME.eq("gallery2"));
q.addPrefetch(Gallery.PAINTING_ARRAY.disjoint());
q.addPrefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint());
List<Gallery> galleries = context.select(q);
assertEquals(1, galleries.size());
Gallery g2 = galleries.get(0);
// this relationship should be resolved
assertTrue(g2.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName()) instanceof ValueHolder);
List<Painting> exhibits = (List<Painting>) g2.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName());
assertFalse(((ValueHolder) exhibits).isFault());
assertEquals(0, exhibits.size());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextPrefetchMultistepIT method testToManyToOne_EmptyToMany_NoRootQualifier.
@Test
public void testToManyToOne_EmptyToMany_NoRootQualifier() throws Exception {
createGalleriesAndArtists();
SelectQuery<Gallery> q = SelectQuery.query(Gallery.class);
q.addPrefetch(Gallery.PAINTING_ARRAY.disjoint());
q.addPrefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint());
List<Gallery> galleries = context.select(q);
assertEquals(3, galleries.size());
Gallery g = galleries.get(0);
// this relationship should be resolved
assertTrue(g.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName()) instanceof ValueHolder);
List<Painting> exhibits = (List<Painting>) g.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName());
assertFalse(((ValueHolder) exhibits).isFault());
assertEquals(0, exhibits.size());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextPrefetchMultistepIT method testToManyToManyFirstStepUnresolved.
@Test
public void testToManyToManyFirstStepUnresolved() throws Exception {
createTwoArtistsWithExhibitsDataSet();
// since objects for the phantom prefetches are not retained explicitly, they may
// get garbage collected, and we won't be able to detect them
// so ensure ObjectStore uses a regular map just for this test
context.getObjectStore().objectMap = new HashMap<Object, Persistent>();
// Check the target ArtistExhibit objects do not exist yet
Map<String, Object> id1 = new HashMap<>();
id1.put("ARTIST_ID", 11);
id1.put("EXHIBIT_ID", 2);
ObjectId oid1 = new ObjectId("ArtistExhibit", id1);
Map<String, Object> id2 = new HashMap<>();
id2.put("ARTIST_ID", 101);
id2.put("EXHIBIT_ID", 2);
ObjectId oid2 = new ObjectId("ArtistExhibit", id2);
assertNull(context.getGraphManager().getNode(oid1));
assertNull(context.getGraphManager().getNode(oid2));
Expression e = ExpressionFactory.exp("galleryName = $name");
SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections.singletonMap("name", "gallery2")));
q.addPrefetch("exhibitArray.artistExhibitArray");
List<Gallery> galleries = context.select(q);
assertEquals(1, galleries.size());
Gallery g2 = galleries.get(0);
// this relationship wasn't explicitly prefetched....
Object list = g2.readPropertyDirectly("exhibitArray");
assertTrue(list instanceof Fault);
// however the target objects must be resolved
ArtistExhibit ae1 = (ArtistExhibit) context.getGraphManager().getNode(oid1);
ArtistExhibit ae2 = (ArtistExhibit) context.getGraphManager().getNode(oid2);
assertNotNull(ae1);
assertNotNull(ae2);
assertEquals(PersistenceState.COMMITTED, ae1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, ae2.getPersistenceState());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextPrefetchMultistepIT method testToManyToManyFirstStepResolved.
@Test
public void testToManyToManyFirstStepResolved() throws Exception {
createTwoArtistsWithExhibitsDataSet();
Expression e = ExpressionFactory.exp("galleryName = $name");
SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections.singletonMap("name", "gallery2")));
q.addPrefetch("exhibitArray");
q.addPrefetch("exhibitArray.artistExhibitArray");
List<Gallery> galleries = context.select(q);
assertEquals(1, galleries.size());
Gallery g2 = galleries.get(0);
// this relationship should be resolved
assertTrue(g2.readPropertyDirectly("exhibitArray") instanceof ValueHolder);
List<Exhibit> exhibits = (List<Exhibit>) g2.readPropertyDirectly("exhibitArray");
assertFalse(((ValueHolder) exhibits).isFault());
assertEquals(1, exhibits.size());
Exhibit e1 = exhibits.get(0);
assertEquals(PersistenceState.COMMITTED, e1.getPersistenceState());
// this to-many must also be resolved
assertTrue(e1.readPropertyDirectly("artistExhibitArray") instanceof ValueHolder);
List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1.readPropertyDirectly("artistExhibitArray");
assertFalse(((ValueHolder) aexhibits).isFault());
assertEquals(1, exhibits.size());
ArtistExhibit ae1 = aexhibits.get(0);
assertEquals(PersistenceState.COMMITTED, ae1.getPersistenceState());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataRowUtilsIT method testIsToOneTargetModifiedWithNewTarget.
@Test
public void testIsToOneTargetModifiedWithNewTarget() throws Exception {
createOneArtistAndOnePainting();
// add NEW gallery to painting
List<Painting> paintings = context.performQuery(new SelectQuery(Painting.class));
assertEquals(1, paintings.size());
Painting p1 = paintings.get(0);
ClassDescriptor d = context.getEntityResolver().getClassDescriptor("Painting");
ArcProperty toGallery = (ArcProperty) d.getProperty("toGallery");
ObjectDiff diff = context.getObjectStore().registerDiff(p1.getObjectId(), null);
assertFalse(DataRowUtils.isToOneTargetModified(toGallery, p1, diff));
Gallery g1 = (Gallery) context.newObject("Gallery");
g1.addToPaintingArray(p1);
assertTrue(DataRowUtils.isToOneTargetModified(toGallery, p1, diff));
}
Aggregations