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