Search in sources :

Example 36 with Artist

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

the class ObjectStoreDiffRetainingIT method testSnapshotRetainedOnRelAndPropertyModification.

@Test
public void testSnapshotRetainedOnRelAndPropertyModification() throws Exception {
    createMixedDataSet();
    Artist a = Cayenne.objectForPK(context, Artist.class, 2000);
    ObjectStore objectStore = context.getObjectStore();
    assertNull(objectStore.getChangesByObjectId().get(a.getObjectId()));
    // we are trying to reproduce the bug CAY-213 - relationship modification puts
    // object in a modified state, so later when object is really modified, its
    // snapshot is not retained... in testing this I am leaving some flexibility for
    // the framework to retain a snapshot when it deems appropriate...
    a.addToPaintingArray(context.newObject(Painting.class));
    a.setArtistName("some other name");
    assertNotNull("Snapshot wasn't retained - CAY-213", objectStore.getChangesByObjectId().get(a.getObjectId()));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 37 with Artist

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

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

the class QueryCacheIT method testLocalCache.

@Test
public void testLocalCache() {
    Artist a = context1.newObject(Artist.class);
    a.setArtistName("artist");
    context1.commitChanges();
    SelectQuery q = new SelectQuery(Artist.class);
    q.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    List<Artist> result1 = context1.performQuery(q);
    List<Artist> result2 = context2.performQuery(q);
    assertNotSame(result1.get(0).getObjectContext(), result2.get(0).getObjectContext());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) Test(org.junit.Test)

Example 39 with Artist

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

the class ExpressionFactoryIT method testCollectionMatch.

// CAY-416
@Test
public void testCollectionMatch() {
    Artist artist = context.newObject(Artist.class);
    artist.setArtistName("artist");
    Painting p1 = context.newObject(Painting.class), p2 = context.newObject(Painting.class), p3 = context.newObject(Painting.class);
    p1.setPaintingTitle("p1");
    p2.setPaintingTitle("p2");
    p3.setPaintingTitle("p3");
    artist.addToPaintingArray(p1);
    artist.addToPaintingArray(p2);
    context.commitChanges();
    assertTrue(ExpressionFactory.matchExp("paintingArray", p1).match(artist));
    assertFalse(ExpressionFactory.matchExp("paintingArray", p3).match(artist));
    // changed to align with SQL
    assertTrue(ExpressionFactory.noMatchExp("paintingArray", p1).match(artist));
    assertTrue(ExpressionFactory.noMatchExp("paintingArray", p3).match(artist));
    assertTrue(ExpressionFactory.matchExp("paintingArray.paintingTitle", "p1").match(artist));
    assertFalse(ExpressionFactory.matchExp("paintingArray.paintingTitle", "p3").match(artist));
    // changed to align with SQL
    assertTrue(ExpressionFactory.noMatchExp("paintingArray.paintingTitle", "p1").match(artist));
    assertTrue(ExpressionFactory.noMatchExp("paintingArray.paintingTitle", "p3").match(artist));
    assertTrue(ExpressionFactory.inExp("paintingTitle", "p1").match(p1));
    assertFalse(ExpressionFactory.notInExp("paintingTitle", "p3").match(p3));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 40 with Artist

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

the class DataContextPrefetchQualifierOverlapIT method testToManyDisjointOverlappingQualifierWithInnerJoin.

@Test
public void testToManyDisjointOverlappingQualifierWithInnerJoin() throws Exception {
    createTwoArtistsThreePaintingsDataSet();
    SelectQuery query = new SelectQuery(Artist.class);
    query.andQualifier(ExpressionFactory.likeExp("paintingArray.paintingTitle", "AB%"));
    query.addPrefetch(Artist.PAINTING_ARRAY.disjoint());
    List<Artist> result = context.performQuery(query);
    assertEquals(1, result.size());
    Artist a = result.get(0);
    assertEquals(3, a.getPaintingArray().size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) Test(org.junit.Test)

Aggregations

Artist (org.apache.cayenne.testdo.testmap.Artist)490 Test (org.junit.Test)481 Painting (org.apache.cayenne.testdo.testmap.Painting)145 SelectQuery (org.apache.cayenne.query.SelectQuery)126 Expression (org.apache.cayenne.exp.Expression)67 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)47 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)39 List (java.util.List)36 ObjectContext (org.apache.cayenne.ObjectContext)30 SQLTemplate (org.apache.cayenne.query.SQLTemplate)26 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)26 DataRow (org.apache.cayenne.DataRow)21 ArrayList (java.util.ArrayList)20 ValueHolder (org.apache.cayenne.ValueHolder)18 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)16 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)15 ObjectId (org.apache.cayenne.ObjectId)14 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)13 Gallery (org.apache.cayenne.testdo.testmap.Gallery)12 ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)12