Search in sources :

Example 1 with AdapterMapping

use of org.apache.cayenne.modeler.util.AdapterMapping in project cayenne by apache.

the class Application method startup.

/**
 * Starts the application.
 */
public void startup() {
    // init subsystems
    initPreferences();
    initClassLoader();
    this.bindingFactory = new BindingFactory();
    this.adapterMapping = new AdapterMapping();
    this.undoManager = new CayenneUndoManager(this);
    this.frameController = new CayenneModelerController(this);
    // open up
    frameController.startupAction();
    // After prefs have been loaded, we can now show the console if needed
    LogConsole.getInstance().showConsoleIfNeeded();
    getFrame().setVisible(true);
}
Also used : AdapterMapping(org.apache.cayenne.modeler.util.AdapterMapping) CayenneUndoManager(org.apache.cayenne.modeler.undo.CayenneUndoManager) BindingFactory(org.apache.cayenne.swing.BindingFactory)

Example 2 with AdapterMapping

use of org.apache.cayenne.modeler.util.AdapterMapping 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 3 with AdapterMapping

use of org.apache.cayenne.modeler.util.AdapterMapping in project cayenne by apache.

the class DataSourceCreator method createDataSource.

protected DBConnectionInfo createDataSource() {
    if (canceled) {
        return null;
    }
    DBConnectionInfo dataSource = (DBConnectionInfo) getApplication().getCayenneProjectPreferences().getDetailObject(DBConnectionInfo.class).create(getName());
    Object adapter = view.getAdapters().getSelectedItem();
    if (NO_ADAPTER.equals(adapter)) {
        adapter = null;
    }
    if (adapter != null) {
        String adapterString = adapter.toString();
        dataSource.setDbAdapter(adapterString);
        // guess adapter defaults...
        AdapterMapping defaultMap = getApplication().getAdapterMapping();
        dataSource.setJdbcDriver(defaultMap.jdbcDriverForAdapter(adapterString));
        dataSource.setUrl(defaultMap.jdbcURLForAdapter(adapterString));
    }
    return dataSource;
}
Also used : AdapterMapping(org.apache.cayenne.modeler.util.AdapterMapping) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Aggregations

AdapterMapping (org.apache.cayenne.modeler.util.AdapterMapping)3 Map (java.util.Map)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)1 JNDIDataSourceFactory (org.apache.cayenne.configuration.server.JNDIDataSourceFactory)1 XMLPoolingDataSourceFactory (org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory)1 DataSourceInfo (org.apache.cayenne.conn.DataSourceInfo)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 DataMap (org.apache.cayenne.map.DataMap)1 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)1 DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)1 CayenneUndoManager (org.apache.cayenne.modeler.undo.CayenneUndoManager)1 BindingFactory (org.apache.cayenne.swing.BindingFactory)1