use of org.apache.cayenne.testdo.testmap.ArtistExhibit in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchToManyOnJoinTableJoinedPrefetch_ViaProperty.
@Test
public void testPrefetchToManyOnJoinTableJoinedPrefetch_ViaProperty() throws Exception {
createTwoArtistsWithExhibitsDataSet();
SelectQuery<Artist> q = new SelectQuery<Artist>(Artist.class);
q.addPrefetch(Artist.ARTIST_EXHIBIT_ARRAY.joint());
q.addOrdering(Artist.ARTIST_NAME.asc());
final List<Artist> artists = context.select(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, artists.size());
Artist a1 = artists.get(0);
assertEquals("artist2", a1.getArtistName());
List<?> toMany = (List<?>) a1.readPropertyDirectly(Artist.ARTIST_EXHIBIT_ARRAY.getName());
assertNotNull(toMany);
assertFalse(((ValueHolder) toMany).isFault());
assertEquals(2, toMany.size());
ArtistExhibit artistExhibit = (ArtistExhibit) toMany.get(0);
assertEquals(PersistenceState.COMMITTED, artistExhibit.getPersistenceState());
assertSame(a1, artistExhibit.getToArtist());
Artist a2 = artists.get(1);
assertEquals("artist3", a2.getArtistName());
List<?> toMany2 = (List<?>) a2.readPropertyDirectly(Artist.ARTIST_EXHIBIT_ARRAY.getName());
assertNotNull(toMany2);
assertFalse(((ValueHolder) toMany2).isFault());
assertEquals(3, toMany2.size());
ArtistExhibit artistExhibit2 = (ArtistExhibit) toMany2.get(0);
assertEquals(PersistenceState.COMMITTED, artistExhibit2.getPersistenceState());
assertSame(a2, artistExhibit2.getToArtist());
}
});
}
use of org.apache.cayenne.testdo.testmap.ArtistExhibit 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.ArtistExhibit 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.ArtistExhibit in project cayenne by apache.
the class DataContextDeleteRulesIT method testCascadeToMany.
@Test
public void testCascadeToMany() {
// Artist artistExhibitArray
Artist anArtist = (Artist) context.newObject("Artist");
anArtist.setArtistName("A Name");
Exhibit anExhibit = (Exhibit) context.newObject("Exhibit");
anExhibit.setClosingDate(new java.sql.Timestamp(System.currentTimeMillis()));
anExhibit.setOpeningDate(new java.sql.Timestamp(System.currentTimeMillis()));
// Needs a gallery... required for data integrity
Gallery gallery = (Gallery) context.newObject("Gallery");
gallery.setGalleryName("A Name");
anExhibit.setToGallery(gallery);
ArtistExhibit artistExhibit = (ArtistExhibit) context.newObject("ArtistExhibit");
artistExhibit.setToArtist(anArtist);
artistExhibit.setToExhibit(anExhibit);
context.commitChanges();
context.deleteObjects(anArtist);
// Test that the link record was deleted, and removed from the
// relationship
assertEquals(PersistenceState.DELETED, artistExhibit.getPersistenceState());
assertFalse(anArtist.getArtistExhibitArray().contains(artistExhibit));
context.commitChanges();
}
use of org.apache.cayenne.testdo.testmap.ArtistExhibit 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();
}
Aggregations