Search in sources :

Example 31 with DBCExecutionContext

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

the class TransactionInfoDialog method createContextFilter.

protected QMEventFilter createContextFilter(DBCExecutionContext executionContext) {
    if (executionContext == null) {
        return VOID_FILTER;
    }
    final boolean showAll = showAllCheck != null && showAllCheck.getSelection();
    final boolean showPrevious = showPreviousCheck != null && showPreviousCheck.getSelection();
    final QMMSessionInfo currentSession = QMUtils.getCurrentSession(executionContext);
    final QMMTransactionSavepointInfo currentSP = QMUtils.getCurrentTransaction(executionContext);
    QMEventFilter filter = event -> {
        QMMObject object = event.getObject();
        if (object instanceof QMMStatementExecuteInfo) {
            QMMStatementExecuteInfo exec = (QMMStatementExecuteInfo) object;
            if (!showPrevious && !CommonUtils.equalObjects(exec.getSavepoint(), currentSP)) {
                return false;
            }
            if (!showAll && !CommonUtils.equalObjects(exec.getStatement().getSession(), currentSession)) {
                return false;
            }
            DBCExecutionPurpose purpose = exec.getStatement().getPurpose();
            if (purpose == DBCExecutionPurpose.META || purpose == DBCExecutionPurpose.UTIL) {
                return false;
            }
            return (showAll || exec.isTransactional());
        }
        return false;
    };
    return filter;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) QMMSessionInfo(org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) QMMStatementExecuteInfo(org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) CoreMessages(org.jkiss.dbeaver.core.CoreMessages) QueryLogViewer(org.jkiss.dbeaver.ui.controls.querylog.QueryLogViewer) DBCExecutionPurpose(org.jkiss.dbeaver.model.exec.DBCExecutionPurpose) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo) AbstractPopupPanel(org.jkiss.dbeaver.ui.dialogs.AbstractPopupPanel) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) QMMObject(org.jkiss.dbeaver.model.qm.meta.QMMObject) QMMSessionInfo(org.jkiss.dbeaver.model.qm.meta.QMMSessionInfo) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter) QMMStatementExecuteInfo(org.jkiss.dbeaver.model.qm.meta.QMMStatementExecuteInfo) DBCExecutionPurpose(org.jkiss.dbeaver.model.exec.DBCExecutionPurpose) QMMObject(org.jkiss.dbeaver.model.qm.meta.QMMObject) QMMTransactionSavepointInfo(org.jkiss.dbeaver.model.qm.meta.QMMTransactionSavepointInfo)

Example 32 with DBCExecutionContext

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

the class TransactionInfoDialog method updateTransactionFilter.

protected void updateTransactionFilter() {
    DBCExecutionContext context = getCurrentContext();
    QMEventFilter filter = context == null ? VOID_FILTER : createContextFilter(context);
    logViewer.setFilter(filter);
    logViewer.refresh();
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter)

Example 33 with DBCExecutionContext

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

the class ConnectionPageInitialization method loadDatabaseSettings.

private void loadDatabaseSettings(DBRProgressMonitor monitor, DBPDataSource dataSource) {
    DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
    Collection<DBPTransactionIsolation> txnLevels = CommonUtils.safeCollection(dataSource.getInfo().getSupportedTransactionsIsolation());
    Integer levelCode = dataSourceContainer.getDefaultTransactionsIsolation();
    UIUtils.syncExec(() -> {
        autocommit.setSelection(dataSourceContainer.isDefaultAutoCommit());
        // isolationLevel.setEnabled(!autocommit.getSelection());
        supportedLevels.clear();
        DBPTransactionIsolation defaultLevel = null;
        {
            if (levelCode != null && !CommonUtils.isEmpty(txnLevels)) {
                for (DBPTransactionIsolation level : txnLevels) {
                    if (level.getCode() == levelCode) {
                        defaultLevel = level;
                        break;
                    }
                }
            }
        }
        isolationLevel.removeAll();
        supportedLevels.clear();
        for (DBPTransactionIsolation level : txnLevels) {
            if (!level.isEnabled()) {
                continue;
            }
            isolationLevel.add(level.getTitle());
            supportedLevels.add(level);
            if (level.equals(defaultLevel)) {
                isolationLevel.select(isolationLevel.getItemCount() - 1);
            }
        }
    });
    if (dataSource instanceof DBSObjectContainer) {
        DBCExecutionContext executionContext = DBUtils.getDefaultContext(dataSource, true);
        DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
        DBSObjectContainer catalogContainer = DBUtils.getChangeableObjectContainer(contextDefaults, (DBSObjectContainer) dataSource, DBSCatalog.class);
        if (catalogContainer != null) {
            loadSelectableObject(monitor, catalogContainer, defaultCatalog, contextDefaults, true);
        }
        DBSObjectContainer schemaContainer = DBUtils.getChangeableObjectContainer(contextDefaults, (DBSObjectContainer) dataSource, DBSSchema.class);
        loadSelectableObject(monitor, schemaContainer, defaultSchema, contextDefaults, false);
    }
    txnOptionsLoaded = true;
}
Also used : DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 34 with DBCExecutionContext

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

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 35 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext 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)

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