Search in sources :

Example 11 with DBCExecutionContext

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

the class SQLObjectResolver method resolveAll.

@Override
protected String[] resolveAll(final TemplateContext context) {
    final List<T> entities = new ArrayList<>();
    if (context instanceof DBPContextProvider) {
        final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
        if (executionContext != null) {
            RuntimeUtils.runTask(new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        resolveObjects(monitor, executionContext, context, entities);
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            }, "Resolve object references", 1000);
        }
    }
    if (!CommonUtils.isEmpty(entities)) {
        String[] result = new String[entities.size()];
        for (int i = 0; i < entities.size(); i++) {
            T entity = entities.get(i);
            result[i] = entity.getName();
        }
        return result;
    }
    return super.resolveAll(context);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 12 with DBCExecutionContext

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

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);
    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, "Show all queries", "Show all transaction queries. Otherwise shows only modifying queries.", false, 1);
    showAllCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateTransactionFilter();
        }
    });
    showPreviousCheck = UIUtils.createCheckbox(composite, "Show previous transactions", "Show previous transactions. Otherwise shows only active one.", false, 1);
    showPreviousCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateTransactionFilter();
        }
    });
}
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)

Example 13 with DBCExecutionContext

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

the class TransactionInfoDialog method updateTransactionFilter.

private void updateTransactionFilter() {
    DBCExecutionContext context = getCurrentContext();
    QMEventFilter filter = context == null ? VOID_FILTER : createContextFilter(context);
    logViewer.setFilter(filter);
    logViewer.refresh();
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) QMEventFilter(org.jkiss.dbeaver.model.qm.QMEventFilter)

Example 14 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 (activePart instanceof INavigatorModelView) {
        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();
                    }
                    DBPDataSource dataSource = object.getDataSource();
                    if (dataSource != null) {
                        context = dataSource.getDefaultContext(true);
                    }
                }
            }
        }
    }
    if (context == null) {
        DBUserInterface.getInstance().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) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) GotoObjectDialog(org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 15 with DBCExecutionContext

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

the class ResultSetFilterPanel method setCustomDataFilter.

private void setCustomDataFilter() {
    DBCExecutionContext context = viewer.getExecutionContext();
    if (context == null) {
        return;
    }
    String condition = filtersText.getText();
    StringBuilder currentCondition = new StringBuilder();
    SQLUtils.appendConditionString(viewer.getModel().getDataFilter(), context.getDataSource(), null, currentCondition, true);
    if (currentCondition.toString().trim().equals(condition.trim())) {
        // The same
        return;
    }
    DBDDataFilter newFilter = new DBDDataFilter(viewer.getModel().getDataFilter());
    for (DBDAttributeConstraint ac : newFilter.getConstraints()) {
        ac.setCriteria(null);
    }
    newFilter.setWhere(condition);
    viewer.setDataFilter(newFilter, true);
//viewer.getControl().setFocus();
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Aggregations

DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)23 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)7 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)5 ArrayList (java.util.ArrayList)3 DBException (org.jkiss.dbeaver.DBException)3 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 NotNull (org.jkiss.code.NotNull)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2 DBCTransactionManager (org.jkiss.dbeaver.model.exec.DBCTransactionManager)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 QMEventFilter (org.jkiss.dbeaver.model.qm.QMEventFilter)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)2 IDocument (org.eclipse.jface.text.IDocument)1