Search in sources :

Example 21 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class SQLTemplateIT method testDataRowReturnAndDirectives.

@Test
public void testDataRowReturnAndDirectives() throws SQLException {
    createArtistDataSet();
    DataMap testDataMap = context.getEntityResolver().getDataMap("testmap");
    SQLTemplate q3 = new SQLTemplate(testDataMap, "SELECT #result('ARTIST_ID' 'java.lang.Long'), #result('ARTIST_NAME' 'java.lang.String') FROM ARTIST", true);
    List<DataRow> result = context.performQuery(q3);
    assertEquals(2, result.size());
    assertTrue(result.get(0) instanceof DataRow);
    assertEquals(2, result.get(0).size());
    assertTrue(result.get(0).get("ARTIST_ID") instanceof Long);
    assertTrue(result.get(0).get("ARTIST_NAME") instanceof String);
}
Also used : DataRow(org.apache.cayenne.DataRow) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 22 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class SQLTemplateIT method testSQLTemplateForDataMap.

@Test
public void testSQLTemplateForDataMap() {
    DataMap testDataMap = context.getEntityResolver().getDataMap("testmap");
    SQLTemplate q1 = new SQLTemplate(testDataMap, "SELECT * FROM ARTIST", true);
    List<DataRow> result = context.performQuery(q1);
    assertEquals(0, result.size());
}
Also used : DataRow(org.apache.cayenne.DataRow) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 23 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class SelectById_RunIT method testDataRowMapPk.

@Test
public void testDataRowMapPk() throws Exception {
    createTwoArtists();
    Map<String, ?> id3 = Collections.singletonMap(Artist.ARTIST_ID_PK_COLUMN, 3);
    DataRow a3 = SelectById.dataRowQuery(Artist.class, id3).selectOne(context);
    assertNotNull(a3);
    assertEquals("artist3", a3.get("ARTIST_NAME"));
    Map<String, ?> id2 = Collections.singletonMap(Artist.ARTIST_ID_PK_COLUMN, 2);
    DataRow a2 = SelectById.dataRowQuery(Artist.class, id2).selectOne(context);
    assertNotNull(a2);
    assertEquals("artist2", a2.get("ARTIST_NAME"));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 24 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class EntityInheritanceTreeTest method testEntityMatchingRow_NoInheritance.

@Test
public void testEntityMatchingRow_NoInheritance() {
    DataMap dataMap = new DataMap("map");
    DbEntity dbEntity = new DbEntity("e1");
    dbEntity.addAttribute(new DbAttribute("x"));
    dataMap.addDbEntity(dbEntity);
    ObjEntity entity = new ObjEntity("E1");
    entity.setDbEntityName(dbEntity.getName());
    dataMap.addObjEntity(entity);
    // no inheritance
    EntityInheritanceTree t1 = new EntityInheritanceTree(entity);
    DataRow row11 = new DataRow(5);
    row11.put("x", 1);
    assertSame(entity, t1.entityMatchingRow(row11));
    entity.setDeclaredQualifier(ExpressionFactory.matchDbExp("x", 2));
    assertNull(t1.entityMatchingRow(row11));
    DataRow row12 = new DataRow(5);
    row12.put("x", 2);
    assertSame(entity, t1.entityMatchingRow(row12));
}
Also used : DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 25 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class StringIdQueryTest method testPerformQuery_SingleEntity.

@Test
public void testPerformQuery_SingleEntity() throws Exception {
    e1Helper.deleteAll();
    e1Helper.insert(3).insert(4);
    StringIdQuery query = new StringIdQuery("E1:3", "E1:4", "E1:5");
    QueryResponse response = runtime.newContext().performGenericQuery(query);
    assertEquals(1, response.size());
    assertEquals(2, response.firstList().size());
    Set<Number> ids = new HashSet<>();
    DataRow r1 = (DataRow) response.firstList().get(0);
    ids.add((Number) r1.get("ID"));
    DataRow r2 = (DataRow) response.firstList().get(1);
    ids.add((Number) r2.get("ID"));
    assertTrue(ids.contains(3L));
    assertTrue(ids.contains(4L));
}
Also used : QueryResponse(org.apache.cayenne.QueryResponse) DataRow(org.apache.cayenne.DataRow) HashSet(java.util.HashSet) 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