Search in sources :

Example 71 with DataChannelDescriptor

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;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataDomain(org.apache.cayenne.access.DataDomain) EntitySorter(org.apache.cayenne.map.EntitySorter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) EventManager(org.apache.cayenne.event.EventManager) NestedQueryCache(org.apache.cayenne.cache.NestedQueryCache) DataNode(org.apache.cayenne.access.DataNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataRowStoreFactory(org.apache.cayenne.access.DataRowStoreFactory) DataMap(org.apache.cayenne.map.DataMap)

Example 72 with DataChannelDescriptor

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;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataDomain(org.apache.cayenne.access.DataDomain) DataNode(org.apache.cayenne.access.DataNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 73 with DataChannelDescriptor

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));
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) TableColumn(javax.swing.table.TableColumn) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable)

Example 74 with DataChannelDescriptor

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);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataNodeDefaults(org.apache.cayenne.modeler.pref.DataNodeDefaults) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 75 with DataChannelDescriptor

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);
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) Resource(org.apache.cayenne.resource.Resource) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)100 DataMap (org.apache.cayenne.map.DataMap)50 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)28 Test (org.junit.Test)20 ObjEntity (org.apache.cayenne.map.ObjEntity)18 DbEntity (org.apache.cayenne.map.DbEntity)12 ProjectController (org.apache.cayenne.modeler.ProjectController)12 URL (java.net.URL)11 Embeddable (org.apache.cayenne.map.Embeddable)11 ArrayList (java.util.ArrayList)10 URLResource (org.apache.cayenne.resource.URLResource)10 ObjAttribute (org.apache.cayenne.map.ObjAttribute)8 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)8 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)6 Injector (org.apache.cayenne.di.Injector)6 Procedure (org.apache.cayenne.map.Procedure)6 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)6 Resource (org.apache.cayenne.resource.Resource)6