Search in sources :

Example 11 with ProcedureQuery

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());
}
Also used : Map(java.util.Map) ProcedureQuery(org.apache.cayenne.query.ProcedureQuery) Test(org.junit.Test)

Example 12 with ProcedureQuery

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);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ProcedureQuery(org.apache.cayenne.query.ProcedureQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

ProcedureQuery (org.apache.cayenne.query.ProcedureQuery)12 Test (org.junit.Test)11 Artist (org.apache.cayenne.testdo.testmap.Artist)6 Painting (org.apache.cayenne.testdo.testmap.Painting)6 DataRow (org.apache.cayenne.DataRow)5 Procedure (org.apache.cayenne.map.Procedure)2 BaseTransaction (org.apache.cayenne.tx.BaseTransaction)2 ExternalTransaction (org.apache.cayenne.tx.ExternalTransaction)2 Map (java.util.Map)1 ColumnDescriptor (org.apache.cayenne.access.jdbc.ColumnDescriptor)1