Search in sources :

Example 1 with Exhibit

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

the class DataContextIT method testCurrentSnapshotWithToOneFault.

/**
 * Testing snapshot with to-one fault. This was a bug CAY-96.
 */
@Test
public void testCurrentSnapshotWithToOneFault() throws Exception {
    createGalleriesAndExhibitsDataSet();
    // Exhibit with Gallery as Fault must still include Gallery
    // Artist and Exhibit (Exhibit has unresolved to-one to gallery as in
    // the
    // CAY-96 bug report)
    ObjectId eId = new ObjectId("Exhibit", Exhibit.EXHIBIT_ID_PK_COLUMN, 2);
    Exhibit e = (Exhibit) context.performQuery(new ObjectIdQuery(eId)).get(0);
    assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
    DataRow snapshot = context.currentSnapshot(e);
    // assert that after taking a snapshot, we have FK in, but the
    // relationship
    // is still a Fault
    assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
    assertEquals(new Integer(33002), snapshot.get("GALLERY_ID"));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) Fault(org.apache.cayenne.Fault) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 2 with Exhibit

use of org.apache.cayenne.testdo.testmap.Exhibit 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 3 with Exhibit

use of org.apache.cayenne.testdo.testmap.Exhibit 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 4 with Exhibit

use of org.apache.cayenne.testdo.testmap.Exhibit 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 5 with Exhibit

use of org.apache.cayenne.testdo.testmap.Exhibit 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)

Aggregations

Exhibit (org.apache.cayenne.testdo.testmap.Exhibit)9 Test (org.junit.Test)9 Gallery (org.apache.cayenne.testdo.testmap.Gallery)7 ArtistExhibit (org.apache.cayenne.testdo.testmap.ArtistExhibit)6 List (java.util.List)3 ValueHolder (org.apache.cayenne.ValueHolder)3 Expression (org.apache.cayenne.exp.Expression)3 Artist (org.apache.cayenne.testdo.testmap.Artist)3 Date (java.util.Date)2 Timestamp (java.sql.Timestamp)1 DataRow (org.apache.cayenne.DataRow)1 Fault (org.apache.cayenne.Fault)1 ObjectId (org.apache.cayenne.ObjectId)1 ByteArrayTypeTest (org.apache.cayenne.access.types.ByteArrayTypeTest)1 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 BeanValidationFailure (org.apache.cayenne.validation.BeanValidationFailure)1 ValidationFailure (org.apache.cayenne.validation.ValidationFailure)1 ValidationResult (org.apache.cayenne.validation.ValidationResult)1