Search in sources :

Example 1 with DBCCompileLog

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

the class OracleObjectValidateAction method handleExecute.

@Override
public void handleExecute(DBCSession session, Throwable error) throws DBCException {
    if (error != null) {
        return;
    }
    DBCCompileLog log = new DBCCompileLogBase();
    CompileHandler.logObjectErrors((JDBCSession) session, log, object, getObjectType());
    if (!log.getErrorStack().isEmpty()) {
        StringBuilder message = new StringBuilder();
        message.append("Error during ").append(getObjectType().getTypeName()).append(" '").append(object.getName()).append("' validation:");
        for (DBCCompileError e : log.getErrorStack()) {
            message.append("\n");
            message.append(e.toString());
        }
        throw new DBCException(message.toString());
    }
}
Also used : DBCCompileLogBase(org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase) DBCCompileLog(org.jkiss.dbeaver.model.exec.compile.DBCCompileLog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError)

Example 2 with DBCCompileLog

use of org.jkiss.dbeaver.model.exec.compile.DBCCompileLog 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 3 with DBCCompileLog

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

the class CompileHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final List<OracleSourceObject> objects = getSelectedObjects(event);
    if (!objects.isEmpty()) {
        final Shell activeShell = HandlerUtil.getActiveShell(event);
        if (objects.size() == 1) {
            final OracleSourceObject unit = objects.get(0);
            DBCSourceHost sourceHost = null;
            final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
            if (activePart != null) {
                sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
                if (sourceHost == null) {
                    sourceHost = activePart.getAdapter(DBCSourceHost.class);
                }
            }
            if (sourceHost != null && sourceHost.getSourceObject() != unit) {
                sourceHost = null;
            }
            final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
            compileLog.clearLog();
            Throwable error = null;
            try {
                DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            compileUnit(monitor, compileLog, unit);
                        } 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) {
                UIUtils.showErrorDialog(activeShell, "Unexpected compilation 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();
                    }
                }
                // If compiled object is currently open in editor - try to position on error line
                if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
                    sourceHost.positionSource(line, position);
                    activePart.getSite().getPage().activate(activePart);
                }
                String errorTitle = unit.getName() + " compilation failed";
                if (sourceHost != null) {
                    sourceHost.setCompileInfo(errorTitle, true);
                    sourceHost.showCompileLog();
                }
                UIUtils.showErrorDialog(activeShell, errorTitle, fullMessage.toString());
            } else {
                String message = unit.getName() + " compiled successfully";
                if (sourceHost != null) {
                    sourceHost.setCompileInfo(message, true);
                }
                UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
            }
        } else {
            OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
            dialog.open();
        }
    }
    return null;
}
Also used : DBCSourceHost(org.jkiss.dbeaver.model.exec.compile.DBCSourceHost) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError) InvocationTargetException(java.lang.reflect.InvocationTargetException) OracleCompilerDialog(org.jkiss.dbeaver.ext.oracle.views.OracleCompilerDialog) 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) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 4 with DBCCompileLog

use of org.jkiss.dbeaver.model.exec.compile.DBCCompileLog in project dbeaver by dbeaver.

the class CompileHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
    final List<OracleSourceObject> objects = getSelectedObjects(event);
    if (!objects.isEmpty()) {
        if (activePart instanceof EntityEditor) {
            // Save editor before compile
            // 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 OracleSourceObject unit = objects.get(0);
            DBCSourceHost sourceHost = null;
            if (activePart != null) {
                sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
                if (sourceHost == null) {
                    sourceHost = activePart.getAdapter(DBCSourceHost.class);
                }
            }
            if (sourceHost != null && sourceHost.getSourceObject() != unit) {
                sourceHost = null;
            }
            final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
            compileLog.clearLog();
            Throwable error = null;
            try {
                DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            compileUnit(monitor, compileLog, unit);
                        } 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) {
                DBUserInterface.getInstance().showError("Unexpected compilation 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();
                    }
                }
                // If compiled object is currently open in editor - try to position on error line
                if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
                    sourceHost.positionSource(line, position);
                    activePart.getSite().getPage().activate(activePart);
                }
                String errorTitle = unit.getName() + " compilation failed";
                if (sourceHost != null) {
                    sourceHost.setCompileInfo(errorTitle, true);
                    sourceHost.showCompileLog();
                }
                DBUserInterface.getInstance().showError(errorTitle, fullMessage.toString());
            } else {
                String message = unit.getName() + " compiled successfully";
                if (sourceHost != null) {
                    sourceHost.setCompileInfo(message, true);
                }
                UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
            }
        } else {
            OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
            dialog.open();
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DBCSourceHost(org.jkiss.dbeaver.model.exec.compile.DBCSourceHost) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError) InvocationTargetException(java.lang.reflect.InvocationTargetException) OracleCompilerDialog(org.jkiss.dbeaver.ext.oracle.views.OracleCompilerDialog) 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) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 5 with DBCCompileLog

use of org.jkiss.dbeaver.model.exec.compile.DBCCompileLog in project dbeaver by dbeaver.

the class OracleObjectValidateAction method afterExecute.

@Override
public void afterExecute(DBCSession session, Throwable error) throws DBCException {
    if (error != null) {
        return;
    }
    DBCCompileLog log = new DBCCompileLogBase();
    CompileHandler.logObjectErrors((JDBCSession) session, log, object, getObjectType());
    if (!log.getErrorStack().isEmpty()) {
        StringBuilder message = new StringBuilder();
        message.append("Error during ").append(getObjectType().getTypeName()).append(" '").append(object.getName()).append("' validation:");
        for (DBCCompileError e : log.getErrorStack()) {
            message.append("\n");
            message.append(e.toString());
        }
        throw new DBCException(message.toString());
    }
}
Also used : DBCCompileLogBase(org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase) DBCCompileLog(org.jkiss.dbeaver.model.exec.compile.DBCCompileLog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError)

Aggregations

DBCException (org.jkiss.dbeaver.model.exec.DBCException)6 DBCCompileError (org.jkiss.dbeaver.model.exec.compile.DBCCompileError)6 DBCCompileLog (org.jkiss.dbeaver.model.exec.compile.DBCCompileLog)6 DBCCompileLogBase (org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Shell (org.eclipse.swt.widgets.Shell)4 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)4 OracleSourceObject (org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)3 DBCSourceHost (org.jkiss.dbeaver.model.exec.compile.DBCSourceHost)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 OracleCompilerDialog (org.jkiss.dbeaver.ext.oracle.views.OracleCompilerDialog)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)2 OracleSchedulerJob (org.jkiss.dbeaver.ext.oracle.model.OracleSchedulerJob)1