Search in sources :

Example 1 with ProcedureQuery

use of org.apache.cayenne.query.ProcedureQuery in project cayenne by apache.

the class ProcedureQueryDescriptor method buildQuery.

@Override
public ProcedureQuery buildQuery() {
    ProcedureQuery procedureQuery = new ProcedureQuery();
    if (root != null) {
        procedureQuery.setRoot(root);
    }
    procedureQuery.setResultEntityName(this.getResultEntityName());
    procedureQuery.initWithProperties(this.getProperties());
    return procedureQuery;
}
Also used : ProcedureQuery(org.apache.cayenne.query.ProcedureQuery)

Example 2 with ProcedureQuery

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

Example 3 with ProcedureQuery

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

Example 4 with ProcedureQuery

use of org.apache.cayenne.query.ProcedureQuery in project cayenne by apache.

the class DataContextProcedureQueryIT method testColumnNameCapitalization.

@Test
public void testColumnNameCapitalization() 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.setColumnNamesCapitalization(CapsStrategy.LOWER);
    q.addParameter("aName", "An Artist");
    List<DataRow> artists = runProcedureSelect(q);
    ProcedureQuery q1 = new ProcedureQuery(SELECT_STORED_PROCEDURE);
    q1.setColumnNamesCapitalization(CapsStrategy.UPPER);
    q1.addParameter("aName", "An Artist");
    List<DataRow> artists1 = runProcedureSelect(q1);
    assertTrue(artists.get(0).containsKey("date_of_birth"));
    assertFalse(artists.get(0).containsKey("DATE_OF_BIRTH"));
    assertFalse(artists1.get(0).containsKey("date_of_birth"));
    assertTrue(artists1.get(0).containsKey("DATE_OF_BIRTH"));
}
Also used : DataRow(org.apache.cayenne.DataRow) ProcedureQuery(org.apache.cayenne.query.ProcedureQuery) Test(org.junit.Test)

Example 5 with ProcedureQuery

use of org.apache.cayenne.query.ProcedureQuery in project cayenne by apache.

the class DataContextProcedureQueryIT method testFetchOffset.

@Test
public void testFetchOffset() throws Exception {
    if (!accessStackAdapter.supportsStoredProcedures()) {
        return;
    }
    // create an artist with painting in the database
    createArtist(1000.0);
    createArtist(2000.0);
    createArtist(3000.0);
    ProcedureQuery q = new ProcedureQuery(SELECT_STORED_PROCEDURE);
    q.addParameter("aName", "An Artist");
    q.addParameter("paintingPrice", new Integer(3000));
    q.setFetchOffset(2);
    List<?> artists = runProcedureSelect(q);
    assertEquals(1, artists.size());
}
Also used : ProcedureQuery(org.apache.cayenne.query.ProcedureQuery) 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