Search in sources :

Example 11 with DBSCatalog

use of org.jkiss.dbeaver.model.struct.rdb.DBSCatalog 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)

Example 12 with DBSCatalog

use of org.jkiss.dbeaver.model.struct.rdb.DBSCatalog in project dbeaver by serge-rider.

the class NavigatorHandlerSetDefaultObject method markObjectAsActive.

@SuppressWarnings("unchecked")
private void markObjectAsActive(final DBNDatabaseNode databaseNode, IEditorPart activeEditor) {
    DBNNode parentNode = databaseNode.getParentNode();
    if (parentNode instanceof DBNDatabaseItem) {
        markObjectAsActive((DBNDatabaseItem) parentNode, activeEditor);
        return;
    }
    DBSObject object = databaseNode.getObject();
    DBPDataSource dataSource = object.getDataSource();
    final DBCExecutionContext editorContext;
    if (activeEditor instanceof DBPContextProvider) {
        editorContext = ((DBPContextProvider) activeEditor).getExecutionContext();
    } else {
        editorContext = null;
    }
    TasksJob.runTask("Change default object", monitor -> {
        try {
            DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
                try {
                    DBCExecutionContext defaultContext = dataSource.getDefaultInstance().getDefaultContext(monitor, false);
                    DBCExecutionContext[] contextsToChange;
                    if (editorContext != null && editorContext != defaultContext && editorContext.getDataSource() == defaultContext.getDataSource()) {
                        contextsToChange = new DBCExecutionContext[] { defaultContext, editorContext };
                    } else {
                        contextsToChange = new DBCExecutionContext[] { defaultContext };
                    }
                    for (DBCExecutionContext executionContext : contextsToChange) {
                        DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
                        if (contextDefaults != null) {
                            if (object instanceof DBSCatalog && contextDefaults.supportsCatalogChange()) {
                                contextDefaults.setDefaultCatalog(monitor, (DBSCatalog) object, null);
                            } else if (object instanceof DBSSchema && contextDefaults.supportsSchemaChange()) {
                                contextDefaults.setDefaultSchema(monitor, (DBSSchema) object);
                            } else {
                                throw new DBCException("Internal error: active object change not supported");
                            }
                        }
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            });
        } catch (Exception e) {
            throw new InvocationTargetException(e);
        }
    });
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSCatalog(org.jkiss.dbeaver.model.struct.rdb.DBSCatalog) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(org.eclipse.core.commands.ExecutionException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Aggregations

DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)12 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)12 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)6 DBException (org.jkiss.dbeaver.DBException)5 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)5 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)5 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 SQLDataSource (org.jkiss.dbeaver.model.sql.SQLDataSource)2 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1