use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class QualifierTranslatorIT method testExtras.
@Test
public void testExtras() throws Exception {
ObjectId oid1 = new ObjectId("Gallery", "GALLERY_ID", 1);
ObjectId oid2 = new ObjectId("Gallery", "GALLERY_ID", 2);
Gallery g1 = new Gallery();
Gallery g2 = new Gallery();
g1.setObjectId(oid1);
g2.setObjectId(oid2);
Expression e1 = ExpressionFactory.matchExp("toGallery", g1);
Expression e2 = e1.orExp(ExpressionFactory.matchExp("toGallery", g2));
doExpressionTest(Exhibit.class, e2, "(ta.GALLERY_ID = ?) OR (ta.GALLERY_ID = ?)");
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class ObjectStoreIT method testUnregisterThenRegister.
@Test
public void testUnregisterThenRegister() throws Exception {
// Create a gallery.
Gallery g = context.newObject(Gallery.class);
g.setGalleryName("Test Gallery");
// Create an artist in the same context.
Artist a = context.newObject(Artist.class);
a.setArtistName("Test Artist");
// Create a painting in the same context.
Painting p = context.newObject(Painting.class);
p.setPaintingTitle("Test Painting");
// Set the painting's gallery.
p.setToGallery(g);
assertEquals(g, p.getToGallery());
// Unregister the painting from the context.
context.unregisterObjects(Collections.singletonList(p));
// Make sure that even though the painting has been removed from the context's
// object graph that the reference to the gallery is the same.
assertEquals(g, p.getToGallery());
// Now, set the relationship between "p" & "a." Since "p" is not registered with a
// context, but "a" is, "p" should be auto-registered with the context of "a."
p.setToArtist(a);
// Now commit the gallery, artist, & painting.
context.commitChanges();
// Check one last time that the painting's gallery is set to what we expect.
assertEquals(g, p.getToGallery());
// Now, retrieve the same painting from the DB. Note that the gallery relationship
// is null even though according to our painting, that should not be the case; a
// NULL
// value has been recorded to the DB for the painting's gallery_id field.
//
// The full object graph is not being re-registered during auto-registration
// with the context.
Painting newP = (Painting) Cayenne.objectForPK(context, p.getObjectId());
assertNotNull(newP.getToGallery());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextPrefetchMultistepIT method testMixedPrefetch2.
@Test
public void testMixedPrefetch2() throws Exception {
createTwoArtistsWithExhibitsDataSet();
Expression e = ExpressionFactory.exp("galleryName = $name");
SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections.singletonMap("name", "gallery2")));
// reverse the order of prefetches compared to the previous test
q.addPrefetch("exhibitArray");
q.addPrefetch("exhibitArray.artistExhibitArray").setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
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(2, aexhibits.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 DataContextPrefetchMultistepIT method testMixedPrefetch1.
@Test
public void testMixedPrefetch1() 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").setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
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(2, aexhibits.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 DataContextDelegateIT method setUp.
@Before
public void setUp() throws Exception {
// prepare a single gallery record
Gallery gallery = (Gallery) context.newObject("Gallery");
gallery.setGalleryName("version1");
// prepare a single artist record
Artist artist = (Artist) context.newObject("Artist");
artist.setArtistName("version1");
context.commitChanges();
}
Aggregations