Search in sources :

Example 11 with ArtistExhibit

use of org.apache.cayenne.testdo.testmap.ArtistExhibit in project cayenne by apache.

the class CayenneDataObjectIT method testReadNestedPropertyToManyInMiddle1.

@SuppressWarnings("unchecked")
@Test
public void testReadNestedPropertyToManyInMiddle1() throws Exception {
    Artist a = context.newObject(Artist.class);
    ArtistExhibit ex = context.newObject(ArtistExhibit.class);
    Painting p1 = context.newObject(Painting.class);
    Painting p2 = context.newObject(Painting.class);
    p1.setPaintingTitle("p1");
    p2.setPaintingTitle("p2");
    a.addToPaintingArray(p1);
    a.addToPaintingArray(p2);
    ex.setToArtist(a);
    List<String> names = (List<String>) a.readNestedProperty("paintingArray+.paintingTitle");
    assertEquals(names.size(), 2);
    assertEquals(names.get(0), "p1");
    assertEquals(names.get(1), "p2");
    List<String> names2 = (List<String>) ex.readNestedProperty("toArtist.paintingArray+.paintingTitle");
    assertEquals(names, names2);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) ArrayList(java.util.ArrayList) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 12 with ArtistExhibit

use of org.apache.cayenne.testdo.testmap.ArtistExhibit in project cayenne by apache.

the class DataContextEJBQLFetchJoinIT method testSeveralFetchJoins.

@Test
public void testSeveralFetchJoins() throws Exception {
    createMultipleFetchJoinsDataSet();
    String ejbql = "SELECT a " + "FROM Artist a JOIN FETCH a.paintingArray JOIN FETCH a.artistExhibitArray " + "WHERE a.artistName = 'A1'";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    final List<?> objects = context.performQuery(query);
    queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, objects.size());
            Artist a = (Artist) objects.get(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()));
            }
            List<ArtistExhibit> exibits = a.getArtistExhibitArray();
            assertNotNull(exibits);
            assertFalse(((ValueHolder) exibits).isFault());
            assertEquals(2, exibits.size());
            Iterator<ArtistExhibit> exibitsIterator = exibits.iterator();
            while (exibitsIterator.hasNext()) {
                ArtistExhibit ae = exibitsIterator.next();
                assertEquals(PersistenceState.COMMITTED, ae.getPersistenceState());
                assertNotNull(ae.getObjectId());
            }
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 13 with ArtistExhibit

use of org.apache.cayenne.testdo.testmap.ArtistExhibit in project cayenne by apache.

the class CDOOneDep2OneIT method testNewAdd2.

/**
 * Tests how primary key is propagated from one new object to another.
 */
@Test
public void testNewAdd2() throws Exception {
    Artist a1 = this.newArtist();
    Gallery g1 = context.newObject(Gallery.class);
    g1.setGalleryName(galleryName);
    Exhibit e1 = context.newObject(Exhibit.class);
    e1.setOpeningDate(new Timestamp(System.currentTimeMillis()));
    e1.setClosingDate(new Timestamp(System.currentTimeMillis()));
    e1.setToGallery(g1);
    ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
    ae1.setToArtist(a1);
    ae1.setToExhibit(e1);
    // *** TESTING THIS ***
    context.commitChanges();
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Gallery(org.apache.cayenne.testdo.testmap.Gallery) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) Timestamp(java.sql.Timestamp) Test(org.junit.Test) ByteArrayTypeTest(org.apache.cayenne.access.types.ByteArrayTypeTest)

Aggregations

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