use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextSharedCacheIT method testSnapshotInsertPropagationToManyRefresh.
/**
* Test case to prove that inserting an object in one ObjectStore and committing to
* the database will be reflected in the peer ObjectStore using the same DataRowCache.
* This would mean refreshing to-many collections.
*/
@Test
public void testSnapshotInsertPropagationToManyRefresh() throws Exception {
Painting painting1 = (Painting) context.newObject("Painting");
painting1.setPaintingTitle("p1");
painting1.setToArtist(artist);
context.commitChanges();
// make sure we have a fully resolved copy of an artist and painting
// objects
// in the second context
final Artist altArtist = context1.localObject(artist);
final Painting altPainting1 = context1.localObject(painting1);
assertEquals(artist.getArtistName(), altArtist.getArtistName());
assertEquals(painting1.getPaintingTitle(), altPainting1.getPaintingTitle());
assertEquals(1, altArtist.getPaintingArray().size());
assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, altPainting1.getPersistenceState());
// insert new painting and add to artist
Painting painting2 = (Painting) context.newObject("Painting");
painting2.setPaintingTitle("p2");
painting2.setToArtist(artist);
context.commitChanges();
// check peer artist
// use threaded helper as a barrier, to avoid triggering faults earlier than
// needed
ParallelTestContainer helper = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
Object value = altArtist.readPropertyDirectly("paintingArray");
assertTrue("Unexpected: " + value, value instanceof ToManyList);
assertTrue(((ToManyList) value).isFault());
}
};
helper.runTest(2000);
List<Painting> list = altArtist.getPaintingArray();
assertEquals(2, list.size());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataDomainCallbacksIT method testPostLoad_Prefetch.
@Test
public void testPostLoad_Prefetch() throws Exception {
LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
registry.addCallback(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
MockCallingBackListener listener = new MockCallingBackListener();
registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, listener, "publicCallback");
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XX");
Painting p1 = context.newObject(Painting.class);
p1.setToArtist(a1);
p1.setPaintingTitle("XXX");
context.commitChanges();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.disjoint());
p1 = (Painting) context1.performQuery(q).get(0);
// artist is prefetched here, and a callback must have been invoked
a1 = p1.getToArtist();
assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
assertEquals(1, a1.getPostLoaded());
assertSame(a1, listener.getPublicCalledbackEntity());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataDomainQueryActionIT method testCachedQuery.
@Test
public void testCachedQuery() {
DataDomain domain = runtime.getDataDomain();
Painting p = context.newObject(Painting.class);
p.setPaintingTitle("sample");
SelectQuery query = new SelectQuery(Painting.class);
query.addPrefetch(Painting.TO_GALLERY.disjoint());
query.addPrefetch(Painting.TO_ARTIST.disjoint());
query.addOrdering(Painting.PAINTING_TITLE.asc());
query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
query.setPageSize(5);
QueryCache cache = domain.queryCache;
domain.queryCache = new MockQueryCache() {
@Override
public List<?> get(QueryMetadata metadata, QueryCacheEntryFactory factory) {
Object results = factory.createObject();
assertTrue("Query cache is not serializable.", results instanceof Serializable);
return null;
}
@SuppressWarnings("all")
@Override
public void put(QueryMetadata metadata, List results) {
assertTrue("Query cache is not serializable.", results instanceof Serializable);
}
};
DataDomainQueryAction action = new DataDomainQueryAction(context, domain, query);
action.execute();
domain.queryCache = cache;
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DeleteObjectIT method testDeleteObjectsRelationshipCollection.
@Test
public void testDeleteObjectsRelationshipCollection() throws Exception {
createObjectsRelationshipCollectionDataSet();
Artist artist = Cayenne.objectForPK(context, Artist.class, 1);
List<Painting> paintings = artist.getPaintingArray();
assertEquals(3, paintings.size());
// create a clone to be able to inspect paintings after deletion
List<Painting> paintingsClone = new ArrayList<Painting>(paintings);
for (Painting object : paintingsClone) {
assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
}
context.deleteObjects(paintings);
// as Painting -> Artist has Nullify rule, relationship list has to be
// cleaned up,
// and no exceptions thrown on concurrent modification...
ObjRelationship r = context.getEntityResolver().getObjEntity(Painting.class).getRelationship("toArtist");
assertEquals(DeleteRule.NULLIFY, r.getDeleteRule());
assertEquals(0, paintings.size());
for (Painting object : paintingsClone) {
assertEquals(PersistenceState.DELETED, object.getPersistenceState());
}
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class ProcedureCallIT method testSelect.
@Test
public void testSelect() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
List<?> artists = runProcedureSelect(ProcedureCall.query(SELECT_STORED_PROCEDURE).param("aName", "An Artist").param("paintingPrice", 3000)).firstList();
// check the results
assertNotNull("Null result from StoredProcedure.", artists);
assertEquals(1, artists.size());
DataRow artistRow = (DataRow) artists.get(0);
Artist a = context.objectFromDataRow(Artist.class, uppercaseConverter(artistRow));
Painting p = a.getPaintingArray().get(0);
// invalidate painting, it may have been updated in the proc
context.invalidateObjects(p);
assertEquals(2000, p.getEstimatedPrice().intValue());
}
Aggregations