Search in sources :

Example 26 with DBRRunnableWithProgress

use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress 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 27 with DBRRunnableWithProgress

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

the class SQLEditor method explainPlanFromQuery.

private void explainPlanFromQuery(final DBCQueryPlanner planner, final SQLQuery sqlQuery) {
    final String[] planQueryString = new String[1];
    DBRRunnableWithProgress queryObtainTask = monitor -> {
        DBCQueryPlannerConfiguration configuration = ExplainPlanViewer.makeExplainPlanConfiguration(monitor, planner);
        if (configuration == null) {
            return;
        }
        try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, "Prepare plan query")) {
            DBCPlan plan = planner.planQueryExecution(session, sqlQuery.getText(), configuration);
            planQueryString[0] = plan.getPlanQueryString();
        } catch (Exception e) {
            log.error(e);
        }
    };
    if (RuntimeUtils.runTask(queryObtainTask, "Retrieve plan query", 5000) && !CommonUtils.isEmpty(planQueryString[0])) {
        SQLQuery planQuery = new SQLQuery(getDataSource(), planQueryString[0]);
        processQueries(Collections.singletonList(planQuery), false, true, false, true, null, null);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) Point(org.eclipse.swt.graphics.Point) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Matcher(java.util.regex.Matcher) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) EFS(org.eclipse.core.filesystem.EFS) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) SQLQueryDataContainer(org.jkiss.dbeaver.model.sql.data.SQLQueryDataContainer) org.jkiss.dbeaver.ui.controls.resultset(org.jkiss.dbeaver.ui.controls.resultset) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) SWT(org.eclipse.swt.SWT) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) SimpleDateFormat(java.text.SimpleDateFormat) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) IFile(org.eclipse.core.resources.IFile) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) org.eclipse.swt.events(org.eclipse.swt.events) SQLPresentationRegistry(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationRegistry) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections) SourceViewer(org.eclipse.jface.text.source.SourceViewer) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.eclipse.core.runtime(org.eclipse.core.runtime) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) GridLayout(org.eclipse.swt.layout.GridLayout) StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) org.eclipse.jface.text(org.eclipse.jface.text) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) SQLPresentationPanelDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationPanelDescriptor) ModelMessages(org.jkiss.dbeaver.model.messages.ModelMessages) SQLPresentationDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationDescriptor) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) DBCQueryPlannerConfiguration(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlannerConfiguration) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) IFileState(org.eclipse.core.resources.IFileState) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) NLS(org.eclipse.osgi.util.NLS) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) org.jkiss.dbeaver.ui.controls(org.jkiss.dbeaver.ui.controls) SQLEditorMessages(org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages) DBStyles(org.jkiss.dbeaver.ui.css.DBStyles) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) Pattern(java.util.regex.Pattern) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) SQLQueryJob(org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) FillLayout(org.eclipse.swt.layout.FillLayout) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) ArrayUtils(org.jkiss.utils.ArrayUtils) DataSourceUtils(org.jkiss.dbeaver.registry.DataSourceUtils) CTabItem(org.eclipse.swt.custom.CTabItem) CSSUtils(org.jkiss.dbeaver.ui.css.CSSUtils) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.ui.wizard.DataTransferWizard) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) DBCQueryPlannerConfiguration(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlannerConfiguration) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBException(org.jkiss.dbeaver.DBException)

Example 28 with DBRRunnableWithProgress

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

the class ObjectPropertiesEditor method makeDatabaseEditorTabs.

private void makeDatabaseEditorTabs(final IDatabaseEditor part, final List<TabbedFolderInfo> tabList) {
    final DBNDatabaseNode node = part.getEditorInput() instanceof IDatabaseEditorInput ? ((IDatabaseEditorInput) part.getEditorInput()).getNavigatorNode() : null;
    if (node == null) {
        return;
    }
    final DBSObject object = node.getObject();
    if (!node.getMeta().isStandaloneNode()) {
        // Collect tabs from navigator tree model
        DBRRunnableWithProgress tabsCollector = monitor -> collectNavigatorTabs(monitor, part, node, tabList);
        try {
            if (node.needsInitialization()) {
                UIUtils.runInProgressService(tabsCollector);
            } else {
                tabsCollector.run(new VoidProgressMonitor());
            }
        } catch (InvocationTargetException e) {
            log.error(e.getTargetException());
        } catch (InterruptedException e) {
        // just go further
        }
    }
    // Extra properties tab (show if we have extra properties only)
    {
        TabbedFolderPageProperties pageProperties = new TabbedFolderPageProperties(this, getEditorInput());
        List<String> extraCategories = pageProperties.getExtraCategories();
        if (!extraCategories.isEmpty()) {
            tabList.add(new TabbedFolderInfo(PropertiesContributor.TAB_PROPERTIES, extraCategories.get(0) + (extraCategories.size() == 1 ? "" : " / ... "), DBIcon.TREE_INFO, String.join(", ", extraCategories), false, pageProperties));
        }
    }
    // Query for entity editors
    List<EntityEditorDescriptor> editors = EntityEditorsRegistry.getInstance().getEntityEditors(object, this, null);
    if (!CommonUtils.isEmpty(editors)) {
        for (EntityEditorDescriptor descriptor : editors) {
            if (descriptor.getType() == EntityEditorDescriptor.Type.folder) {
                tabList.add(new TabbedFolderInfo(descriptor.getId(), descriptor.getName(), descriptor.getIcon(), descriptor.getDescription(), descriptor.isEmbeddable(), new TabbedFolderPageEditor(this, descriptor)));
            }
        }
    }
}
Also used : MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) SashForm(org.eclipse.swt.custom.SashForm) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) Point(org.eclipse.swt.graphics.Point) DataSourcePropertyFilter(org.jkiss.dbeaver.runtime.properties.DataSourcePropertyFilter) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) Composite(org.eclipse.swt.widgets.Composite) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) PropertiesContributor(org.jkiss.dbeaver.runtime.properties.PropertiesContributor) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) org.jkiss.dbeaver.ui.editors(org.jkiss.dbeaver.ui.editors) IAdaptable(org.eclipse.core.runtime.IAdaptable) CommonUtils(org.jkiss.utils.CommonUtils) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBUtils(org.jkiss.dbeaver.model.DBUtils) IContributionManager(org.eclipse.jface.action.IContributionManager) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) NavigatorPreferences(org.jkiss.dbeaver.ui.navigator.NavigatorPreferences) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) DBStyles(org.jkiss.dbeaver.ui.css.DBStyles) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBXTreeFolder(org.jkiss.dbeaver.model.navigator.meta.DBXTreeFolder) DBIcon(org.jkiss.dbeaver.model.DBIcon) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) java.util(java.util) org.jkiss.dbeaver.model.navigator(org.jkiss.dbeaver.model.navigator) PartSite(org.eclipse.ui.internal.PartSite) Nullable(org.jkiss.code.Nullable) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) ObjectEditorPageControl(org.jkiss.dbeaver.ui.controls.ObjectEditorPageControl) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) org.jkiss.dbeaver.ui.controls.folders(org.jkiss.dbeaver.ui.controls.folders) Viewer(org.eclipse.jface.viewers.Viewer) org.jkiss.dbeaver.ui.editors.entity(org.jkiss.dbeaver.ui.editors.entity) Action(org.eclipse.jface.action.Action) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) UINavigatorMessages(org.jkiss.dbeaver.ui.internal.UINavigatorMessages) org.eclipse.ui(org.eclipse.ui) CSSUtils(org.jkiss.dbeaver.ui.css.CSSUtils) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)

Example 29 with DBRRunnableWithProgress

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

the class NavigatorHandlerObjectCreateCopy method pasteResource.

private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
    final IResource resource = resourceNode.getResource();
    final IResource targetResource = toFolder.getResource();
    assert resource != null;
    assert targetResource != null;
    final IContainer targetFolder = targetResource instanceof IContainer ? (IContainer) targetResource : targetResource.getParent();
    try {
        UIUtils.runInProgressService(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    copyResource(monitor, resource, targetFolder);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        DBWorkbench.getPlatformUI().showError("Copy error", "Error copying resource", e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 30 with DBRRunnableWithProgress

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

the class NavigatorStatePersistor method restoreState.

public void restoreState(final TreeViewer navigatorViewer, final DBNNode rootNode, int maxDepth, final IMemento memento) {
    if (memento == null || ArrayUtils.isEmpty(memento.getAttributeKeys())) {
        return;
    }
    DBRRunnableWithProgress runnable = (monitor) -> {
        try {
            if (memento != null) {
                monitor.beginTask("Expan navigator nodes", memento.getAttributeKeys().length);
                for (int i = 0; i < memento.getAttributeKeys().length; i++) {
                    if (monitor.isCanceled()) {
                        break;
                    }
                    String nodeIdentifier = memento.getString(KEY_PREFIX + i);
                    monitor.subTask("Expan node " + nodeIdentifier);
                    DBNNode node = findNode(nodeIdentifier, rootNode, 1, maxDepth, monitor);
                    if (node != null && !node.isDisposed()) {
                        UIUtils.syncExec(() -> {
                            navigatorViewer.setExpandedState(node, true);
                        });
                    }
                }
                monitor.done();
            }
        } catch (Exception e) {
            throw new InvocationTargetException(e);
        }
    };
    AbstractJob expandJob = new AbstractJob("Expand navigator nodes") {

        {
            setSystem(false);
            setUser(true);
        }

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                runnable.run(monitor);
            } catch (InvocationTargetException e) {
                log.error(e);
            } catch (InterruptedException e) {
            // ignore
            }
            return Status.OK_STATUS;
        }
    };
    UIUtils.asyncExec(expandJob::schedule);
}
Also used : IMemento(org.eclipse.ui.IMemento) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) Status(org.eclipse.core.runtime.Status) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) ArrayUtils(org.jkiss.utils.ArrayUtils) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) IStatus(org.eclipse.core.runtime.IStatus) DBException(org.jkiss.dbeaver.DBException) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)64 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)60 InvocationTargetException (java.lang.reflect.InvocationTargetException)58 DBException (org.jkiss.dbeaver.DBException)36 ArrayList (java.util.ArrayList)11 IFile (org.eclipse.core.resources.IFile)11 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)11 CoreException (org.eclipse.core.runtime.CoreException)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)10 List (java.util.List)9 NotNull (org.jkiss.code.NotNull)9 Nullable (org.jkiss.code.Nullable)9 CommonUtils (org.jkiss.utils.CommonUtils)8 File (java.io.File)7 Collection (java.util.Collection)7 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)7 Log (org.jkiss.dbeaver.Log)6 InputStream (java.io.InputStream)5 IResource (org.eclipse.core.resources.IResource)5 SWT (org.eclipse.swt.SWT)5