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;
}
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());
}
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());
}
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"));
}
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());
}
Aggregations