Search in sources :

Example 46 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class DataSourceTransactionLogHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    DBCExecutionContext context = null;
    if (editor instanceof DBPContextProvider) {
        context = ((DBPContextProvider) editor).getExecutionContext();
    }
    TransactionLogDialog.showDialog(activeShell, context);
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IEditorPart(org.eclipse.ui.IEditorPart)

Example 47 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class PendingTransactionsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    contextTree = new Tree(composite, SWT.FULL_SELECTION | SWT.BORDER);
    contextTree.setHeaderVisible(true);
    contextTree.setLinesVisible(true);
    TreeColumn colName = new TreeColumn(contextTree, SWT.NONE);
    colName.setText("Connection");
    TreeColumn colTxn = new TreeColumn(contextTree, SWT.RIGHT);
    colTxn.setText("Transaction");
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = contextTree.getHeaderHeight() + contextTree.getItemHeight() * 5;
    contextTree.setLayoutData(gd);
    contextTree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.item != null && e.item.getData() instanceof DBCExecutionContext) {
                selectedContext = (DBCExecutionContext) e.item.getData();
            } else {
                selectedContext = null;
            }
            boolean hasTransaction = selectedContext != null && QMUtils.isTransactionActive(selectedContext, false);
            commitButton.setEnabled(hasTransaction);
            rollbackButton.setEnabled(hasTransaction);
            logViewer.setFilter(createContextFilter(selectedContext));
            logViewer.refresh();
        }
    });
    closeOnFocusLost(contextTree);
    {
        Composite controlPanel = UIUtils.createPlaceholder(composite, 3, 5);
        controlPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        final Button showAllCheck = UIUtils.createCheckbox(controlPanel, "Show all connections", "Show all datasource connections. Otherwise shows only transactional connections.", false, 1);
        showAllCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                loadContexts(showAllCheck.getSelection());
            }
        });
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.grabExcessHorizontalSpace = true;
        showAllCheck.setLayoutData(gd);
        commitButton = UIUtils.createPushButton(controlPanel, "Commit", DBeaverIcons.getImage(UIIcon.TXN_COMMIT));
        commitButton.setEnabled(false);
        commitButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                endTransaction(true);
            }
        });
        rollbackButton = UIUtils.createPushButton(controlPanel, "Rollback", DBeaverIcons.getImage(UIIcon.TXN_ROLLBACK));
        rollbackButton.setEnabled(false);
        rollbackButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                endTransaction(false);
            }
        });
        closeOnFocusLost(showAllCheck, commitButton, rollbackButton);
    }
    super.createTransactionLogPanel(composite);
    loadContexts(false);
    return parent;
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 48 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class DataSourceAutoCommitHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    boolean autoCommit = true;
    DBPTransactionIsolation isolation = null;
    DBCExecutionContext context = getExecutionContextFromPart(activeEditor);
    if (context != null && context.isConnected()) {
        DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
        if (txnManager != null) {
            try {
                // Change auto-commit mode
                autoCommit = txnManager.isAutoCommit();
                isolation = txnManager.getTransactionIsolation();
            } catch (DBCException e) {
                log.warn(e);
            }
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        if (container != null) {
            autoCommit = container.isDefaultAutoCommit();
            isolation = container.getActiveTransactionsIsolation();
        }
    }
    element.setChecked(autoCommit);
    // Update command image
    element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
    String isolationName = isolation == null ? "?" : isolation.getTitle();
    String text = autoCommit ? NLS.bind(CoreMessages.action_menu_transaction_manualcommit_name, isolationName) : CoreMessages.action_menu_transaction_autocommit_name;
    element.setText(text);
    element.setTooltip(text);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Example 49 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class DatabaseEditorInputFactory method saveState.

public static void saveState(IMemento memento, DatabaseEditorInput input) {
    if (!DBWorkbench.getPlatform().getPreferenceStore().getBoolean(DatabaseEditorPreferences.PROP_SAVE_EDITORS_STATE)) {
        return;
    }
    final DBCExecutionContext context = input.getExecutionContext();
    if (context == null) {
        // Detached - nothing to save
        return;
    }
    if (input.getDatabaseObject() != null && !input.getDatabaseObject().isPersisted()) {
        return;
    }
    final DBNDatabaseNode node = input.getNavigatorNode();
    memento.putString(TAG_CLASS, input.getClass().getName());
    memento.putString(TAG_PROJECT, context.getDataSource().getContainer().getProject().getName());
    memento.putString(TAG_DATA_SOURCE, context.getDataSource().getContainer().getId());
    memento.putString(TAG_NODE, node.getNodeItemPath());
    memento.putString(TAG_NODE_NAME, node.getNodeName());
    if (!CommonUtils.isEmpty(input.getDefaultPageId())) {
        memento.putString(TAG_ACTIVE_PAGE, input.getDefaultPageId());
    }
    if (!CommonUtils.isEmpty(input.getDefaultFolderId())) {
        memento.putString(TAG_ACTIVE_FOLDER, input.getDefaultFolderId());
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 50 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class AbstractSessionEditor method createEditorControl.

@Override
public void createEditorControl(Composite parent) {
    final DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext != null) {
        setPartName("Sessions - " + executionContext.getDataSource().getContainer().getName());
        sessionsViewer = createSessionViewer(executionContext, parent);
        sessionsViewer.loadSettings(this);
        sessionsViewer.refreshSessions();
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext)

Aggregations

DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)107 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)27 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)22 DBException (org.jkiss.dbeaver.DBException)21 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)20 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)16 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)15 GridData (org.eclipse.swt.layout.GridData)12 IEditorPart (org.eclipse.ui.IEditorPart)12 DBCException (org.jkiss.dbeaver.model.exec.DBCException)12 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 ArrayList (java.util.ArrayList)10 Composite (org.eclipse.swt.widgets.Composite)10 DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)10 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 NotNull (org.jkiss.code.NotNull)8