Search in sources :

Example 1 with OracleSchedulerJob

use of org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob in project dbeaver by serge-rider.

the class JobRunHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
    final List<OracleSchedulerJob> objects = getSelectedJobs(event);
    if (!objects.isEmpty()) {
        if (activePart instanceof EntityEditor) {
            // Save editor before run
            // Use null monitor as entity editor has its own detached job for save
            EntityEditor entityEditor = (EntityEditor) activePart;
            if (entityEditor.isDirty()) {
                NullProgressMonitor monitor = new NullProgressMonitor();
                entityEditor.doSave(monitor);
                if (monitor.isCanceled()) {
                    // Save failed - doesn't make sense to compile
                    return null;
                }
            }
        }
        final Shell activeShell = HandlerUtil.getActiveShell(event);
        if (objects.size() == 1) {
            final OracleSchedulerJob job = objects.get(0);
            final DBCCompileLog compileLog = new DBCCompileLogBase();
            compileLog.clearLog();
            Throwable error = null;
            try {
                UIUtils.runInProgressService(monitor -> {
                    try {
                        runJob(monitor, compileLog, job);
                    } catch (DBCException e) {
                        throw new InvocationTargetException(e);
                    }
                });
                if (compileLog.getError() != null) {
                    error = compileLog.getError();
                }
            } catch (InvocationTargetException e) {
                error = e.getTargetException();
            } catch (InterruptedException e) {
                return null;
            }
            if (error != null) {
                DBWorkbench.getPlatformUI().showError("Unexpected run schedule error", null, error);
            } else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
                // Show compile errors
                int line = -1, position = -1;
                StringBuilder fullMessage = new StringBuilder();
                for (DBCCompileError oce : compileLog.getErrorStack()) {
                    fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
                    if (line < 0) {
                        line = oce.getLine();
                        position = oce.getPosition();
                    }
                }
                String errorTitle = job.getName() + " run schedule failed";
                DBWorkbench.getPlatformUI().showError(errorTitle, fullMessage.toString());
            } else {
                String message = job.getName() + " successfully scheduled to run";
                UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
            }
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OracleSchedulerJob(org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBCCompileLogBase(org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBCCompileLog(org.jkiss.dbeaver.model.exec.compile.DBCCompileLog) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor)

Example 2 with OracleSchedulerJob

use of org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob in project dbeaver by dbeaver.

the class JobRunHandler method getSelectedJobs.

private List<OracleSchedulerJob> getSelectedJobs(ExecutionEvent event) {
    List<OracleSchedulerJob> objects = new ArrayList<>();
    final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
        for (Iterator<?> iter = ((IStructuredSelection) currentSelection).iterator(); iter.hasNext(); ) {
            final Object element = iter.next();
            final OracleSchedulerJob sourceJob = RuntimeUtils.getObjectAdapter(element, OracleSchedulerJob.class);
            if (sourceJob != null) {
                objects.add(sourceJob);
            }
        }
    }
    if (objects.isEmpty()) {
        final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
        final OracleSchedulerJob sourceJob = RuntimeUtils.getObjectAdapter(activePart, OracleSchedulerJob.class);
        if (sourceJob != null) {
            objects.add(sourceJob);
        }
    }
    return objects;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) OracleSchedulerJob(org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with OracleSchedulerJob

use of org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob in project dbeaver by serge-rider.

the class JobRunHandler method getSelectedJobs.

private List<OracleSchedulerJob> getSelectedJobs(ExecutionEvent event) {
    List<OracleSchedulerJob> objects = new ArrayList<>();
    final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
        for (Iterator<?> iter = ((IStructuredSelection) currentSelection).iterator(); iter.hasNext(); ) {
            final Object element = iter.next();
            final OracleSchedulerJob sourceJob = RuntimeUtils.getObjectAdapter(element, OracleSchedulerJob.class);
            if (sourceJob != null) {
                objects.add(sourceJob);
            }
        }
    }
    if (objects.isEmpty()) {
        final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
        final OracleSchedulerJob sourceJob = RuntimeUtils.getObjectAdapter(activePart, OracleSchedulerJob.class);
        if (sourceJob != null) {
            objects.add(sourceJob);
        }
    }
    return objects;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) OracleSchedulerJob(org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with OracleSchedulerJob

use of org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob in project dbeaver by dbeaver.

the class JobRunHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
    final List<OracleSchedulerJob> objects = getSelectedJobs(event);
    if (!objects.isEmpty()) {
        if (activePart instanceof EntityEditor) {
            // Save editor before run
            // Use null monitor as entity editor has its own detached job for save
            EntityEditor entityEditor = (EntityEditor) activePart;
            if (entityEditor.isDirty()) {
                NullProgressMonitor monitor = new NullProgressMonitor();
                entityEditor.doSave(monitor);
                if (monitor.isCanceled()) {
                    // Save failed - doesn't make sense to compile
                    return null;
                }
            }
        }
        final Shell activeShell = HandlerUtil.getActiveShell(event);
        if (objects.size() == 1) {
            final OracleSchedulerJob job = objects.get(0);
            final DBCCompileLog compileLog = new DBCCompileLogBase();
            compileLog.clearLog();
            Throwable error = null;
            try {
                UIUtils.runInProgressService(monitor -> {
                    try {
                        runJob(monitor, compileLog, job);
                    } catch (DBCException e) {
                        throw new InvocationTargetException(e);
                    }
                });
                if (compileLog.getError() != null) {
                    error = compileLog.getError();
                }
            } catch (InvocationTargetException e) {
                error = e.getTargetException();
            } catch (InterruptedException e) {
                return null;
            }
            if (error != null) {
                DBWorkbench.getPlatformUI().showError("Unexpected run schedule error", null, error);
            } else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
                // Show compile errors
                int line = -1, position = -1;
                StringBuilder fullMessage = new StringBuilder();
                for (DBCCompileError oce : compileLog.getErrorStack()) {
                    fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
                    if (line < 0) {
                        line = oce.getLine();
                        position = oce.getPosition();
                    }
                }
                String errorTitle = job.getName() + " run schedule failed";
                DBWorkbench.getPlatformUI().showError(errorTitle, fullMessage.toString());
            } else {
                String message = job.getName() + " successfully scheduled to run";
                UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
            }
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OracleSchedulerJob(org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBCCompileLogBase(org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBCCompileLog(org.jkiss.dbeaver.model.exec.compile.DBCCompileLog) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)4 OracleSchedulerJob (org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Shell (org.eclipse.swt.widgets.Shell)2 OracleSourceObject (org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 DBCCompileError (org.jkiss.dbeaver.model.exec.compile.DBCCompileError)2 DBCCompileLog (org.jkiss.dbeaver.model.exec.compile.DBCCompileLog)2 DBCCompileLogBase (org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase)2 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)2