Search in sources :

Example 11 with DBRProgressMonitor

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

the class SSHTunnelImpl method closeTunnel.

@Override
public void closeTunnel(DBRProgressMonitor monitor) throws DBException, IOException {
    if (session != null) {
        RuntimeUtils.runTask(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    session.disconnect();
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        }, "Close SSH session", 1000);
        session = null;
    }
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 12 with DBRProgressMonitor

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

the class SQLUtils method convertStreamToSQL.

public static String convertStreamToSQL(DBSAttributeBase attribute, DBDContent content, DBDValueHandler valueHandler, SQLDataSource dataSource) {
    try {
        DBRProgressMonitor monitor = VoidProgressMonitor.INSTANCE;
        if (valueHandler instanceof DBDContentValueHandler) {
            StringWriter buffer = new StringWriter();
            ((DBDContentValueHandler) valueHandler).writeStreamValue(monitor, dataSource, attribute, content, buffer);
            return buffer.toString();
        } else {
            if (ContentUtils.isTextContent(content)) {
                String strValue = ContentUtils.getContentStringValue(monitor, content);
                strValue = dataSource.getSQLDialect().escapeString(strValue);
                return "'" + strValue + "'";
            } else {
                byte[] binValue = ContentUtils.getContentBinaryValue(monitor, content);
                return dataSource.getSQLDialect().getNativeBinaryFormatter().toString(binValue, 0, binValue.length);
            }
        }
    } catch (Throwable e) {
        log.warn(e);
        return SQLConstants.NULL_VALUE;
    }
}
Also used : StringWriter(java.io.StringWriter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 13 with DBRProgressMonitor

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

the class CompareObjectsWizard method performFinish.

@Override
public boolean performFinish() {
    // Save settings
    getSettings().saveTo(getDialogSettings());
    showError(null);
    // Compare
    final CompareObjectsExecutor executor = new CompareObjectsExecutor(settings);
    try {
        DBeaverUI.run(getContainer(), true, true, new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    CompareReport report = generateReport(monitor, executor);
                    renderReport(monitor, report);
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
        UIUtils.showMessageBox(getShell(), "Objects compare", "Objects compare finished", SWT.ICON_INFORMATION);
    } catch (InvocationTargetException e) {
        if (executor.getInitializeError() != null) {
            showError(executor.getInitializeError().getMessage());
        } else {
            log.error(e.getTargetException());
            showError(e.getTargetException().getMessage());
        }
        return false;
    } catch (InterruptedException e) {
        showError("Compare interrupted");
        return false;
    } finally {
        executor.dispose();
    }
    // 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)

Example 14 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor 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().getNavigatorNode();
    if (node == null) {
        return;
    }
    final DBSObject object = node.getObject();
    if (!node.getMeta().isStandaloneNode()) {
        // Collect tabs from navigator tree model
        DBRRunnableWithProgress tabsCollector = new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) {
                collectNavigatorTabs(monitor, part, node, tabList);
            }
        };
        try {
            if (node.needsInitialization()) {
                DBeaverUI.runInProgressService(tabsCollector);
            } else {
                tabsCollector.run(VoidProgressMonitor.INSTANCE);
            }
        } catch (InvocationTargetException e) {
            log.error(e.getTargetException());
        } catch (InterruptedException e) {
        // just go further
        }
    }
    // Query for entity editors
    List<EntityEditorDescriptor> editors = EntityEditorsRegistry.getInstance().getEntityEditors(object, 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 : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) EntityEditorDescriptor(org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 15 with DBRProgressMonitor

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

the class SQLEditor method dumpServerOutput.

private void dumpServerOutput(@NotNull final DBCExecutionContext executionContext, @NotNull final DBCServerOutputReader outputReader) {
    new AbstractJob("Dump server output") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            final StringWriter dump = new StringWriter();
            try {
                outputReader.readServerOutput(monitor, executionContext, new PrintWriter(dump, true));
                final String dumpString = dump.toString();
                if (!dumpString.isEmpty()) {
                    DBeaverUI.asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (outputViewer.isDisposed()) {
                                return;
                            }
                            try {
                                IOUtils.copyText(new StringReader(dumpString), outputViewer.getOutputWriter());
                            } catch (IOException e) {
                                log.error(e);
                            }
                            if (outputViewer.isHasNewOutput()) {
                                outputViewer.scrollToEnd();
                                CTabItem outputItem = UIUtils.getTabItem(resultTabs, outputViewer);
                                if (outputItem != null && outputItem != resultTabs.getSelection()) {
                                    outputItem.setImage(IMG_OUTPUT_ALERT);
                                } else {
                                    toolOutputItem.setImage(IMG_OUTPUT_ALERT);
                                }
                            }
                        }
                    });
                }
            } catch (Exception e) {
                log.error(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) CTabItem(org.eclipse.swt.custom.CTabItem) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Aggregations

DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)79 DBException (org.jkiss.dbeaver.DBException)45 InvocationTargetException (java.lang.reflect.InvocationTargetException)36 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)30 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)14 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)10 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 ArrayList (java.util.ArrayList)8 IStatus (org.eclipse.core.runtime.IStatus)8 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)6 GridData (org.eclipse.swt.layout.GridData)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)6 List (java.util.List)5 NotNull (org.jkiss.code.NotNull)5 File (java.io.File)4 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4