Search in sources :

Example 1 with DBCCompileError

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

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

the class CompileHandler method logObjectErrors.

public static boolean logObjectErrors(JDBCSession session, DBCCompileLog compileLog, OracleSourceObject unit, OracleObjectType objectType) {
    try {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM SYS.ALL_ERRORS WHERE OWNER=? AND NAME=? AND TYPE=? ORDER BY SEQUENCE")) {
            dbStat.setString(1, unit.getSchema().getName());
            dbStat.setString(2, unit.getName());
            dbStat.setString(3, objectType.getTypeName());
            try (ResultSet dbResult = dbStat.executeQuery()) {
                boolean hasErrors = false;
                while (dbResult.next()) {
                    DBCCompileError error = new DBCCompileError("ERROR".equals(dbResult.getString("ATTRIBUTE")), dbResult.getString("TEXT"), dbResult.getInt("LINE"), dbResult.getInt("POSITION"));
                    hasErrors = true;
                    if (error.isError()) {
                        compileLog.error(error);
                    } else {
                        compileLog.warn(error);
                    }
                }
                return !hasErrors;
            }
        }
    } catch (Exception e) {
        log.error("Can't read user errors", e);
        return false;
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) ResultSet(java.sql.ResultSet) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError) DBCException(org.jkiss.dbeaver.model.exec.DBCException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with DBCCompileError

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

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

the class ObjectCompilerLogViewer method log.

@Override
protected void log(final int type, final Object message, final Throwable t) {
    super.log(type, message, t);
    DBeaverUI.syncExec(new Runnable() {

        @Override
        public void run() {
            if (infoTable == null || infoTable.isDisposed()) {
                return;
            }
            int color = -1;
            switch(type) {
                case LOG_LEVEL_TRACE:
                    color = SWT.COLOR_DARK_BLUE;
                    break;
                case LOG_LEVEL_DEBUG:
                case LOG_LEVEL_INFO:
                    break;
                case LOG_LEVEL_WARN:
                    color = SWT.COLOR_DARK_YELLOW;
                    break;
                case LOG_LEVEL_ERROR:
                case LOG_LEVEL_FATAL:
                    color = SWT.COLOR_DARK_RED;
                    break;
                default:
                    break;
            }
            String messageStr;
            DBCCompileError error = null;
            if (message instanceof DBCCompileError) {
                error = (DBCCompileError) message;
                messageStr = error.getMessage();
            } else {
                messageStr = CommonUtils.toString(message);
            }
            //$NON-NLS-1$
            StringTokenizer st = new StringTokenizer(messageStr, "\n");
            while (st.hasMoreTokens()) {
                final TableItem item = new TableItem(infoTable, SWT.NONE);
                item.setText(0, st.nextToken());
                if (error != null && error.getLine() > 0) {
                    item.setText(1, String.valueOf(((DBCCompileError) message).getLine()));
                    item.setText(2, String.valueOf(((DBCCompileError) message).getPosition()));
                }
                if (color != -1) {
                    item.setForeground(infoTable.getDisplay().getSystemColor(color));
                }
                infoTable.showItem(item);
            }
            if (t != null) {
                String prevMessage = null;
                for (Throwable ex = t; error != null; ex = ex.getCause()) {
                    final String errorMessage = ex.getMessage();
                    if (errorMessage == null || errorMessage.equals(prevMessage)) {
                        continue;
                    }
                    prevMessage = errorMessage;
                    TableItem stackItem = new TableItem(infoTable, SWT.NONE);
                    stackItem.setText(errorMessage);
                    stackItem.setForeground(infoTable.getDisplay().getSystemColor(SWT.COLOR_RED));
                    infoTable.showItem(stackItem);
                }
            }
        }
    });
}
Also used : StringTokenizer(java.util.StringTokenizer) TableItem(org.eclipse.swt.widgets.TableItem) DBCCompileError(org.jkiss.dbeaver.model.exec.compile.DBCCompileError)

Aggregations

DBCCompileError (org.jkiss.dbeaver.model.exec.compile.DBCCompileError)4 DBCException (org.jkiss.dbeaver.model.exec.DBCException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBCCompileLog (org.jkiss.dbeaver.model.exec.compile.DBCCompileLog)2 DBCCompileLogBase (org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase)2 ResultSet (java.sql.ResultSet)1 StringTokenizer (java.util.StringTokenizer)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 Shell (org.eclipse.swt.widgets.Shell)1 TableItem (org.eclipse.swt.widgets.TableItem)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 OracleSourceObject (org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)1 OracleCompilerDialog (org.jkiss.dbeaver.ext.oracle.views.OracleCompilerDialog)1 DBCSourceHost (org.jkiss.dbeaver.model.exec.compile.DBCSourceHost)1 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)1