use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DataContextSQLTemplateIT method testColumnNamesCapitalization.
@Test
public void testColumnNamesCapitalization() throws Exception {
createFourArtistsAndThreePaintingsDataSet();
String template = "SELECT * FROM ARTIST ORDER BY ARTIST_ID";
SQLTemplate query = new SQLTemplate(Artist.class, template);
query.setColumnNamesCapitalization(CapsStrategy.LOWER);
query.setFetchingDataRows(true);
List<DataRow> rows = context.performQuery(query);
DataRow row1 = rows.get(0);
assertFalse(row1.containsKey("ARTIST_ID"));
assertTrue(row1.containsKey("artist_id"));
DataRow row2 = rows.get(1);
assertFalse(row2.containsKey("ARTIST_ID"));
assertTrue(row2.containsKey("artist_id"));
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
List<DataRow> rowsUpper = context.performQuery(query);
DataRow row3 = rowsUpper.get(0);
assertFalse(row3.containsKey("artist_id"));
assertTrue(row3.containsKey("ARTIST_ID"));
DataRow row4 = rowsUpper.get(1);
assertFalse(row4.containsKey("artist_id"));
assertTrue(row4.containsKey("ARTIST_ID"));
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class EJBQLQueryIT method testDataRows.
@Test
public void testDataRows() throws Exception {
// insertValue();
createArtistsDataSet();
String ejbql = "select a FROM Artist a";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setFetchingDataRows(true);
List<?> artists = context.performQuery(query);
DataRow row = (DataRow) artists.get(0);
String artistName = (String) row.get("ARTIST_NAME");
Artist artist = (Artist) context.objectFromDataRow("Artist", row);
assertEquals(artistName, artist.getArtistName());
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class SQLExecIT method test_ExecuteSelect.
@Test
public void test_ExecuteSelect() throws Exception {
int inserted = SQLExec.query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES (1, 'a')").update(context);
assertEquals(1, inserted);
QueryResult result = SQLExec.query("SELECT * FROM ARTIST").execute(context);
assertEquals(2, result.size());
assertTrue(result.isList());
assertEquals(1, result.firstList().size());
DataRow row = (DataRow) result.firstList().get(0);
if (unitDbAdapter.isLowerCaseNames()) {
assertTrue(row.containsKey("artist_id"));
assertEquals(1L, ((Number) row.get("artist_id")).longValue());
assertEquals("a", row.get("artist_name"));
} else {
assertTrue(row.containsKey("ARTIST_ID"));
assertEquals(1L, ((Number) row.get("ARTIST_ID")).longValue());
assertEquals("a", row.get("ARTIST_NAME"));
}
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class ObjectSelect_RunIT method test_SelectDataRows.
@Test
public void test_SelectDataRows() {
List<DataRow> result = ObjectSelect.dataRowQuery(Artist.class).select(context);
assertEquals(20, result.size());
assertThat(result.get(0), instanceOf(DataRow.class));
DataRow a = ObjectSelect.dataRowQuery(Artist.class).where(Artist.ARTIST_NAME.eq("artist14")).selectOne(context);
assertNotNull(a);
assertEquals("artist14", a.get("ARTIST_NAME"));
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class SQLTemplateIT method testDataRowWithTypes.
@Test
public void testDataRowWithTypes() throws SQLException {
createArtistDataSet();
DataMap testDataMap = context.getEntityResolver().getDataMap("testmap");
SQLTemplate q3 = new SQLTemplate(testDataMap, "SELECT ARTIST_ID, ARTIST_NAME FROM ARTIST", true);
q3.setResultColumnsTypes(Double.class, String.class);
q3.setColumnNamesCapitalization(CapsStrategy.UPPER);
List<DataRow> artists = context.performQuery(q3);
assertEquals(2, artists.size());
assertTrue(artists.get(0) instanceof DataRow);
assertThat(artists.get(0).get("ARTIST_ID"), instanceOf(Double.class));
}
Aggregations