Search in sources :

Example 1 with Gallery

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

the class QualifierTranslatorIT method testExtras.

@Test
public void testExtras() throws Exception {
    ObjectId oid1 = new ObjectId("Gallery", "GALLERY_ID", 1);
    ObjectId oid2 = new ObjectId("Gallery", "GALLERY_ID", 2);
    Gallery g1 = new Gallery();
    Gallery g2 = new Gallery();
    g1.setObjectId(oid1);
    g2.setObjectId(oid2);
    Expression e1 = ExpressionFactory.matchExp("toGallery", g1);
    Expression e2 = e1.orExp(ExpressionFactory.matchExp("toGallery", g2));
    doExpressionTest(Exhibit.class, e2, "(ta.GALLERY_ID = ?) OR (ta.GALLERY_ID = ?)");
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Expression(org.apache.cayenne.exp.Expression) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Test(org.junit.Test)

Example 2 with Gallery

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

the class ObjectStoreIT method testUnregisterThenRegister.

@Test
public void testUnregisterThenRegister() throws Exception {
    // Create a gallery.
    Gallery g = context.newObject(Gallery.class);
    g.setGalleryName("Test Gallery");
    // Create an artist in the same context.
    Artist a = context.newObject(Artist.class);
    a.setArtistName("Test Artist");
    // Create a painting in the same context.
    Painting p = context.newObject(Painting.class);
    p.setPaintingTitle("Test Painting");
    // Set the painting's gallery.
    p.setToGallery(g);
    assertEquals(g, p.getToGallery());
    // Unregister the painting from the context.
    context.unregisterObjects(Collections.singletonList(p));
    // Make sure that even though the painting has been removed from the context's
    // object graph that the reference to the gallery is the same.
    assertEquals(g, p.getToGallery());
    // Now, set the relationship between "p" & "a." Since "p" is not registered with a
    // context, but "a" is, "p" should be auto-registered with the context of "a."
    p.setToArtist(a);
    // Now commit the gallery, artist, & painting.
    context.commitChanges();
    // Check one last time that the painting's gallery is set to what we expect.
    assertEquals(g, p.getToGallery());
    // Now, retrieve the same painting from the DB. Note that the gallery relationship
    // is null even though according to our painting, that should not be the case; a
    // NULL
    // value has been recorded to the DB for the painting's gallery_id field.
    // 
    // The full object graph is not being re-registered during auto-registration
    // with the context.
    Painting newP = (Painting) Cayenne.objectForPK(context, p.getObjectId());
    assertNotNull(newP.getToGallery());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 3 with Gallery

use of org.apache.cayenne.testdo.testmap.Gallery 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());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Test(org.junit.Test)

Example 4 with Gallery

use of org.apache.cayenne.testdo.testmap.Gallery 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());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Test(org.junit.Test)

Example 5 with Gallery

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

the class DataContextDelegateIT method setUp.

@Before
public void setUp() throws Exception {
    // prepare a single gallery record
    Gallery gallery = (Gallery) context.newObject("Gallery");
    gallery.setGalleryName("version1");
    // prepare a single artist record
    Artist artist = (Artist) context.newObject("Artist");
    artist.setArtistName("version1");
    context.commitChanges();
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Before(org.junit.Before)

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