use of org.apache.cayenne.testdo.testmap.Artist 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());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class ProcedureCallIT method testSelectDataObject.
@Test
public void testSelectDataObject() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
if (!accessStackAdapter.canMakeObjectsOutOfProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1101.01);
List<Artist> artists = runProcedureSelect(ProcedureCall.query(SELECT_STORED_PROCEDURE, Artist.class).param("aName", "An Artist")).firstList();
// check the results
assertNotNull("Null result from StoredProcedure.", artists);
assertEquals(1, artists.size());
Artist a = (Artist) artists.get(0);
Painting p = a.getPaintingArray().get(0);
// invalidate painting, it may have been updated in the proc
context.invalidateObjects(p);
assertEquals(1101.01, p.getEstimatedPrice().doubleValue(), 0.02);
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class ProcedureCallIT method testUpdate.
@Test
public void testUpdate() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
runProcedureSelect(ProcedureCall.query(UPDATE_STORED_PROCEDURE).param("paintingPrice", 3000));
// 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.Artist in project cayenne by apache.
the class SelectById_RunIT method testIntPk.
@Test
public void testIntPk() throws Exception {
createTwoArtists();
Artist a3 = SelectById.query(Artist.class, 3).selectOne(context);
assertNotNull(a3);
assertEquals("artist3", a3.getArtistName());
Artist a2 = SelectById.query(Artist.class, 2).selectOne(context);
assertNotNull(a2);
assertEquals("artist2", a2.getArtistName());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class SelectById_RunIT method testLocalCache.
@Test
public void testLocalCache() throws Exception {
createTwoArtists();
final Artist[] a3 = new Artist[1];
assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {
@Override
public void execute() {
a3[0] = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
assertNotNull(a3[0]);
assertEquals("artist3", a3[0].getArtistName());
}
}));
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
Artist a3cached = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
assertSame(a3[0], a3cached);
}
});
context.performGenericQuery(new RefreshQuery("g1"));
assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {
@Override
public void execute() {
SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
}
}));
}
Aggregations