Search in sources :

Example 26 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 27 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 28 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)

Example 29 with DBCExecutionContext

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

the class SQLEditorBase method scrollCursorToError.

/**
 * Error handling
 */
boolean scrollCursorToError(@NotNull DBRProgressMonitor monitor, @NotNull SQLQuery query, @NotNull Throwable error) {
    try {
        DBCExecutionContext context = getExecutionContext();
        if (context == null) {
            return false;
        }
        boolean scrolled = false;
        DBPErrorAssistant errorAssistant = DBUtils.getAdapter(DBPErrorAssistant.class, context.getDataSource());
        if (errorAssistant != null) {
            DBPErrorAssistant.ErrorPosition[] positions = errorAssistant.getErrorPosition(monitor, context, query.getText(), error);
            if (positions != null && positions.length > 0) {
                int queryStartOffset = query.getOffset();
                int queryLength = query.getLength();
                DBPErrorAssistant.ErrorPosition pos = positions[0];
                if (pos.line < 0) {
                    if (pos.position >= 0) {
                        // Only position
                        getSelectionProvider().setSelection(new TextSelection(queryStartOffset + pos.position, 0));
                        scrolled = true;
                    }
                } else {
                    // Line + position
                    IDocument document = getDocument();
                    if (document != null) {
                        int startLine = document.getLineOfOffset(queryStartOffset);
                        int errorOffset = document.getLineOffset(startLine + pos.line);
                        int errorLength;
                        if (pos.position >= 0) {
                            errorOffset += pos.position;
                            errorLength = 1;
                        } else {
                            errorLength = document.getLineLength(startLine + pos.line);
                        }
                        if (errorOffset < queryStartOffset)
                            errorOffset = queryStartOffset;
                        if (errorLength > queryLength)
                            errorLength = queryLength;
                        if (errorOffset >= queryStartOffset + queryLength) {
                            // This may happen if error position was incorrectly detected.
                            // E.g. in SQL Server when actual error happened in some stored procedure.
                            errorOffset = queryStartOffset + queryLength - 1;
                        }
                        getSelectionProvider().setSelection(new TextSelection(errorOffset, errorLength));
                        scrolled = true;
                    }
                }
            }
        }
        return scrolled;
    // if (!scrolled) {
    // // Can't position on error - let's just select entire problem query
    // showStatementInEditor(result.getStatement(), true);
    // }
    } catch (Exception e) {
        log.warn("Error positioning on query error", e);
        return false;
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) CoreException(org.eclipse.core.runtime.CoreException)

Example 30 with DBCExecutionContext

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

the class TransactionInfoDialog method createTransactionLogPanel.

protected void createTransactionLogPanel(Composite composite) {
    DBCExecutionContext context = getCurrentContext();
    QMEventFilter filter = context == null ? VOID_FILTER : createContextFilter(context);
    logViewer = new QueryLogViewer(composite, activeEditor.getSite(), filter, false, true);
    logViewer.setUseDefaultFilter(false);
    final Object gd = logViewer.getControl().getLayoutData();
    if (gd instanceof GridData) {
        ((GridData) gd).heightHint = logViewer.getControl().getHeaderHeight() + logViewer.getControl().getItemHeight() * 5;
    }
    showAllCheck = UIUtils.createCheckbox(composite, CoreMessages.transaction_info_dialog_checkbox_show_all_queries, CoreMessages.transaction_info_dialog_label_show_all_transaction_queries, false, 1);
    showAllCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateTransactionFilter();
        }
    });
    showPreviousCheck = UIUtils.createCheckbox(composite, CoreMessages.transaction_info_dialog_checkbox_show_previous_transactions, CoreMessages.transaction_info_dialog_label_otherwise, false, 1);
    showPreviousCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateTransactionFilter();
        }
    });
    closeOnFocusLost(logViewer.getSearchText(), logViewer.getControl(), showAllCheck, showPreviousCheck);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) QMMObject(org.jkiss.dbeaver.model.qm.meta.QMMObject) QueryLogViewer(org.jkiss.dbeaver.ui.controls.querylog.QueryLogViewer)

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