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);
}
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();
}
}
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);
}
}
}
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);
}
}
}
}
}
}
}
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;
}
Aggregations