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;
}
}
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;
}
}
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;
}
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)));
}
}
}
}
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();
}
Aggregations