Search in sources :

Example 31 with DataChannelDescriptor

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

the class GenerateCodeAction method performAction.

public void performAction(ActionEvent e) {
    Collection<DataMap> dataMaps;
    DataMap dataMap = getProjectController().getCurrentDataMap();
    if (dataMap != null) {
        dataMaps = new ArrayList<>();
        dataMaps.add(dataMap);
        new CodeGeneratorController(getApplication().getFrameController(), dataMaps).startup();
    } else if (getProjectController().getCurrentDataNode() != null) {
        Collection<String> nodeMaps = getProjectController().getCurrentDataNode().getDataMapNames();
        Project project = getProjectController().getProject();
        dataMaps = ((DataChannelDescriptor) project.getRootNode()).getDataMaps();
        Collection<DataMap> resultMaps = new ArrayList<>();
        for (DataMap map : dataMaps) {
            if (nodeMaps.contains(map.getName())) {
                resultMaps.add(map);
            }
        }
        new CodeGeneratorController(getApplication().getFrameController(), resultMaps).startup();
    } else {
        Project project = getProjectController().getProject();
        dataMaps = ((DataChannelDescriptor) project.getRootNode()).getDataMaps();
        new CodeGeneratorController(getApplication().getFrameController(), dataMaps).startup();
    }
}
Also used : Project(org.apache.cayenne.project.Project) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) CodeGeneratorController(org.apache.cayenne.modeler.dialog.codegen.CodeGeneratorController) Collection(java.util.Collection) DataMap(org.apache.cayenne.map.DataMap)

Example 32 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor 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 33 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor 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)

Example 34 with DataChannelDescriptor

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

the class LinkDataMapsAction method performAction.

@Override
public void performAction(ActionEvent e) {
    ProjectController mediator = getProjectController();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) mediator.getProject().getRootNode();
    Collection<String> linkedDataMaps = new ArrayList<>();
    DataNodeDescriptor dataNodeDescriptor = mediator.getCurrentDataNode();
    for (DataNodeDescriptor dataNodeDesc : dataChannelDescriptor.getNodeDescriptors()) {
        linkedDataMaps.addAll(dataNodeDesc.getDataMapNames());
    }
    for (DataMap dataMap : dataChannelDescriptor.getDataMaps()) {
        if (!linkedDataMaps.contains(dataMap.getName())) {
            dataNodeDescriptor.getDataMapNames().add(dataMap.getName());
            mediator.fireDataNodeEvent(new DataNodeEvent(this, dataNodeDescriptor));
        }
    }
    application.getUndoManager().addEdit(new LinkDataMapsUndoableEdit(dataNodeDescriptor, linkedDataMaps, mediator));
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) ArrayList(java.util.ArrayList) LinkDataMapsUndoableEdit(org.apache.cayenne.modeler.undo.LinkDataMapsUndoableEdit) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) ProjectController(org.apache.cayenne.modeler.ProjectController) DataMap(org.apache.cayenne.map.DataMap)

Example 35 with DataChannelDescriptor

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

the class ObjEntitySyncAction method syncObjEntity.

protected void syncObjEntity() {
    ProjectController mediator = getProjectController();
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity != null && entity.getDbEntity() != null) {
        EntityMergeSupport merger = new EntitySyncController(Application.getInstance().getFrameController(), entity).createMerger();
        if (merger == null) {
            return;
        }
        merger.setNameGenerator(new DbEntitySyncAction.PreserveRelationshipNameGenerator());
        if (merger.synchronizeWithDbEntity(entity)) {
            mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
            mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, entity, entity.getDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
        }
    }
}
Also used : EntityMergeSupport(org.apache.cayenne.dbsync.merge.context.EntityMergeSupport) ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProjectController(org.apache.cayenne.modeler.ProjectController) EntitySyncController(org.apache.cayenne.modeler.dialog.objentity.EntitySyncController)

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