Search in sources :

Example 6 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class TreeDragSource method dragOver.

public void dragOver(DragSourceDragEvent dsde) {
    TreePath sourcePath = sourceTree.getSelectionPath();
    DefaultMutableTreeNode sourceParent = (DefaultMutableTreeNode) sourcePath.getLastPathComponent();
    TreePath path = dt.getPath();
    if (path == null) {
        dsde.getDragSourceContext().setCursor(DragSource.DefaultLinkNoDrop);
        return;
    }
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (sourceParent.getUserObject() instanceof DataMap && parent.getUserObject() instanceof DataNodeDescriptor) {
        dsde.getDragSourceContext().setCursor(DragSource.DefaultLinkDrop);
    } else {
        dsde.getDragSourceContext().setCursor(DragSource.DefaultLinkNoDrop);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 7 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class CreateNodeAction method buildDataNode.

/**
 * A factory method that makes a new DataNode.
 */
DataNodeDescriptor buildDataNode(DataChannelDescriptor dataChannelDescriptor) {
    DataNodeDescriptor node = new DataNodeDescriptor();
    node.setName(NameBuilder.builder(node, dataChannelDescriptor).name());
    node.setDataChannelDescriptor(dataChannelDescriptor);
    return node;
}
Also used : DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Example 8 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class CreateNodeAction method buildDataNode.

/**
 * Creates a new DataNode, adding to the current domain, but doesn't send
 * any events.
 */
public DataNodeDescriptor buildDataNode() {
    ProjectController mediator = getProjectController();
    DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
    DataNodeDescriptor node = buildDataNode(domain);
    DataSourceInfo src = new DataSourceInfo();
    node.setDataSourceDescriptor(src);
    // by default create JDBC Node
    node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
    node.setSchemaUpdateStrategyType(SkipSchemaUpdateStrategy.class.getName());
    return node;
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) XMLPoolingDataSourceFactory(org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory) SkipSchemaUpdateStrategy(org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 9 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class ImportEOModelAction method loadDataNode.

protected void loadDataNode(Map eomodelIndex) {
    // if this is JDBC or JNDI node and connection dictionary is specified, load a
    // DataNode, otherwise ignore it (meaning that pre 5.* EOModels will not have a
    // node).
    String adapter = (String) eomodelIndex.get("adaptorName");
    Map connection = (Map) eomodelIndex.get("connectionDictionary");
    if (adapter != null && connection != null) {
        CreateNodeAction nodeBuilder = (CreateNodeAction) getApplication().getActionManager().getAction(CreateNodeAction.class);
        // this should make created node current, resulting in the new map being added
        // to the node automatically once it is loaded
        DataNodeDescriptor node = nodeBuilder.buildDataNode();
        // configure node...
        if ("JNDI".equalsIgnoreCase(adapter)) {
            node.setDataSourceFactoryType(JNDIDataSourceFactory.class.getName());
            node.setParameters((String) connection.get("serverUrl"));
        } else {
            // guess adapter from plugin or driver
            AdapterMapping adapterDefaults = getApplication().getAdapterMapping();
            String cayenneAdapter = adapterDefaults.adapterForEOFPluginOrDriver((String) connection.get("plugin"), (String) connection.get("driver"));
            if (cayenneAdapter != null) {
                try {
                    Class<DbAdapter> adapterClass = getApplication().getClassLoadingService().loadClass(DbAdapter.class, cayenneAdapter);
                    node.setAdapterType(adapterClass.toString());
                } catch (Throwable ex) {
                // ignore...
                }
            }
            node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
            DataSourceInfo dsi = node.getDataSourceDescriptor();
            dsi.setDataSourceUrl(keyAsString(connection, "URL"));
            dsi.setJdbcDriver(keyAsString(connection, "driver"));
            dsi.setPassword(keyAsString(connection, "password"));
            dsi.setUserName(keyAsString(connection, "username"));
        }
        DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject().getRootNode();
        domain.getNodeDescriptors().add(node);
        // send events after the node creation is complete
        getProjectController().fireDataNodeEvent(new DataNodeEvent(this, node, MapEvent.ADD));
        getProjectController().fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this, (DataChannelDescriptor) getProjectController().getProject().getRootNode(), node));
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) AdapterMapping(org.apache.cayenne.modeler.util.AdapterMapping) JNDIDataSourceFactory(org.apache.cayenne.configuration.server.JNDIDataSourceFactory) DbAdapter(org.apache.cayenne.dba.DbAdapter) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) XMLPoolingDataSourceFactory(org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) Map(java.util.Map) DataMap(org.apache.cayenne.map.DataMap)

Example 10 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class LinkDataMapAction method linkDataMap.

public void linkDataMap(DataMap map, DataNodeDescriptor node) {
    if (map == null) {
        return;
    }
    // no change?
    if (node != null && node.getDataMapNames().contains(map.getName())) {
        return;
    }
    ProjectController mediator = getProjectController();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) mediator.getProject().getRootNode();
    Collection<DataNodeDescriptor> unlinkedNodes = new ArrayList<>();
    // Being paranoid, we will still scan through all.
    for (DataNodeDescriptor nextNode : dataChannelDescriptor.getNodeDescriptors()) {
        if (nextNode.getDataMapNames().contains(map.getName())) {
            nextNode.getDataMapNames().remove(map.getName());
            mediator.fireDataNodeEvent(new DataNodeEvent(this, nextNode));
            unlinkedNodes.add(nextNode);
        }
    }
    // link to a selected node
    if (node != null) {
        node.getDataMapNames().add(map.getName());
        // announce DataNode change
        mediator.fireDataNodeEvent(new DataNodeEvent(this, node));
    }
    application.getUndoManager().addEdit(new LinkDataMapUndoableEdit(map, node, unlinkedNodes, mediator));
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) ArrayList(java.util.ArrayList) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) ProjectController(org.apache.cayenne.modeler.ProjectController) LinkDataMapUndoableEdit(org.apache.cayenne.modeler.undo.LinkDataMapUndoableEdit)

Aggregations

DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)58 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)28 DataMap (org.apache.cayenne.map.DataMap)23 Test (org.junit.Test)22 DbEntity (org.apache.cayenne.map.DbEntity)11 ArrayList (java.util.ArrayList)8 Injector (org.apache.cayenne.di.Injector)8 Constants (org.apache.cayenne.configuration.Constants)7 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)7 DbAdapter (org.apache.cayenne.dba.DbAdapter)7 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)7 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)7 DIBootstrap (org.apache.cayenne.di.DIBootstrap)7 Key (org.apache.cayenne.di.Key)7 Module (org.apache.cayenne.di.Module)7 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)7 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)7 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)7 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)7 ObjEntity (org.apache.cayenne.map.ObjEntity)7