Search in sources :

Example 66 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class SchemaUpdateStrategyBase method tablesMap.

protected Map<String, Boolean> tablesMap() {
    DataMap map = node.getEntityResolver().getDataMap("sus-map");
    Map<String, String> tables = new HashMap<>();
    // add upper/lower case permutations
    for (String name : map.getDbEntityMap().keySet()) {
        tables.put(name.toLowerCase(), name);
        tables.put(name.toUpperCase(), name);
    }
    Map<String, Boolean> presentInDB = new HashMap<>();
    for (String name : map.getDbEntityMap().keySet()) {
        presentInDB.put(name, false);
    }
    String tableLabel = node.getAdapter().tableTypeForTable();
    try (Connection con = node.getDataSource().getConnection()) {
        try (ResultSet rs = con.getMetaData().getTables(null, null, "%", new String[] { tableLabel })) {
            while (rs.next()) {
                String dbName = rs.getString("TABLE_NAME");
                String name = tables.get(dbName);
                if (name != null) {
                    presentInDB.put(name, true);
                }
            }
        }
    } catch (SQLException e) {
        throw new CayenneRuntimeException(e);
    }
    return presentInDB;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataMap(org.apache.cayenne.map.DataMap)

Example 67 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class DefaultDataChannelDescriptorMergerTest method testMerged_DataMaps.

@Test
public void testMerged_DataMaps() {
    DataChannelDescriptor d1 = new DataChannelDescriptor();
    d1.setName("Zx");
    DataMap m11 = new DataMap("A");
    DataMap m12 = new DataMap("B");
    d1.getDataMaps().add(m11);
    d1.getDataMaps().add(m12);
    DataChannelDescriptor d2 = new DataChannelDescriptor();
    d2.setName("Ym");
    DataMap m21 = new DataMap("C");
    DataMap m22 = new DataMap("A");
    d2.getDataMaps().add(m21);
    d2.getDataMaps().add(m22);
    DefaultDataChannelDescriptorMerger merger = new DefaultDataChannelDescriptorMerger();
    DataChannelDescriptor merged = merger.merge(d1, d2);
    assertEquals(3, merged.getDataMaps().size());
    assertSame(m22, merged.getDataMap("A"));
    assertSame(m12, merged.getDataMap("B"));
    assertSame(m21, merged.getDataMap("C"));
}
Also used : DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 68 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class ServerRuntimeBuilderIT method tesConfigFree_WithDBParams.

@Test
public void tesConfigFree_WithDBParams() {
    localRuntime = new ServerRuntimeBuilder(null).addConfig(CayenneProjects.TESTMAP_PROJECT).jdbcDriver(dsi.getJdbcDriver()).url(dsi.getDataSourceUrl()).password(dsi.getPassword()).user(dsi.getUserName()).minConnections(1).maxConnections(2).build();
    DataMap map = localRuntime.getDataDomain().getDataMap("testmap");
    assertNotNull(map);
    DataNode node = localRuntime.getDataDomain().getDefaultNode();
    assertNotNull(node);
    assertEquals(1, node.getDataMaps().size());
    assertSame(map, node.getDataMap("testmap"));
}
Also used : DataNode(org.apache.cayenne.access.DataNode) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 69 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class ServerRuntimeBuilderIT method testNoNodeConfig_WithDataSource.

@Test
public void testNoNodeConfig_WithDataSource() {
    localRuntime = new ServerRuntimeBuilder(null).addConfig(CayenneProjects.TESTMAP_PROJECT).dataSource(dataSource).build();
    DataMap map = localRuntime.getDataDomain().getDataMap("testmap");
    assertNotNull(map);
    DataNode node = localRuntime.getDataDomain().getDefaultNode();
    assertNotNull(node);
    assertEquals(1, node.getDataMaps().size());
    assertSame(map, node.getDataMap("testmap"));
}
Also used : DataNode(org.apache.cayenne.access.DataNode) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 70 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class DbEntityHandlerTest method testLoad.

@Test
public void testLoad() throws Exception {
    final DataMap map = new DataMap();
    assertTrue(map.getDbEntities().isEmpty());
    parse("db-entity", new HandlerFactory() {

        @Override
        public NamespaceAwareNestedTagHandler createHandler(NamespaceAwareNestedTagHandler parent) {
            return new DbEntityHandler(parent, map);
        }
    });
    assertEquals(1, map.getDbEntities().size());
    DbEntity entity = map.getDbEntity("ARTGROUP");
    assertNotNull(entity);
    assertNull(entity.getPrimaryKeyGenerator());
    assertEquals(3, entity.getAttributes().size());
    assertEquals("catalog", entity.getCatalog());
    assertEquals("schema", entity.getSchema());
    assertEquals("name = \"test\"", entity.getQualifier().toString());
    DbAttribute attribute = entity.getAttribute("GROUP_ID");
    assertNotNull(attribute);
    assertTrue(attribute.isMandatory());
    assertTrue(attribute.isPrimaryKey());
    assertTrue(attribute.isGenerated());
    assertEquals(Types.INTEGER, attribute.getType());
    attribute = entity.getAttribute("NAME");
    assertNotNull(attribute);
    assertTrue(attribute.isMandatory());
    assertFalse(attribute.isPrimaryKey());
    assertFalse(attribute.isGenerated());
    assertEquals(100, attribute.getMaxLength());
    assertEquals(Types.VARCHAR, attribute.getType());
    attribute = entity.getAttribute("PARENT_GROUP_ID");
    assertNotNull(attribute);
    assertFalse(attribute.isMandatory());
    assertFalse(attribute.isPrimaryKey());
    assertFalse(attribute.isGenerated());
    assertEquals(10, attribute.getScale());
    assertEquals(Types.BIT, attribute.getType());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) 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