Search in sources :

Example 6 with DBConnectionInfo

use of org.apache.cayenne.modeler.pref.DBConnectionInfo in project cayenne by apache.

the class DataSourceWizard method setDataSourceKey.

public void setDataSourceKey(String dataSourceKey) {
    this.dataSourceKey = dataSourceKey;
    // update a clone object that will be used to obtain connection...
    DBConnectionInfo currentInfo = dataSources.get(dataSourceKey);
    if (currentInfo != null) {
        currentInfo.copyTo(connectionInfo);
    } else {
        connectionInfo = new DBConnectionInfo();
    }
    view.getConnectionInfo().setConnectionInfo(connectionInfo);
}
Also used : DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Example 7 with DBConnectionInfo

use of org.apache.cayenne.modeler.pref.DBConnectionInfo in project cayenne by apache.

the class DataSourceWizard method refreshDataSources.

@SuppressWarnings("unchecked")
private void refreshDataSources() {
    this.dataSources = (Map<String, DBConnectionInfo>) getApplication().getCayenneProjectPreferences().getDetailObject(DBConnectionInfo.class).getChildrenPreferences();
    // 1.2 migration fix - update data source adapter names
    final String _12package = "org.objectstyle.cayenne.";
    for (DBConnectionInfo info : dataSources.values()) {
        if (info.getDbAdapter() != null && info.getDbAdapter().startsWith(_12package)) {
            info.setDbAdapter("org.apache.cayenne." + info.getDbAdapter().substring(_12package.length()));
        }
    }
    String[] keys = dataSources.keySet().toArray(new String[0]);
    Arrays.sort(keys);
    view.getDataSources().setModel(new DefaultComboBoxModel<>(keys));
    String key = null;
    if (getDataSourceKey() == null || !dataSources.containsKey(getDataSourceKey())) {
        if (keys.length > 0) {
            key = keys[0];
        }
    }
    setDataSourceKey(key != null ? key : getDataSourceKey());
    dataSourceBinding.updateView();
}
Also used : DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Example 8 with DBConnectionInfo

use of org.apache.cayenne.modeler.pref.DBConnectionInfo in project cayenne by apache.

the class DbLoaderContext method buildConfig.

public boolean buildConfig(DataSourceWizard connectionWizard, DbLoaderOptionsDialog dialog) {
    if (dialog == null || connectionWizard == null) {
        return false;
    }
    // Build filters
    ReverseEngineering reverseEngineering = new ReverseEngineering();
    reverseEngineering.addCatalog(new Catalog(dialog.getSelectedCatalog()));
    reverseEngineering.addSchema(new Schema(dialog.getSelectedSchema()));
    reverseEngineering.addIncludeTable(new IncludeTable(dialog.getTableIncludePattern()));
    if (dialog.getTableExcludePattern() != null) {
        reverseEngineering.addExcludeTable(new ExcludeTable(dialog.getTableExcludePattern()));
    }
    // Add here auto_pk_support table
    reverseEngineering.addExcludeTable(new ExcludeTable("auto_pk_support|AUTO_PK_SUPPORT"));
    reverseEngineering.addIncludeProcedure(new IncludeProcedure(dialog.getProcedureNamePattern()));
    FiltersConfigBuilder filtersConfigBuilder = new FiltersConfigBuilder(reverseEngineering);
    DbImportConfiguration config = new DbImportConfiguration() {

        @Override
        public DbLoaderDelegate createLoaderDelegate() {
            return new LoaderDelegate(DbLoaderContext.this);
        }
    };
    // Build config
    DBConnectionInfo connectionInfo = connectionWizard.getConnectionInfo();
    config.setAdapter(connectionWizard.getAdapter().getClass().getName());
    config.setUsername(connectionInfo.getUserName());
    config.setPassword(connectionInfo.getPassword());
    config.setDriver(connectionInfo.getJdbcDriver());
    config.setUrl(connectionInfo.getUrl());
    config.getDbLoaderConfig().setFiltersConfig(filtersConfigBuilder.build());
    config.setMeaningfulPkTables(dialog.getMeaningfulPk());
    config.setNamingStrategy(dialog.getNamingStrategy());
    config.setUsePrimitives(dialog.isUsePrimitives());
    config.setUseJava7Types(dialog.isUseJava7Typed());
    setConfig(config);
    prepareDataMap();
    return true;
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) DbLoaderDelegate(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate) IncludeProcedure(org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) ExcludeTable(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)

Example 9 with DBConnectionInfo

use of org.apache.cayenne.modeler.pref.DBConnectionInfo 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)

Example 10 with DBConnectionInfo

use of org.apache.cayenne.modeler.pref.DBConnectionInfo in project cayenne by apache.

the class DataSourcePreferences method newDataSourceAction.

/**
 * Shows a dialog to create new local DataSource configuration.
 */
public void newDataSourceAction() {
    DataSourceCreator creatorWizard = new DataSourceCreator(this);
    DBConnectionInfo dataSource = creatorWizard.startupAction();
    if (dataSource != null) {
        dataSourcePreferences.create(creatorWizard.getName(), dataSource);
        dataSources = dataSourcePreferences.getChildrenPreferences();
        Object[] keys = dataSources.keySet().toArray();
        Arrays.sort(keys);
        view.getDataSources().setModel(new DefaultComboBoxModel(keys));
        view.getDataSources().setSelectedItem(creatorWizard.getName());
        editDataSourceAction();
        fireEvent(creatorWizard.getName(), MapEvent.ADD);
    }
}
Also used : DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Aggregations

DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)10 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 File (java.io.File)1 Driver (java.sql.Driver)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Preferences (java.util.prefs.Preferences)1 DataSourceInfo (org.apache.cayenne.conn.DataSourceInfo)1 DriverDataSource (org.apache.cayenne.datasource.DriverDataSource)1 Catalog (org.apache.cayenne.dbsync.reverse.dbimport.Catalog)1 DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)1 ExcludeTable (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)1 IncludeProcedure (org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure)1 IncludeTable (org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable)1 ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)1 Schema (org.apache.cayenne.dbsync.reverse.dbimport.Schema)1 DbLoaderDelegate (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate)1