Search in sources :

Example 31 with DBRRunnableWithProgress

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

the class ContentPanelEditor method primeEditorValue.

@Override
public void primeEditorValue(@Nullable final Object value) throws DBException {
    final DBDContent content = (DBDContent) valueController.getValue();
    if (content == null) {
        valueController.showMessage("NULL content value. Must be DBDContent.", DBPMessageType.ERROR);
        return;
    }
    if (streamEditor == null) {
        valueController.showMessage("NULL content editor.", DBPMessageType.ERROR);
        return;
    }
    DBeaverUI.runInUI(valueController.getValueSite().getWorkbenchWindow(), new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                streamEditor.primeEditorValue(monitor, control, content);
            } catch (Throwable e) {
                log.debug(e);
                valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
            }
        }
    });
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with DBRRunnableWithProgress

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

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

the class NavigatorHandlerObjectCreateCopy method pasteResource.

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

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    final IFile targetFile = targetFolder.getFile(new Path(file.getName()));
                    if (targetFile.exists()) {
                        throw new IOException("Target file '" + targetFile.getFullPath() + "' already exists");
                    }
                    try (InputStream is = new FileInputStream(file)) {
                        targetFile.create(is, true, monitor.getNestedMonitor());
                    }
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(null, "Copy error", "Error copying resource", e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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)

Example 34 with DBRRunnableWithProgress

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

the class DataSourceHandler method checkAndCloseActiveTransaction.

public static boolean checkAndCloseActiveTransaction(DBCExecutionContext[] contexts) {
    if (contexts == null) {
        return true;
    }
    Boolean commitTxn = null;
    for (final DBCExecutionContext context : contexts) {
        // First rollback active transaction
        try {
            if (QMUtils.isTransactionActive(context)) {
                if (commitTxn == null) {
                    // Ask for confirmation
                    TransactionCloseConfirmer closeConfirmer = new TransactionCloseConfirmer(context.getDataSource().getContainer().getName());
                    DBeaverUI.syncExec(closeConfirmer);
                    switch(closeConfirmer.result) {
                        case IDialogConstants.YES_ID:
                            commitTxn = true;
                            break;
                        case IDialogConstants.NO_ID:
                            commitTxn = false;
                            break;
                        default:
                            return false;
                    }
                }
                final boolean commit = commitTxn;
                DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        closeActiveTransaction(monitor, context, commit);
                    }
                });
            }
        } catch (Throwable e) {
            log.warn("Can't rollback active transaction before disconnect", e);
        }
    }
    return true;
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 35 with DBRRunnableWithProgress

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

the class DataTransferWizard method performFinish.

@Override
public boolean performFinish() {
    // Save settings
    getSettings().saveTo(getDialogSettings());
    // Start consumers
    try {
        DBeaverUI.run(getContainer(), true, true, new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    for (DataTransferPipe pipe : settings.getDataPipes()) {
                        pipe.getConsumer().startTransfer(monitor);
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(getShell(), "Transfer init failed", "Can't start data transfer", e.getTargetException());
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    // Run export jobs
    executeJobs();
    // Done
    return true;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) 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