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);
}
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();
}
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;
}
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;
}
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);
}
}
Aggregations