Search in sources :

Example 76 with DataMap

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());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) SQLResult(org.apache.cayenne.map.SQLResult) FrontBaseAdapter(org.apache.cayenne.dba.frontbase.FrontBaseAdapter) OpenBaseAdapter(org.apache.cayenne.dba.openbase.OpenBaseAdapter) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 77 with DataMap

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());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) SQLResult(org.apache.cayenne.map.SQLResult) FrontBaseAdapter(org.apache.cayenne.dba.frontbase.FrontBaseAdapter) OpenBaseAdapter(org.apache.cayenne.dba.openbase.OpenBaseAdapter) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 78 with DataMap

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

Example 79 with DataMap

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

Example 80 with DataMap

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

Aggregations

DataMap (org.apache.cayenne.map.DataMap)233 Test (org.junit.Test)88 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)48 DbEntity (org.apache.cayenne.map.DbEntity)48 ObjEntity (org.apache.cayenne.map.ObjEntity)45 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)22 URL (java.net.URL)21 URLResource (org.apache.cayenne.resource.URLResource)20 ArrayList (java.util.ArrayList)19 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)19 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)17 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)16 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)15 File (java.io.File)14 Procedure (org.apache.cayenne.map.Procedure)14 Embeddable (org.apache.cayenne.map.Embeddable)13 Injector (org.apache.cayenne.di.Injector)12 DbAttribute (org.apache.cayenne.map.DbAttribute)11 EntityResolver (org.apache.cayenne.map.EntityResolver)11 Entity (org.apache.cayenne.map.Entity)10