use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataContextIteratedQueryIT method testPerformIteratedQuery_CommitWithinIterator.
@Test
public void testPerformIteratedQuery_CommitWithinIterator() throws Exception {
createArtistsAndPaintingsDataSet();
assertEquals(7, tPainting.getRowCount());
try (ResultIterator<?> it = context.performIteratedQuery(ObjectSelect.query(Artist.class))) {
while (it.hasNextRow()) {
DataRow row = (DataRow) it.nextRow();
Artist artist = context.objectFromDataRow(Artist.class, row);
Painting painting = context.newObject(Painting.class);
painting.setPaintingTitle("P_" + artist.getArtistName());
painting.setToArtist(artist);
context.commitChanges();
}
}
assertEquals(14, tPainting.getRowCount());
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataContextIteratedQueryIT method testPerformIteratedQuery_resolve.
@Test
public void testPerformIteratedQuery_resolve() throws Exception {
createArtistsAndPaintingsDataSet();
try (ResultIterator<?> it = context.performIteratedQuery(ObjectSelect.query(Artist.class))) {
while (it.hasNextRow()) {
DataRow row = (DataRow) it.nextRow();
// try instantiating an object and fetching its relationships
Artist artist = context.objectFromDataRow(Artist.class, row);
List<Painting> paintings = artist.getPaintingArray();
assertNotNull(paintings);
assertEquals("Expected one painting for artist: " + artist, 1, paintings.size());
}
}
}
use of org.apache.cayenne.DataRow 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.DataRow 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.DataRow 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"));
}
Aggregations