use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CDOMany2OneIT method testSelectViaMultiRelationship.
@Test
public void testSelectViaMultiRelationship() throws Exception {
createArtistWithPaintingsInGalleryDataSet();
Artist a1 = Cayenne.objectForPK(context, Artist.class, 8);
Gallery g1 = Cayenne.objectForPK(context, Gallery.class, 11);
Expression e = ExpressionFactory.matchExp("paintingArray.toGallery", g1);
SelectQuery q = new SelectQuery("Artist", e);
List<Artist> artists = context.performQuery(q);
assertEquals(1, artists.size());
assertSame(a1, artists.get(0));
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CDOOne2ManyIT method testPropagatePK.
@Test
public void testPropagatePK() throws Exception {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XyBn");
Gallery g1 = context.newObject(Gallery.class);
g1.setGalleryName("Tyu");
Exhibit e1 = context.newObject(Exhibit.class);
e1.setToGallery(g1);
e1.setOpeningDate(new Date());
e1.setClosingDate(new Date());
context.commitChanges();
// *** TESTING THIS ***
ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
e1.addToArtistExhibitArray(ae1);
a1.addToArtistExhibitArray(ae1);
// check before save
assertSame(e1, ae1.getToExhibit());
assertSame(a1, ae1.getToArtist());
// save
// test "assertion" is that commit succeeds (PK of ae1 was set properly)
context.commitChanges();
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextFlattenedAttributesIT method testSelectEJQBQLSubquery.
@Test
public void testSelectEJQBQLSubquery() throws Exception {
createTestDataSet();
EJBQLQuery query = new EJBQLQuery("SELECT g FROM Gallery g WHERE " + "(SELECT COUNT(cp) FROM CompoundPainting cp WHERE g.galleryName=cp.galleryName) = 4");
List<?> objects = context.performQuery(query);
assertNotNull(objects);
assertEquals(1, objects.size());
Gallery gallery = (Gallery) objects.get(0);
assertEquals("gallery2", gallery.getGalleryName());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextJoinAliasesIT method testMatchAll.
@Test
public void testMatchAll() throws Exception {
// select all galleries that have exhibits by both Picasso and Dali...
createMatchAllDataSet();
Artist picasso = Cayenne.objectForPK(context, Artist.class, 1);
Artist dali = Cayenne.objectForPK(context, Artist.class, 2);
SelectQuery query = new SelectQuery(Gallery.class);
query.andQualifier(ExpressionFactory.matchAllExp("|exhibitArray.artistExhibitArray.toArtist", picasso, dali));
List<Gallery> galleries = context.performQuery(query);
assertEquals(1, galleries.size());
assertEquals("G1", galleries.get(0).getGalleryName());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchWithSharedCache.
@Test
public void testPrefetchWithSharedCache() throws Exception {
tArtist.deleteAll();
tGallery.deleteAll();
tPainting.deleteAll();
tArtist.insert(1, "artist1");
tGallery.insert(1, "gallery1");
tPainting.insert(1, "painting1", 1, 100, 1);
final ObjectSelect<Painting> s1 = ObjectSelect.query(Painting.class).sharedCache("g1");
final ObjectSelect<Painting> s2 = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.disjoint()).sharedCache("g1");
final ObjectSelect<Painting> s3 = ObjectSelect.query(Painting.class).prefetch(Painting.TO_GALLERY.joint()).sharedCache("g1");
final ObjectSelect<Painting> s4 = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.disjoint()).prefetch(Painting.TO_GALLERY.joint()).sharedCache("g1");
// first iteration select from DB and cache
List<Painting> paintings = s1.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Fault);
paintings = s2.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Fault);
paintings = s3.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
paintings = s4.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
// select from cache
List<Painting> paintings = s2.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Fault);
paintings = s3.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
paintings = s4.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
}
});
}
Aggregations