use of org.jkiss.dbeaver.registry.DataSourceDescriptor in project dbeaver by serge-rider.
the class ConnectionWizard method testConnection.
public void testConnection() {
DataSourceDescriptor dataSource = getPageSettings().getActiveDataSource();
DataSourceDescriptor testDataSource = new DataSourceDescriptor(dataSource);
// Generate new ID to avoid session conflicts in QM
testDataSource.setId(DataSourceDescriptor.generateNewId(dataSource.getDriver()));
try {
saveSettings(testDataSource);
final ConnectionTester op = new ConnectionTester(testDataSource);
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Wait for job to finish
op.ownerMonitor = RuntimeUtils.makeMonitor(monitor);
op.schedule();
while (op.getState() == Job.WAITING || op.getState() == Job.RUNNING) {
if (monitor.isCanceled()) {
op.cancel();
throw new InterruptedException();
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
}
if (op.getConnectError() != null) {
throw new InvocationTargetException(op.getConnectError());
}
if (op.getConnectStatus() == Status.CANCEL_STATUS) {
throw new InterruptedException();
}
}
});
String message = "";
if (!CommonUtils.isEmpty(op.productName)) {
message += "Server: " + op.productName + " " + op.productVersion + "\n";
}
if (!CommonUtils.isEmpty(op.driverName)) {
message += "Driver: " + op.driverName + " " + op.driverVersion + "\n";
}
if (!CommonUtils.isEmpty(message)) {
message += "\n";
}
message += NLS.bind(CoreMessages.dialog_connection_wizard_start_connection_monitor_connected, op.connectTime);
MessageDialog.openInformation(getShell(), CoreMessages.dialog_connection_wizard_start_connection_monitor_success, message);
} catch (InterruptedException ex) {
UIUtils.showErrorDialog(getShell(), CoreMessages.dialog_connection_wizard_start_dialog_interrupted_title, CoreMessages.dialog_connection_wizard_start_dialog_interrupted_message);
} catch (InvocationTargetException ex) {
UIUtils.showErrorDialog(getShell(), CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
}
} finally {
testDataSource.dispose();
}
}
use of org.jkiss.dbeaver.registry.DataSourceDescriptor in project dbeaver by serge-rider.
the class ConnectionWizard method getActiveDataSource.
@NotNull
public DataSourceDescriptor getActiveDataSource() {
DriverDescriptor driver = getSelectedDriver();
DataSourceDescriptor info = infoMap.get(driver);
if (info == null) {
DBPConnectionConfiguration connectionInfo = new DBPConnectionConfiguration();
info = new DataSourceDescriptor(getDataSourceRegistry(), DataSourceDescriptor.generateNewId(getSelectedDriver()), getSelectedDriver(), connectionInfo);
info.getConnectionConfiguration().setClientHomeId(driver.getDefaultClientHomeId());
infoMap.put(driver, info);
}
return info;
}
use of org.jkiss.dbeaver.registry.DataSourceDescriptor in project dbeaver by serge-rider.
the class EditConnectionDialog method createContents.
@Override
protected Control createContents(Composite parent) {
Control contents = super.createContents(parent);
DataSourceDescriptor activeDataSource = getWizard().getActiveDataSource();
getShell().setText("Connection '" + activeDataSource.getName() + "' configuration");
getShell().setImage(DBeaverIcons.getImage(activeDataSource.getObjectImage()));
return contents;
}
use of org.jkiss.dbeaver.registry.DataSourceDescriptor in project dbeaver by serge-rider.
the class EditConnectionWizard method performFinish.
/**
* This method is called when 'Finish' button is pressed in
* the wizard. We will create an operation and run it
* using wizard as execution context.
*/
@Override
public boolean performFinish() {
DataSourceDescriptor dsCopy = new DataSourceDescriptor(originalDataSource);
DataSourceDescriptor dsChanged = new DataSourceDescriptor(dataSource);
saveSettings(dsChanged);
if (dsCopy.equalSettings(dsChanged)) {
// No changes
return true;
}
// Check locked datasources
if (!CommonUtils.isEmpty(dataSource.getLockPasswordHash())) {
if (DBeaverCore.getInstance().getSecureStorage().useSecurePreferences() && !isOnlyUserCredentialChanged(dsCopy, dsChanged)) {
if (!checkLockPassword()) {
return false;
}
}
}
// Save
saveSettings(originalDataSource);
originalDataSource.getRegistry().updateDataSource(originalDataSource);
if (originalDataSource.isConnected()) {
if (UIUtils.confirmAction(getShell(), "Connection changed", "Connection '" + originalDataSource.getName() + "' has been changed.\nDo you want to reconnect?")) {
DataSourceHandler.reconnectDataSource(null, originalDataSource);
}
}
return true;
}
use of org.jkiss.dbeaver.registry.DataSourceDescriptor in project dbeaver by serge-rider.
the class MigrateConnectionWizard method performFinish.
@Override
public boolean performFinish() {
final List<DataSourceDescriptor> connections = pageConnections.getSelectedConnections();
final DriverDescriptor targetDriver = pageDriver.selectedDriver;
for (DataSourceDescriptor conn : connections) {
conn.setDriver(targetDriver);
conn.getRegistry().updateDataSource(conn);
}
return true;
}
Aggregations