use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class DiagramObjectCollector method generateEntityList.
public static List<ERDEntity> generateEntityList(final EntityDiagram diagram, Collection<DBPNamedObject> objects) {
final List<DBSObject> roots = new ArrayList<>();
for (DBPNamedObject object : objects) {
if (object instanceof DBSObject) {
roots.add((DBSObject) object);
}
}
final List<ERDEntity> entities = new ArrayList<>();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DiagramObjectCollector collector = new DiagramObjectCollector(diagram);
try {
collector.generateDiagramObjects(monitor, roots);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
entities.addAll(collector.getDiagramEntities());
}
});
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
} catch (InterruptedException e) {
// interrupted
}
return entities;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
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) {
DBUserInterface.getInstance().showError("Transfer init failed", "Can't start data transfer", e.getTargetException());
return false;
} catch (InterruptedException e) {
return false;
}
// Run export jobs
executeJobs();
// Done
return true;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
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;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
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) {
DBUserInterface.getInstance().showError("Copy error", "Error copying resource", e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class NavigatorHandlerObjectCreateCopy method pasteResource.
private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
final IResource resource = resourceNode.getResource();
final IResource targetResource = toFolder.getResource();
assert resource != null;
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 {
copyResource(monitor, resource, targetFolder);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError("Copy error", "Error copying resource", e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
Aggregations