use of org.apache.cayenne.testdo.testmap.Painting 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.Painting 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.Painting in project cayenne by apache.
the class SQLSelectIT method test_SelectOne.
@Test
public void test_SelectOne() throws Exception {
createPaintingsDataSet();
Painting a = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING WHERE PAINTING_TITLE = #bind($a)").params("a", "painting3").columnNameCaps(CapsStrategy.UPPER).selectOne(context);
assertEquals("painting3", a.getPaintingTitle());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SQLSelectIT method test_SelectFirst.
@Test
public void test_SelectFirst() throws Exception {
createPaintingsDataSet();
Painting p = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING ORDER BY PAINTING_TITLE").columnNameCaps(CapsStrategy.UPPER).selectFirst(context);
assertNotNull(p);
assertEquals("painting1", p.getPaintingTitle());
}
use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.
the class SQLSelectIT method test_SelectFirstByContext.
@Test
public void test_SelectFirstByContext() throws Exception {
createPaintingsDataSet();
SQLSelect<Painting> q = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING ORDER BY PAINTING_TITLE").columnNameCaps(CapsStrategy.UPPER);
Painting p = context.selectFirst(q);
assertNotNull(p);
assertEquals("painting1", p.getPaintingTitle());
}
Aggregations