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()));
}
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());
}
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());
}
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));
}
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());
}
Aggregations