Search in sources :

Example 1 with DBPTransactionIsolation

use of org.jkiss.dbeaver.model.DBPTransactionIsolation 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 = getExecutionContext(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 ? "Switch to manual commit (" + isolationName + ")" : "Switch to auto-commit";
    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 2 with DBPTransactionIsolation

use of org.jkiss.dbeaver.model.DBPTransactionIsolation 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 3 with DBPTransactionIsolation

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

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 4 with DBPTransactionIsolation

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

the class DBTaskUtils method extractContext.

public static DBTTaskContext extractContext(@NotNull DBCExecutionContext executionContext) {
    DBTTaskContext context = new DBTTaskContext();
    DBCExecutionContextDefaults defaults = executionContext.getContextDefaults();
    if (defaults != null) {
        DBSCatalog defaultCatalog = defaults.getDefaultCatalog();
        if (defaultCatalog != null) {
            context.setDefaultCatalog(defaultCatalog.getName());
        }
        DBSSchema defaultSchema = defaults.getDefaultSchema();
        if (defaultSchema != null) {
            context.setDefaultSchema(defaultSchema.getName());
        }
    }
    DBCTransactionManager txnManager = DBUtils.getTransactionManager(executionContext);
    if (txnManager != null) {
        try {
            context.setAutoCommit(txnManager.isAutoCommit());
            DBPTransactionIsolation isolation = txnManager.getTransactionIsolation();
            if (isolation != null) {
                context.setTransactionIsolation(isolation.getCode());
            }
        } catch (Throwable e) {
            log.debug(e);
        }
    }
    return context;
}
Also used : DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DBSCatalog(org.jkiss.dbeaver.model.struct.rdb.DBSCatalog) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Aggregations

DBPTransactionIsolation (org.jkiss.dbeaver.model.DBPTransactionIsolation)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)3 DBCTransactionManager (org.jkiss.dbeaver.model.exec.DBCTransactionManager)3 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)2 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)1 DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)1 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)1