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