use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.
the class PostgreDataSource method openConnection.
// //////////////////////////////////////////
// Connections
@Override
protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @Nullable JDBCExecutionContext context, @NotNull String purpose) throws DBCException {
final DBPConnectionConfiguration conConfig = getContainer().getActualConnectionConfiguration();
JDBCRemoteInstance instance = context == null ? null : context.getOwnerInstance();
Connection pgConnection;
if (instance != null) {
log.debug("Initiate connection to " + getServerType().getServerTypeName() + " database [" + instance.getName() + "@" + conConfig.getHostName() + "] for " + purpose);
}
if (instance instanceof PostgreDatabase && instance.getName() != null && !CommonUtils.equalObjects(instance.getName(), conConfig.getDatabaseName())) {
// If database was changed then use new name for connection
final DBPConnectionConfiguration originalConfig = new DBPConnectionConfiguration(conConfig);
try {
// Patch URL with new database name
if (CommonUtils.isEmpty(conConfig.getUrl()) || !CommonUtils.isEmpty(conConfig.getHostName())) {
conConfig.setDatabaseName(instance.getName());
conConfig.setUrl(getContainer().getDriver().getDataSourceProvider().getConnectionURL(getContainer().getDriver(), conConfig));
}
// else {
// String url = conConfig.getUrl();
// }
pgConnection = super.openConnection(monitor, context, purpose);
} finally {
conConfig.setDatabaseName(originalConfig.getDatabaseName());
conConfig.setUrl(originalConfig.getUrl());
}
} else {
pgConnection = super.openConnection(monitor, context, purpose);
}
if (getServerType().supportsClientInfo() && !getContainer().getPreferenceStore().getBoolean(ModelPreferences.META_CLIENT_NAME_DISABLE)) {
// Provide client info. Not supported by Redshift?
try {
pgConnection.setClientInfo(JDBCConstants.APPLICATION_NAME_CLIENT_PROPERTY, DBUtils.getClientApplicationName(getContainer(), context, purpose));
} catch (Throwable e) {
// just ignore
log.debug(e);
}
}
return pgConnection;
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.
the class PostgreDataSource method initializeRemoteInstance.
@Override
protected void initializeRemoteInstance(@NotNull DBRProgressMonitor monitor) throws DBException {
activeDatabaseName = getContainer().getConnectionConfiguration().getBootstrap().getDefaultCatalogName();
if (CommonUtils.isEmpty(activeDatabaseName)) {
activeDatabaseName = getContainer().getConnectionConfiguration().getDatabaseName();
}
if (CommonUtils.isEmpty(activeDatabaseName)) {
activeDatabaseName = PostgreConstants.DEFAULT_DATABASE;
}
databaseCache = new DatabaseCache();
DBPConnectionConfiguration configuration = getContainer().getActualConnectionConfiguration();
final boolean showNDD = CommonUtils.getBoolean(configuration.getProviderProperty(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB), false);
List<PostgreDatabase> dbList = new ArrayList<>();
if (!showNDD) {
PostgreDatabase defDatabase = new PostgreDatabase(monitor, this, activeDatabaseName);
dbList.add(defDatabase);
} else {
loadAvailableDatabases(monitor, configuration, dbList);
}
databaseCache.setCache(dbList);
// Initiate default context
getDefaultInstance().checkInstanceConnection(monitor, false);
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.
the class ConnectionPageWithAuth method loadSettings.
@Override
public void loadSettings() {
super.loadSettings();
DBPDataSourceContainer activeDataSource = getSite().getActiveDataSource();
DBPAuthModelDescriptor selectedAuthModel = null;
DBPConnectionConfiguration configuration = activeDataSource.getConnectionConfiguration();
if (site.isNew() && CommonUtils.isEmpty(configuration.getUserName())) {
configuration.setUserName(activeDataSource.getDriver().getDefaultUser());
}
String dsModelId = configuration.getAuthModelId();
if (dsModelId != null) {
selectedAuthModel = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getAuthModel(dsModelId);
}
authModelSelector.loadSettings(getSite().getActiveDataSource(), selectedAuthModel, getDefaultAuthModelId(activeDataSource));
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.
the class BigQueryConnectionPage method loadSettings.
@Override
public void loadSettings() {
super.loadSettings();
// Load values from new connection info
DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
if (projectText != null) {
String databaseName = connectionInfo.getDatabaseName();
if (CommonUtils.isEmpty(databaseName)) {
// $NON-NLS-1$
databaseName = "";
}
projectText.setText(databaseName);
}
String additionalProjects = connectionInfo.getProperty(BigQueryConstants.DRIVER_PROP_ADDITIONAL_PROJECTS);
if (additionalProjects != null) {
extraProjectsText.setText(additionalProjects);
}
if (usernameText != null) {
usernameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
}
if (authTypeCombo != null) {
authTypeCombo.select(CommonUtils.toInt(connectionInfo.getProperty(BigQueryConstants.DRIVER_PROP_OAUTH_TYPE)));
}
String keyPath = connectionInfo.getProperty(BigQueryConstants.DRIVER_PROP_OAUTH_PVT_KEYPATH);
if (keyPath != null && authCertFile != null) {
authCertFile.setText(keyPath);
}
if (hostText != null) {
if (CommonUtils.isEmpty(connectionInfo.getHostName())) {
hostText.setText(BigQueryConstants.DEFAULT_HOST_NAME);
} else {
hostText.setText(connectionInfo.getHostName());
}
}
if (portText != null) {
if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
portText.setText(String.valueOf(connectionInfo.getHostPort()));
} else if (site.getDriver().getDefaultPort() != null) {
portText.setText(site.getDriver().getDefaultPort());
} else {
// $NON-NLS-1$
portText.setText("");
}
}
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.
the class DB2ConnectionPage method saveSettings.
@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
if (hostText != null) {
connectionInfo.setHostName(hostText.getText().trim());
}
if (portText != null) {
connectionInfo.setHostPort(portText.getText().trim());
}
if (dbText != null) {
connectionInfo.setDatabaseName(dbText.getText().trim());
}
super.saveSettings(dataSource);
}
Aggregations