Search in sources :

Example 6 with Gallery

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();
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) Gallery(org.apache.cayenne.testdo.testmap.Gallery) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) Test(org.junit.Test)

Example 7 with Gallery

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);
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) ValueHolder(org.apache.cayenne.ValueHolder) Painting(org.apache.cayenne.testdo.testmap.Painting) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with Gallery

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())));
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Gallery(org.apache.cayenne.testdo.testmap.Gallery) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Gallery

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);
}
Also used : Gallery(org.apache.cayenne.testdo.testmap.Gallery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 10 with Gallery

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));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Gallery(org.apache.cayenne.testdo.testmap.Gallery) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

Gallery (org.apache.cayenne.testdo.testmap.Gallery)27 Test (org.junit.Test)26 Painting (org.apache.cayenne.testdo.testmap.Painting)13 Artist (org.apache.cayenne.testdo.testmap.Artist)12 List (java.util.List)9 ValueHolder (org.apache.cayenne.ValueHolder)7 ArtistExhibit (org.apache.cayenne.testdo.testmap.ArtistExhibit)7 Exhibit (org.apache.cayenne.testdo.testmap.Exhibit)7 Expression (org.apache.cayenne.exp.Expression)6 SelectQuery (org.apache.cayenne.query.SelectQuery)6 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)4 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)4 ArrayList (java.util.ArrayList)3 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)3 Date (java.util.Date)2 Iterator (java.util.Iterator)2 Fault (org.apache.cayenne.Fault)2 ObjectId (org.apache.cayenne.ObjectId)2 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1