Search in sources :

Example 1 with DataSourceInfo

use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.

the class PasswordEncoderEditor method passwordLocationChangedAction.

public void passwordLocationChangedAction() {
    if (node == null || node.getDataSourceDescriptor() == null)
        return;
    DataSourceInfo dsi = node.getDataSourceDescriptor();
    String selectedItem = (String) view.getPasswordLocation().getSelectedItem();
    if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_CLASSPATH))
        updatePasswordElements(true, true, dsi.getPassword(), "Password Filename:", dsi.getPasswordSourceFilename());
    else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE))
        updatePasswordElements(false, true, null, "Password Executable:", dsi.getPasswordSourceExecutable());
    else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_MODEL))
        updatePasswordElements(true, false, dsi.getPassword(), "Password Source:", dsi.getPasswordSourceModel());
    else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_URL))
        updatePasswordElements(false, true, null, "Password URL:", dsi.getPasswordSourceUrl());
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo)

Example 2 with DataSourceInfo

use of org.apache.cayenne.conn.DataSourceInfo 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 3 with DataSourceInfo

use of org.apache.cayenne.conn.DataSourceInfo 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 4 with DataSourceInfo

use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.

the class ConnectionProperties method buildDataSourceInfo.

/**
 * Creates a DataSourceInfo object from a set of properties.
 */
private DataSourceInfo buildDataSourceInfo(Map<String, String> props) {
    DataSourceInfo dsi = new DataSourceInfo();
    String adapter = props.get(ADAPTER_KEY);
    // try legacy adapter key
    if (adapter == null) {
        adapter = props.get(ADAPTER20_KEY);
    }
    dsi.setAdapterClassName(adapter);
    dsi.setUserName(props.get(USER_NAME_KEY));
    dsi.setPassword(props.get(PASSWORD_KEY));
    dsi.setDataSourceUrl(props.get(URL_KEY));
    dsi.setJdbcDriver(props.get(DRIVER_KEY));
    dsi.setMinConnections(MIN_CONNECTIONS);
    dsi.setMaxConnections(MAX_CONNECTIONS);
    return dsi;
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo)

Example 5 with DataSourceInfo

use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.

the class ServerCaseDataSourceInfoProvider method applyOverrides.

private DataSourceInfo applyOverrides(DataSourceInfo connectionInfo) {
    String adapter = property(ADAPTER_KEY_MAVEN);
    String user = property(USER_NAME_KEY_MAVEN);
    String pass = property(PASSWORD_KEY_MAVEN);
    String url = property(URL_KEY_MAVEN);
    String driver = property(DRIVER_KEY_MAVEN);
    if (connectionInfo == null) {
        // only create a brand new DSI if overrides contains a DB url...
        if (url == null) {
            return null;
        }
        connectionInfo = new DataSourceInfo();
        connectionInfo.setMinConnections(ConnectionProperties.MIN_CONNECTIONS);
        connectionInfo.setMaxConnections(ConnectionProperties.MAX_CONNECTIONS);
    }
    connectionInfo = connectionInfo.cloneInfo();
    if (adapter != null) {
        connectionInfo.setAdapterClassName(adapter);
    }
    if (user != null) {
        connectionInfo.setUserName(user);
    }
    if (pass != null) {
        connectionInfo.setPassword(pass);
    }
    if (url != null) {
        connectionInfo.setDataSourceUrl(url);
    }
    if (driver != null) {
        connectionInfo.setJdbcDriver(driver);
    }
    return connectionInfo;
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo)

Aggregations

DataSourceInfo (org.apache.cayenne.conn.DataSourceInfo)12 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 Driver (java.sql.Driver)2 ConfigurationException (org.apache.cayenne.ConfigurationException)2 XMLPoolingDataSourceFactory (org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory)2 ProjectController (org.apache.cayenne.modeler.ProjectController)2 Test (org.junit.Test)2 Map (java.util.Map)1 SkipSchemaUpdateStrategy (org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy)1 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)1 JNDIDataSourceFactory (org.apache.cayenne.configuration.server.JNDIDataSourceFactory)1 DriverDataSource (org.apache.cayenne.datasource.DriverDataSource)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 DataMap (org.apache.cayenne.map.DataMap)1 CayenneModelerController (org.apache.cayenne.modeler.CayenneModelerController)1 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)1 DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)1 AdapterMapping (org.apache.cayenne.modeler.util.AdapterMapping)1 BuildException (org.apache.tools.ant.BuildException)1