use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataContextSQLTemplateIT method testSQLResultSetMappingScalarArray.
@Test
public void testSQLResultSetMappingScalarArray() throws Exception {
createFourArtists();
String sql = "SELECT count(1) AS X, 77 AS Y FROM ARTIST";
DataMap map = context.getEntityResolver().getDataMap("testmap");
SQLTemplate query = new SQLTemplate(map, sql, false);
query.setTemplate(FrontBaseAdapter.class.getName(), "SELECT COUNT(ARTIST_ID) X, 77 Y FROM ARTIST GROUP BY Y");
query.setTemplate(OpenBaseAdapter.class.getName(), "SELECT COUNT(ARTIST_ID) X, 77 Y FROM ARTIST GROUP BY 77");
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
SQLResult rsMap = new SQLResult();
rsMap.addColumnResult("X");
rsMap.addColumnResult("Y");
query.setResult(rsMap);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Object o = objects.get(0);
assertTrue(o instanceof Object[]);
Object[] row = (Object[]) o;
assertEquals(2, row.length);
assertEquals(4, ((Number) row[0]).intValue());
assertEquals(77, ((Number) row[1]).intValue());
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataContextSQLTemplateIT method testSQLResultSetMappingScalar.
@Test
public void testSQLResultSetMappingScalar() throws Exception {
createFourArtists();
String sql = "SELECT count(1) AS X FROM ARTIST";
DataMap map = context.getEntityResolver().getDataMap("testmap");
SQLTemplate query = new SQLTemplate(map, sql, false);
query.setTemplate(FrontBaseAdapter.class.getName(), "SELECT COUNT(ARTIST_ID) X FROM ARTIST");
query.setTemplate(OpenBaseAdapter.class.getName(), "SELECT COUNT(ARTIST_ID) X FROM ARTIST");
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
SQLResult rsMap = new SQLResult();
rsMap.addColumnResult("X");
query.setResult(rsMap);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Object o = objects.get(0);
assertTrue("Expected Number: " + o, o instanceof Number);
assertEquals(4, ((Number) o).intValue());
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataDomainIT method testEntityResolverRefresh.
@Test
public void testEntityResolverRefresh() throws Exception {
DataDomain domain = new DataDomain("dom1");
org.apache.cayenne.map.EntityResolver resolver = domain.getEntityResolver();
assertNotNull(resolver);
DataMap map = new DataMap("map");
ObjEntity entity = new ObjEntity("TestEntity");
map.addObjEntity(entity);
domain.addDataMap(map);
assertSame(entity, resolver.getObjEntity("TestEntity"));
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataDomainIT method testLookupDataNode.
@Test
public void testLookupDataNode() {
DataDomain domain = new DataDomain("test");
DataMap m1 = new DataMap("m1");
DataNode n1 = new DataNode("n1");
n1.addDataMap(m1);
domain.addNode(n1);
DataMap m2 = new DataMap("m2");
DataNode n2 = new DataNode("n2");
n2.addDataMap(m2);
domain.addNode(n2);
assertSame(n1, domain.lookupDataNode(m1));
assertSame(n2, domain.lookupDataNode(m2));
try {
domain.lookupDataNode(new DataMap("m3"));
fail("must have thrown on missing Map to Node maping");
} catch (CayenneRuntimeException e) {
// expected
}
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataDomainIT method testLookupDataNode_Default.
@Test
public void testLookupDataNode_Default() {
DataDomain domain = new DataDomain("test");
DataMap m1 = new DataMap("m1");
DataNode n1 = new DataNode("n1");
n1.addDataMap(m1);
domain.setDefaultNode(n1);
DataMap m2 = new DataMap("m2");
DataNode n2 = new DataNode("n2");
n2.addDataMap(m2);
domain.addNode(n2);
assertSame(n1, domain.lookupDataNode(m1));
assertSame(n2, domain.lookupDataNode(m2));
// must map to default
assertSame(n1, domain.lookupDataNode(new DataMap("m3")));
}
Aggregations