Search in sources :

Example 11 with Gallery

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

Example 12 with Gallery

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();
}
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) Date(java.util.Date) Test(org.junit.Test)

Example 13 with Gallery

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

Example 14 with Gallery

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

Example 15 with Gallery

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);
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Gallery(org.apache.cayenne.testdo.testmap.Gallery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Fault(org.apache.cayenne.Fault) List(java.util.List) 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