use of org.apache.cayenne.query.ProcedureQuery in project cayenne by apache.
the class DataContextProcedureQueryIT method testOutParams.
@Test
public void testOutParams() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
ProcedureQuery q = new ProcedureQuery(OUT_STORED_PROCEDURE);
q.addParameter("in_param", new Integer(20));
List<?> rows = runProcedureSelect(q);
assertEquals(1, rows.size());
Object row = rows.get(0);
assertNotNull(row);
assertTrue("Unexpected row class: " + row.getClass().getName(), row instanceof Map<?, ?>);
Map<?, ?> outParams = (Map<?, ?>) row;
Number price = (Number) outParams.get("out_param");
assertNotNull("Null result... row content: " + row, price);
assertEquals(40, price.intValue());
}
use of org.apache.cayenne.query.ProcedureQuery in project cayenne by apache.
the class DataContextProcedureQueryIT 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);
ProcedureQuery q = new ProcedureQuery(SELECT_STORED_PROCEDURE, Artist.class);
q.addParameter("aName", "An Artist");
List<?> artists = runProcedureSelect(q);
// 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);
}
Aggregations