use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class ConfigImportWizard method adaptConnectionUrl.
protected void adaptConnectionUrl(ImportConnectionInfo connectionInfo) throws DBException {
String sampleURL = connectionInfo.getDriverInfo().getSampleURL();
if (connectionInfo.getDriver() != null) {
sampleURL = connectionInfo.getDriver().getSampleURL();
}
// connectionInfo.getDriver()
String url = connectionInfo.getUrl();
if (url != null) {
// Parse url
final JDBCURL.MetaURL metaURL = JDBCURL.parseSampleURL(sampleURL);
int sourceOffset = 0;
List<String> urlComponents = metaURL.getUrlComponents();
for (int i = 0, urlComponentsSize = urlComponents.size(); i < urlComponentsSize; i++) {
String component = urlComponents.get(i);
if (component.length() > 2 && component.charAt(0) == '{' && component.charAt(component.length() - 1) == '}' && metaURL.getAvailableProperties().contains(component.substring(1, component.length() - 1))) {
// Property
int partEnd;
if (i < urlComponentsSize - 1) {
// Find next component
final String nextComponent = urlComponents.get(i + 1);
partEnd = url.indexOf(nextComponent, sourceOffset);
if (partEnd == -1) {
if (nextComponent.equals(":")) {
// Try to find another divider - dbvis sometimes contains bad sample URLs (e.g. for Oracle)
partEnd = url.indexOf("/", sourceOffset);
}
if (partEnd == -1) {
if (connectionInfo.getHost() == null) {
throw new DBException("Can't parse URL '" + url + "' with pattern '" + sampleURL + "'. String '" + nextComponent + "' not found after '" + component);
} else {
// We have connection properties anyway
url = null;
break;
}
}
}
} else {
partEnd = url.length();
}
String propertyValue = url.substring(sourceOffset, partEnd);
switch(component) {
case "{host}":
connectionInfo.setHost(propertyValue);
break;
case "{port}":
connectionInfo.setPort(propertyValue);
break;
case "{database}":
connectionInfo.setDatabase(propertyValue);
break;
default:
if (connectionInfo.getHost() == null) {
throw new DBException("Unsupported property " + component);
}
}
sourceOffset = partEnd;
} else {
// Static string
sourceOffset += component.length();
}
}
}
if (url == null) {
if (connectionInfo.getDriver() == null) {
throw new DBCException("Can't detect target driver for '" + connectionInfo.getAlias() + "'");
}
if (connectionInfo.getHost() == null) {
throw new DBCException("No URL and no host name - can't import connection '" + connectionInfo.getAlias() + "'");
}
// No URL - generate from props
DBPConnectionConfiguration conConfig = new DBPConnectionConfiguration();
conConfig.setHostName(connectionInfo.getHost());
conConfig.setHostPort(connectionInfo.getPort());
conConfig.setDatabaseName(connectionInfo.getDatabase());
url = connectionInfo.getDriver().getDataSourceProvider().getConnectionURL(connectionInfo.getDriver(), conConfig);
connectionInfo.setUrl(url);
}
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class PostgreConnectionPageAdvanced method loadSettings.
@Override
public void loadSettings() {
// Load values from new connection info
DBPPreferenceStore globalPrefs = DBWorkbench.getPlatform().getPreferenceStore();
DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
setTitle(site.getActiveDataSource().getDriver().getName());
showNonDefault.setSelection(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB), globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB)));
showTemplates.setSelection(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_SHOW_TEMPLATES_DB), globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_TEMPLATES_DB)));
showTemplates.setEnabled(showNonDefault.getSelection());
showUnavailable.setSelection(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_SHOW_UNAVAILABLE_DB), globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_UNAVAILABLE_DB)));
showUnavailable.setEnabled(showNonDefault.getSelection());
ddPlainBehaviorCombo.select(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_DD_PLAIN_STRING), globalPrefs.getBoolean(PostgreConstants.PROP_DD_PLAIN_STRING)) ? 0 : 1);
ddTagBehaviorCombo.select(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_DD_TAG_STRING), globalPrefs.getBoolean(PostgreConstants.PROP_DD_TAG_STRING)) ? 0 : 1);
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class ConnectionPageNetworkHandler method setConnectionConfigProfile.
private void setConnectionConfigProfile(String profileName) {
activeProfile = CommonUtils.isEmpty(profileName) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileName);
DBPDataSourceContainer dataSource = site.getActiveDataSource();
DBPConnectionConfiguration cfg = dataSource.getConnectionConfiguration();
String oldProfileId = cfg.getConfigProfileName();
saveSettings(site.getActiveDataSource());
if (activeProfile != null) {
cfg.setConfigProfile(activeProfile);
handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
}
} else {
cfg.setConfigProfile(null);
}
site.firePropertyChange(this, PROP_CONFIG_PROFILE, oldProfileId, activeProfile == null ? null : activeProfile.getProfileName());
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class ConnectionPageNetworkHandler method updateProfileList.
private void updateProfileList() {
DBPConnectionConfiguration cfg = site.getActiveDataSource().getConnectionConfiguration();
String profileId = cfg.getConfigProfileName();
activeProfile = CommonUtils.isEmpty(profileId) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileId);
// Refresh profile list
profileCombo.removeAll();
profileCombo.add("");
for (DBWNetworkProfile profile : site.getProject().getDataSourceRegistry().getNetworkProfiles()) {
profileCombo.add(profile.getProfileName());
if (CommonUtils.equalObjects(profileId, profile.getProfileName())) {
profileCombo.select(profileCombo.getItemCount() - 1);
}
}
// Update settings from profile
if (activeProfile != null) {
}
// Update page controls
handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, site.getActiveDataSource());
}
useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
configurator.loadSettings(handlerConfiguration);
enableHandlerContent();
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.
the class ConnectionPageGeneral method saveSettings.
@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
if (dataSourceDescriptor != null && !activated) {
// No changes anyway
return;
}
final DBPConnectionConfiguration confConfig = dataSource.getConnectionConfiguration();
String name = connectionNameChanged ? connectionNameText.getText() : generateConnectionName(getWizard().getPageSettings());
dataSource.setName(name);
dataSource.setFolder(dataSourceFolder);
if (connectionTypeCombo.getSelectionIndex() >= 0) {
confConfig.setConnectionType(connectionTypeCombo.getItem(connectionTypeCombo.getSelectionIndex()));
}
DataSourceDescriptor dsDescriptor = (DataSourceDescriptor) dataSource;
final String description = descriptionText.getText();
if (description.isEmpty()) {
dsDescriptor.setDescription(null);
} else {
dsDescriptor.setDescription(description);
}
if (this.navigatorSettings == null) {
this.navigatorSettings = new DataSourceNavigatorSettings(getWizard().getSelectedNavigatorSettings());
}
dsDescriptor.setNavigatorSettings(this.navigatorSettings);
dsDescriptor.setConnectionReadOnly(this.readOnlyConnection.getSelection());
dsDescriptor.setModifyPermissions(this.accessRestrictions);
for (FilterInfo filterInfo : filters) {
if (filterInfo.filter != null) {
dataSource.setObjectFilter(filterInfo.type, null, filterInfo.filter);
}
}
}
Aggregations