use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DataDomainProvider method createAndInitDataDomain.
protected DataDomain createAndInitDataDomain() throws Exception {
DataChannelDescriptor descriptor = loadDescriptor();
DataDomain dataDomain = createDataDomain(descriptor.getName());
dataDomain.setMaxIdQualifierSize(runtimeProperties.getInt(Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY, -1));
dataDomain.setQueryCache(new NestedQueryCache(queryCache));
dataDomain.setEntitySorter(injector.getInstance(EntitySorter.class));
dataDomain.setEventManager(injector.getInstance(EventManager.class));
dataDomain.setDataRowStoreFactory(injector.getInstance(DataRowStoreFactory.class));
dataDomain.initWithProperties(descriptor.getProperties());
for (DataMap dataMap : descriptor.getDataMaps()) {
dataDomain.addDataMap(dataMap);
}
dataDomain.getEntityResolver().applyDBLayerDefaults();
dataDomain.getEntityResolver().setValueObjectTypeRegistry(valueObjectTypeRegistry);
for (DataNodeDescriptor nodeDescriptor : descriptor.getNodeDescriptors()) {
addDataNode(dataDomain, nodeDescriptor);
}
// init default node
DataNode defaultNode = null;
if (descriptor.getDefaultNodeName() != null) {
defaultNode = dataDomain.getDataNode(descriptor.getDefaultNodeName());
}
if (defaultNode == null) {
Collection<DataNode> allNodes = dataDomain.getDataNodes();
if (allNodes.size() == 1) {
defaultNode = allNodes.iterator().next();
}
}
if (defaultNode != null) {
logger.info("setting DataNode '" + defaultNode.getName() + "' as default, used by all unlinked DataMaps");
dataDomain.setDefaultNode(defaultNode);
}
for (DataChannelFilter filter : filters) {
dataDomain.addFilter(filter);
}
for (Object listener : listeners) {
dataDomain.addListener(listener);
}
return dataDomain;
}
use of org.apache.cayenne.configuration.DataChannelDescriptor 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.configuration.DataChannelDescriptor in project cayenne by apache.
the class ObjEntityAttributePanel method initComboBoxes.
public void initComboBoxes() {
List<String> embeddableNames = new ArrayList<>();
List<String> typeNames = new ArrayList<>();
for (DataMap dataMap : ((DataChannelDescriptor) mediator.getProject().getRootNode()).getDataMaps()) {
for (Embeddable emb : dataMap.getEmbeddables()) {
embeddableNames.add(emb.getClassName());
}
}
String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
Collections.addAll(typeNames, registeredTypes);
typeNames.addAll(embeddableNames);
TableColumn typeColumn = table.getColumnModel().getColumn(ObjAttributeTableModel.OBJ_ATTRIBUTE_TYPE);
JComboBox javaTypesCombo = Application.getWidgetFactory().createComboBox(typeNames.toArray(), false);
AutoCompletion.enable(javaTypesCombo, false, true);
typeColumn.setCellEditor(Application.getWidgetFactory().createCellEditor(javaTypesCombo));
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class MainDataNodeEditor method setNodeName.
public void setNodeName(String newName) {
if (node == null) {
return;
}
// validate...
if (newName == null) {
throw new ValidationException("Empty DataNode Name");
}
ProjectController parent = (ProjectController) getParent();
DataNodeDefaults oldPref = parent.getDataNodePreferences();
DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) getApplication().getProject().getRootNode();
Collection<DataNodeDescriptor> matchingNode = dataChannelDescriptor.getNodeDescriptors();
Iterator<DataNodeDescriptor> it = matchingNode.iterator();
while (it.hasNext()) {
DataNodeDescriptor node = it.next();
if (node.getName().equals(newName)) {
// there is an entity with the same name
throw new ValidationException("There is another DataNode named '" + newName + "'. Use a different name.");
}
}
// passed validation, set value...
// TODO: fixme....there is a slight chance that domain is different than
// the one
// cached node belongs to
ProjectUtil.setDataNodeName((DataChannelDescriptor) parent.getProject().getRootNode(), node, newName);
oldPref.copyPreferences(newName);
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DbImportProjectSaver method save.
@Override
public void save(Project project) {
DataMap dataMap = (DataMap) project.getRootNode();
if (projectController.getCurrentDataMap() != null) {
projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.REMOVE));
projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.ADD));
} else {
DataChannelDescriptor currentDomain = (DataChannelDescriptor) projectController.getProject().getRootNode();
Resource baseResource = currentDomain.getConfigurationSource();
// a new DataMap, so need to set configuration source for it
if (baseResource != null) {
Resource dataMapResource = baseResource.getRelativeResource(nameMapper.configurationLocation(dataMap));
dataMap.setConfigurationSource(dataMapResource);
}
projectController.addDataMap(Application.getFrame(), dataMap);
}
}
Aggregations