Search in sources :

Example 76 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class PendingTransactionsDialog method loadContexts.

private void loadContexts(boolean showAllContexts) {
    contextTree.removeAll();
    // Load all open context
    for (DBPDataSourceContainer dataSource : DataSourceRegistry.getAllDataSources()) {
        if (!dataSource.isConnected() || dataSource.getDataSource() == null) {
            continue;
        }
        for (DBSInstance instance : dataSource.getDataSource().getAvailableInstances()) {
            DBCExecutionContext[] allContexts = instance.getAllContexts();
            if (ArrayUtils.isEmpty(allContexts)) {
                continue;
            }
            List<DBCExecutionContext> txnContexts = new ArrayList<>();
            for (DBCExecutionContext context : allContexts) {
                if (showAllContexts || QMUtils.isTransactionActive(context, false)) {
                    txnContexts.add(context);
                }
            }
            if (txnContexts.isEmpty()) {
                continue;
            }
            TreeItem dsItem = new TreeItem(contextTree, SWT.NONE);
            dsItem.setText(dataSource.getName());
            dsItem.setImage(DBeaverIcons.getImage(dataSource.getDriver().getIcon()));
            dsItem.setData(dataSource);
            for (DBCExecutionContext context : txnContexts) {
                QMTransactionState txnState = QMUtils.getTransactionState(context);
                TreeItem contextItem = new TreeItem(dsItem, SWT.NONE);
                contextItem.setText(0, context.getContextName());
                String stateString = String.valueOf(txnState.getUpdateCount()) + "/" + String.valueOf(txnState.getExecuteCount());
                contextItem.setText(1, stateString);
                contextItem.setData(context);
            }
            dsItem.setExpanded(true);
        }
    }
    UIUtils.asyncExec(new Runnable() {

        @Override
        public void run() {
            UIUtils.packColumns(contextTree);
        }
    });
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) ArrayList(java.util.ArrayList) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) QMTransactionState(org.jkiss.dbeaver.model.qm.QMTransactionState)

Example 77 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class DataSourceInvalidateHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBCExecutionContext context = getActiveExecutionContext(event, false);
    if (context != null) {
        invalidateDataSource(context.getDataSource());
    } else {
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        if (editor instanceof IDataSourceContainerProviderEx) {
            // Try to set the same container.
            // It should trigger connection instantiation if for some reason it was lost (SQLEditor specific?)
            DBPDataSourceContainer dsContainer = ((IDataSourceContainerProviderEx) editor).getDataSourceContainer();
            if (dsContainer != null) {
                ((IDataSourceContainerProviderEx) editor).setDataSourceContainer(null);
                ((IDataSourceContainerProviderEx) editor).setDataSourceContainer(dsContainer);
            }
        }
    }
    return null;
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) IEditorPart(org.eclipse.ui.IEditorPart) IDataSourceContainerProviderEx(org.jkiss.dbeaver.model.IDataSourceContainerProviderEx) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 78 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class DataSourceToolbarHandler method handleDataSourceEvent.

@Override
public void handleDataSourceEvent(final DBPEvent event) {
    if (workbenchWindow.getWorkbench().isClosing()) {
        return;
    }
    DBPDataSourceContainer currentDataSource = DataSourceToolbarUtils.getCurrentDataSource(workbenchWindow);
    if ((event.getAction() == DBPEvent.Action.OBJECT_UPDATE && event.getObject() == currentDataSource) || (event.getAction() == DBPEvent.Action.OBJECT_SELECT && Boolean.TRUE.equals(event.getEnabled()) && DBUtils.getContainer(event.getObject()) == currentDataSource)) {
        UIUtils.asyncExec(this::updateToolbar);
    }
    // TODO: replace with something smarter
    if (event.getAction() == DBPEvent.Action.OBJECT_UPDATE && event.getEnabled() != null) {
        DataSourcePropertyTester.firePropertyChange(DataSourcePropertyTester.PROP_CONNECTED);
        DataSourcePropertyTester.firePropertyChange(DataSourcePropertyTester.PROP_TRANSACTIONAL);
        UIUtils.asyncExec(() -> {
            if (workbenchWindow instanceof WorkbenchWindow) {
                ((WorkbenchWindow) workbenchWindow).updateActionBars();
            }
        });
    }
}
Also used : WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 79 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class DatabaseDebugConfigurationTab method createConnectionSettingsGroup.

protected void createConnectionSettingsGroup(Composite composite) {
    Group group = UIUtils.createControlGroup(composite, DebugUIMessages.DatabaseTab_connection_group_text, 4, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
    UIUtils.createControlLabel(group, DebugUIMessages.DatabaseTab_datasource_label_text);
    connectionCombo = new SelectDataSourceCombo(group) {

        @Override
        protected void onDataSourceChange(DBPDataSourceContainer dataSource) {
            String driverName = dataSource == null ? "" : dataSource.getDriver().getFullName();
            driverText.setText(driverName);
            setDirty(true);
            loadConnectionDebugTypes();
            updateLaunchConfigurationDialog();
        }
    };
    connectionCombo.addItem(null);
    for (DBPDataSourceContainer ds : DataSourceRegistry.getAllDataSources()) {
        connectionCombo.addItem(ds);
    }
    driverText = UIUtils.createLabelText(group, DebugUIMessages.DatabaseTab_driver_label_text, "", SWT.READ_ONLY);
}
Also used : SelectDataSourceCombo(org.jkiss.dbeaver.ui.controls.SelectDataSourceCombo) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 80 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class DatabaseDebugConfigurationTab method loadConnectionDebugTypes.

private void loadConnectionDebugTypes() {
    for (Control c : typesGroup.getChildren()) {
        c.dispose();
    }
    DBPDataSourceContainer dataSource = connectionCombo.getSelectedItem();
    if (dataSource == null) {
        UIUtils.createInfoLabel(typesGroup, "Select a connection to see available debug types");
    } else {
        List<DebugConfigurationPanelDescriptor> panels = DebugConfigurationPanelRegistry.getInstance().getPanels(dataSource);
        if (CommonUtils.isEmpty(panels)) {
            UIUtils.createInfoLabel(typesGroup, "Driver '" + dataSource.getDriver().getFullName() + "' doesn't support debugging");
        } else {
            for (DebugConfigurationPanelDescriptor panel : panels) {
                Button typeSelector = new Button(typesGroup, SWT.RADIO);
                typeSelector.setText(panel.getName());
                if (!CommonUtils.isEmpty(panel.getDescription())) {
                    typeSelector.setToolTipText(panel.getDescription());
                }
                typeSelector.setData(panel);
                if (panel.isValid()) {
                    typeSelector.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            if (typeSelector.getSelection()) {
                                setDirty(true);
                                setDebugType(connectionCombo.getSelectedItem(), (DebugConfigurationPanelDescriptor) typeSelector.getData());
                                typesGroup.getParent().layout(true, true);
                            }
                        }
                    });
                } else {
                    typeSelector.setEnabled(false);
                }
            }
        }
    }
    setDebugType(dataSource, null);
    typesGroup.getParent().layout(true, true);
}
Also used : DebugConfigurationPanelDescriptor(org.jkiss.dbeaver.debug.ui.internal.DebugConfigurationPanelDescriptor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)230 DBException (org.jkiss.dbeaver.DBException)32 ArrayList (java.util.ArrayList)31 IFile (org.eclipse.core.resources.IFile)30 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)27 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)27 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)22 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)19 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)19 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)18 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)18 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 GridData (org.eclipse.swt.layout.GridData)16 IEditorPart (org.eclipse.ui.IEditorPart)16 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)16 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13