use of org.apache.cayenne.access.DataNode in project cayenne by apache.
the class SyntheticNodeDataDomainProvider method createAndInitDataDomain.
@Override
protected DataDomain createAndInitDataDomain() throws Exception {
DataDomain dataDomain = super.createAndInitDataDomain();
// no nodes... add a synthetic node... it will become the default
if (dataDomain.getDataNodes().isEmpty()) {
DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor(createSyntheticDataNodeName(dataDomain));
for (DataMap map : dataDomain.getDataMaps()) {
nodeDescriptor.getDataMapNames().add(map.getName());
}
nodeDescriptor.setDataChannelDescriptor(channelDescriptor);
DataNode node = addDataNode(dataDomain, nodeDescriptor);
dataDomain.setDefaultNode(node);
}
return dataDomain;
}
use of org.apache.cayenne.access.DataNode in project cayenne by apache.
the class CreateTableToDb method execute.
@Override
public void execute(MergerContext mergerContext) {
try {
DataNode node = mergerContext.getDataNode();
DbAdapter adapter = node.getAdapter();
if (needAutoPkSupport()) {
adapter.getPkGenerator().createAutoPk(node, Collections.singletonList(getEntity()));
}
executeSql(mergerContext, adapter.createTable(getEntity()));
} catch (Exception e) {
mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(this, e.getMessage()));
}
}
use of org.apache.cayenne.access.DataNode in project cayenne by apache.
the class TokensToModelExecutionTest method testCreateAndDropColumn.
@Test
public void testCreateAndDropColumn() throws Exception {
DbAttribute attr = dbAttr("attr").build();
DbEntity entity = dbEntity().build();
DataMap dataMap = dataMap().with(entity).build();
assertEquals(1, dataMap.getDbEntityMap().size());
assertTrue(dataMap.getObjEntityMap().isEmpty());
MergerContext context = MergerContext.builder(dataMap).dataNode(new DataNode()).build();
new DefaultMergerTokenFactory().createAddColumnToModel(entity, attr).execute(context);
assertEquals(1, dataMap.getDbEntityMap().size());
assertEquals(1, entity.getAttributes().size());
assertEquals(attr, entity.getAttribute(attr.getName()));
new DefaultMergerTokenFactory().createDropColumnToModel(entity, attr).execute(context);
assertEquals(1, dataMap.getDbEntityMap().size());
assertTrue(entity.getAttributes().isEmpty());
assertTrue(dataMap.getObjEntityMap().isEmpty());
}
Aggregations