Search in sources :

Example 6 with DataSourceDescriptor

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();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 7 with DataSourceDescriptor

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;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor) NotNull(org.jkiss.code.NotNull)

Example 8 with DataSourceDescriptor

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;
}
Also used : Control(org.eclipse.swt.widgets.Control) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 9 with DataSourceDescriptor

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;
}
Also used : DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 10 with DataSourceDescriptor

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;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)21 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 DBException (org.jkiss.dbeaver.DBException)4 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)4 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)4 IStatus (org.eclipse.core.runtime.IStatus)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Control (org.eclipse.swt.widgets.Control)2 DBPConnectionEventType (org.jkiss.dbeaver.model.connection.DBPConnectionEventType)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)2