use of org.apache.cayenne.testdo.testmap.Gallery 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.Gallery in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testSeveralEntitiesAndScalarFetchInnerJoins.
@Test
public void testSeveralEntitiesAndScalarFetchInnerJoins() throws Exception {
createMultipleFetchJoinsDataSet();
String ejbql = "SELECT DISTINCT a, a.artistName , g " + "FROM Artist a JOIN FETCH a.paintingArray, Gallery g JOIN FETCH g.exhibitArray " + "ORDER BY a.artistName";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, objects.size());
Object[] firstRow = (Object[]) objects.get(0);
Artist a = (Artist) firstRow[0];
assertEquals("A1", a.getArtistName());
List<Painting> paintings = a.getPaintingArray();
assertNotNull(paintings);
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(2, paintings.size());
List<String> expectedPaintingsNames = new ArrayList<String>();
expectedPaintingsNames.add("P11");
expectedPaintingsNames.add("P12");
Iterator<Painting> paintingsIterator = paintings.iterator();
while (paintingsIterator.hasNext()) {
Painting p = paintingsIterator.next();
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
}
String artistName = (String) firstRow[1];
assertEquals("A1", artistName);
Gallery g1 = (Gallery) firstRow[2];
assertEquals("gallery1", g1.getGalleryName());
List<Exhibit> exibits = g1.getExhibitArray();
assertNotNull(exibits);
assertFalse(((ValueHolder) exibits).isFault());
assertEquals(2, exibits.size());
Object[] secondRow = (Object[]) objects.get(1);
a = (Artist) secondRow[0];
assertEquals("A2", a.getArtistName());
paintings = a.getPaintingArray();
assertNotNull(paintings);
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(1, paintings.size());
expectedPaintingsNames = new ArrayList<String>();
expectedPaintingsNames.add("P2");
paintingsIterator = paintings.iterator();
while (paintingsIterator.hasNext()) {
Painting p = paintingsIterator.next();
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
}
artistName = (String) secondRow[1];
assertEquals("A2", artistName);
Gallery g2 = (Gallery) secondRow[2];
assertEquals(g1, g2);
}
});
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextEJBQLGroupByHavingIT method testGroupByJoinedEntities.
@Test
public void testGroupByJoinedEntities() throws Exception {
createArtistsPaintingGalleries();
EJBQLQuery query = new EJBQLQuery("SELECT COUNT(p), p.toArtist, p.toGallery FROM Painting p " + "GROUP BY p.toGallery, p.toArtist ");
List<Object[]> data = context.performQuery(query);
assertNotNull(data);
assertEquals(2, data.size());
HashSet<List<?>> expectedResults = new HashSet<List<?>>();
expectedResults.add(Arrays.asList(1L, "AA2", "gallery1"));
expectedResults.add(Arrays.asList(1L, "AA1", "gallery2"));
for (Object[] row : data) {
assertFalse(expectedResults.add(Arrays.asList(row[0], row[1] == null ? null : ((Artist) row[1]).getArtistName(), row[2] == null ? null : ((Gallery) row[2]).getGalleryName())));
}
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CayenneDataObjectRelationshipsIT method testReadToOneRel3.
@Test
public void testReadToOneRel3() throws Exception {
createArtistWithPaintingDataSet();
Painting p1 = Cayenne.objectForPK(context, Painting.class, 6);
Gallery g1 = p1.getToGallery();
assertNull(g1);
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CDOMany2OneIT method testSavedAdd.
@Test
public void testSavedAdd() throws Exception {
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("xa");
assertTrue(context.hasChanges());
// do save
context.commitChanges();
ObjectContext context2 = runtime.newContext();
// test database data
Painting p2 = (Painting) Cayenne.objectForQuery(context2, new SelectQuery(Painting.class));
assertNull(p2.getToGallery());
Gallery g2 = context2.newObject(Gallery.class);
g2.setGalleryName("rE");
p2.setToGallery(g2);
// test before save
assertEquals(1, g2.getPaintingArray().size());
assertSame(p2, g2.getPaintingArray().get(0));
// do save II
context2.commitChanges();
ObjectContext context3 = runtime.newContext();
Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(Painting.class));
Gallery g3 = p3.getToGallery();
assertNotNull(g3);
assertEquals("rE", g3.getGalleryName());
assertEquals(1, g3.getPaintingArray().size());
assertSame(p3, g3.getPaintingArray().get(0));
}
Aggregations