Search in sources :

Example 81 with DBCExecutionContext

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

the class SQLLogFilter method belongsToEditor.

private boolean belongsToEditor(QMMSessionInfo session) {
    String containerId = session.getContainerId();
    String contextName = session.getContextName();
    DBCExecutionContext executionContext = editor.getExecutionContext();
    return executionContext != null && Objects.equals(executionContext.getDataSource().getContainer().getId(), containerId) && Objects.equals(executionContext.getContextName(), contextName);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext)

Example 82 with DBCExecutionContext

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

the class ExplainPlanViewer method refresh.

@Override
public void refresh() {
    DBCQueryPlanner planner;
    DBCExecutionContext executionContext = contextProvider.getExecutionContext();
    if (executionContext != null) {
        DBPDataSource dataSource = executionContext.getDataSource();
        planner = GeneralUtils.adapt(dataSource, DBCQueryPlanner.class);
    } else {
        planner = null;
    }
    if (planner == null) {
        DBWorkbench.getPlatformUI().showError("No SQL Plan", "This datasource doesn't support execution plans");
    } else {
        explainService = LoadingJob.createService(new ExplainPlanService(planner, executionContext, lastQuery.getText(), lastQueryId), planPresentationContainer.createVisualizer());
        explainService.schedule();
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 83 with DBCExecutionContext

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

the class SelectDatabaseDialog method createUpperControls.

@Override
protected void createUpperControls(Composite dialogArea) {
    DBPDataSource dataSource = dataSourceContainer.getDataSource();
    if (currentInstanceName != null && dataSource != null) {
        DBSObjectContainer instanceContainer = DBUtils.getAdapter(DBSObjectContainer.class, dataSource);
        DBCExecutionContextDefaults contextDefaults = null;
        DBCExecutionContext defaultContext = DBUtils.getDefaultContext(instanceContainer, true);
        if (defaultContext != null) {
            contextDefaults = defaultContext.getContextDefaults();
        }
        if (instanceContainer != null && contextDefaults != null && contextDefaults.supportsCatalogChange()) {
            createInstanceSelector(dialogArea, instanceContainer);
        }
    }
}
Also used : DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 84 with DBCExecutionContext

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

the class SQLCompletionAnalyzer method filterProposals.

private void filterProposals(DBPDataSource dataSource) {
    // Remove duplications
    final Set<String> proposalMap = new HashSet<>(proposals.size());
    for (int i = 0; i < proposals.size(); ) {
        SQLCompletionProposalBase proposal = proposals.get(i);
        if (proposalMap.contains(proposal.getDisplayString())) {
            proposals.remove(i);
            continue;
        }
        proposalMap.add(proposal.getDisplayString());
        i++;
    }
    DBSInstance defaultInstance = dataSource == null ? null : dataSource.getDefaultInstance();
    DBCExecutionContext executionContext = request.getContext().getExecutionContext();
    DBSObject selectedObject = defaultInstance == null || executionContext == null ? null : DBUtils.getActiveInstanceObject(executionContext);
    boolean hideDups = request.getContext().isHideDuplicates() && selectedObject != null;
    if (hideDups) {
        for (int i = 0; i < proposals.size(); i++) {
            SQLCompletionProposalBase proposal = proposals.get(i);
            for (int j = 0; j < proposals.size(); ) {
                SQLCompletionProposalBase proposal2 = proposals.get(j);
                if (i != j && proposal.hasStructObject() && proposal2.hasStructObject() && CommonUtils.equalObjects(proposal.getObject().getName(), proposal2.getObject().getName()) && proposal.getObjectContainer() == selectedObject) {
                    proposals.remove(j);
                } else {
                    j++;
                }
            }
        }
    }
    if (hideDups) {
        if (selectedObject instanceof DBSObjectContainer) {
        }
    }
    // Apply navigator object filters
    if (dataSource != null) {
        DBPDataSourceContainer dsContainer = dataSource.getContainer();
        Map<DBSObject, Map<Class, List<SQLCompletionProposalBase>>> containerMap = new HashMap<>();
        for (SQLCompletionProposalBase proposal : proposals) {
            DBSObject container = proposal.getObjectContainer();
            DBPNamedObject object = proposal.getObject();
            if (object == null) {
                continue;
            }
            Map<Class, List<SQLCompletionProposalBase>> typeMap = containerMap.computeIfAbsent(container, k -> new HashMap<>());
            Class objectType = object instanceof DBSObjectReference ? ((DBSObjectReference) object).getObjectClass() : object.getClass();
            List<SQLCompletionProposalBase> list = typeMap.computeIfAbsent(objectType, k -> new ArrayList<>());
            list.add(proposal);
        }
        for (Map.Entry<DBSObject, Map<Class, List<SQLCompletionProposalBase>>> entry : containerMap.entrySet()) {
            for (Map.Entry<Class, List<SQLCompletionProposalBase>> typeEntry : entry.getValue().entrySet()) {
                DBSObjectFilter filter = dsContainer.getObjectFilter(typeEntry.getKey(), entry.getKey(), true);
                if (filter != null && filter.isEnabled()) {
                    for (SQLCompletionProposalBase proposal : typeEntry.getValue()) {
                        if (!filter.matches(proposal.getObject().getName())) {
                            proposals.remove(proposal);
                        }
                    }
                }
            }
        }
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext)

Example 85 with DBCExecutionContext

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

the class NavigatorHandlerObjectGoto method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBCExecutionContext context = null;
    DBSObject container = null;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof DBPContextProvider) {
        context = ((DBPContextProvider) activePart).getExecutionContext();
    } else if (GeneralUtils.adapt(activePart, INavigatorModelView.class) != null) {
        final ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof DBSWrapper) {
                DBSObject object = ((DBSWrapper) element).getObject();
                if (object != null) {
                    container = object;
                    while (container instanceof DBSFolder) {
                        container = container.getParentObject();
                    }
                    context = DBUtils.getDefaultContext(object, true);
                }
            }
        }
    }
    if (context == null) {
        DBWorkbench.getPlatformUI().showError("Go to object", "No active datasource");
        return null;
    }
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
    dialog.open();
    Object[] objectsToOpen = dialog.getResult();
    if (!ArrayUtils.isEmpty(objectsToOpen)) {
        Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
        for (DBNDatabaseNode node : nodes) {
            NavigatorUtils.openNavigatorNode(node, workbenchWindow);
        }
    }
    return null;
}
Also used : DBSFolder(org.jkiss.dbeaver.model.struct.DBSFolder) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) GotoObjectDialog(org.jkiss.dbeaver.ui.navigator.dialogs.GotoObjectDialog) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

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