use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextProcedureQueryIT method testUpdateNoParam.
@Test
public void testUpdateNoParam() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
ProcedureQuery q = new ProcedureQuery(UPDATE_STORED_PROCEDURE_NOPARAM);
// since stored procedure commits its stuff, we must use an explicit
// non-committing transaction
BaseTransaction t = new ExternalTransaction(jdbcEventLogger);
BaseTransaction.bindThreadTransaction(t);
try {
context.performGenericQuery(q);
} finally {
BaseTransaction.bindThreadTransaction(null);
t.commit();
}
// check that price have doubled
SelectQuery select = new SelectQuery(Artist.class);
select.addPrefetch("paintingArray");
List<?> artists = context.performQuery(select);
assertEquals(1, artists.size());
Artist a = (Artist) artists.get(0);
Painting p = a.getPaintingArray().get(0);
assertEquals(2000, p.getEstimatedPrice().intValue());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextProcedureQueryIT method testSelect2.
@Test
public void testSelect2() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
ProcedureQuery q = new ProcedureQuery(SELECT_STORED_PROCEDURE);
q.addParameter("aName", "An Artist");
q.addParameter("paintingPrice", new Integer(3000));
List<?> artists = runProcedureSelect(q);
// 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());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextProcedureQueryIT method testSelect3.
@Test
public void testSelect3() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
// test ProcedureQuery with Procedure as root
Procedure proc = context.getEntityResolver().getProcedure(SELECT_STORED_PROCEDURE);
ProcedureQuery q = new ProcedureQuery(proc);
q.addParameter("aName", "An Artist");
q.addParameter("paintingPrice", new Integer(3000));
List<?> artists = runProcedureSelect(q);
// 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());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRefreshQueryIT method testRefreshQueryResultsLocalCache.
@Test
public void testRefreshQueryResultsLocalCache() throws Exception {
createRefreshCollectionDataSet();
Expression qual = Painting.PAINTING_TITLE.eq("P2");
SelectQuery<Painting> q = new SelectQuery<>(Painting.class, qual);
q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING);
q.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
q.setCacheGroup("X");
List<?> paints = context.performQuery(q);
// fetch P1 separately from cached query
Painting p1 = Cayenne.objectForPK(context, Painting.class, 33001);
Painting p2 = (Painting) paints.get(0);
Artist a1 = p2.getToArtist();
assertSame(a1, p1.getToArtist());
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p1.getObjectId()));
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p2.getObjectId()));
createRefreshCollectionToOneUpdateDataSet();
RefreshQuery refresh = new RefreshQuery(q);
context.performQuery(refresh);
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p1.getObjectId()));
// probably refreshed eagerly
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p2.getObjectId()));
assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, p2.getPersistenceState());
assertSame(a1, p1.getToArtist());
assertNotSame(a1, p2.getToArtist());
assertEquals("c", p1.getToArtist().getArtistName());
assertEquals("b", p2.getToArtist().getArtistName());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class DataContextRefreshQueryIT method testRefreshQueryResultGroupLocal.
@Test
public void testRefreshQueryResultGroupLocal() throws Exception {
createRefreshCollectionDataSet();
Expression qual = Painting.PAINTING_TITLE.eq("P2");
SelectQuery<Painting> q = new SelectQuery<>(Painting.class, qual);
q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING);
q.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
q.setCacheGroup("X");
List<?> paints = context.performQuery(q);
// fetch P1 separately from cached query
Painting p1 = Cayenne.objectForPK(context, Painting.class, 33001);
Painting p2 = (Painting) paints.get(0);
Artist a1 = p2.getToArtist();
assertSame(a1, p1.getToArtist());
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p1.getObjectId()));
assertNotNull(context.getParentDataDomain().getSharedSnapshotCache().getCachedSnapshot(p2.getObjectId()));
createRefreshCollectionToOneUpdateDataSet();
// results are served from cache and therefore are not refreshed
context.performQuery(q);
assertSame(a1, p1.getToArtist());
assertSame(a1, p2.getToArtist());
assertEquals("c", p1.getToArtist().getArtistName());
assertEquals("c", p2.getToArtist().getArtistName());
RefreshQuery refresh = new RefreshQuery("X");
// this should invalidate results for the next query run
context.performQuery(refresh);
// this should force a refresh
context.performQuery(q);
assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, p2.getPersistenceState());
assertSame(a1, p1.getToArtist());
assertNotSame(a1, p2.getToArtist());
assertEquals("c", p1.getToArtist().getArtistName());
assertEquals("b", p2.getToArtist().getArtistName());
}
Aggregations