Search in sources :

Example 16 with DataRow

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"));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 17 with DataRow

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

Example 18 with DataRow

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"));
    }
}
Also used : QueryResult(org.apache.cayenne.QueryResult) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 19 with DataRow

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

Example 20 with DataRow

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));
}
Also used : DataRow(org.apache.cayenne.DataRow) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Aggregations

DataRow (org.apache.cayenne.DataRow)152 Test (org.junit.Test)113 Artist (org.apache.cayenne.testdo.testmap.Artist)31 ObjectId (org.apache.cayenne.ObjectId)25 DataObject (org.apache.cayenne.DataObject)20 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)20 SQLTemplate (org.apache.cayenne.query.SQLTemplate)18 Date (java.util.Date)14 HashMap (java.util.HashMap)14 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)14 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)12 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Persistent (org.apache.cayenne.Persistent)8 Painting (org.apache.cayenne.testdo.testmap.Painting)8 Connection (java.sql.Connection)6 Calendar (java.util.Calendar)5 Map (java.util.Map)5 QueryResponse (org.apache.cayenne.QueryResponse)5 DataMap (org.apache.cayenne.map.DataMap)5