use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class TasksJob method run.
@Override
protected IStatus run(DBRProgressMonitor monitor) {
monitor.beginTask(getName(), tasks.size());
boolean ignoreErrors = false;
for (int i = 0; i < tasks.size(); ) {
DBRRunnableWithProgress task = tasks.get(i);
if (monitor.isCanceled()) {
break;
}
try {
task.run(monitor);
} catch (InvocationTargetException e) {
if (tasks.size() == 1) {
DBWorkbench.getPlatformUI().showError(getName(), null, e.getTargetException());
} else if (!ignoreErrors) {
boolean keepRunning = true;
switch(DBWorkbench.getPlatformUI().showErrorStopRetryIgnore(getName(), e.getTargetException(), true)) {
case STOP:
keepRunning = false;
break;
case RETRY:
// just make it again
continue;
case IGNORE:
// Just do nothing
break;
case IGNORE_ALL:
ignoreErrors = true;
break;
}
if (!keepRunning) {
break;
}
}
} catch (InterruptedException e) {
// Ignore
}
monitor.worked(1);
i++;
}
monitor.done();
return Status.OK_STATUS;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class StreamProducerPageSettings method chooseSourceFile.
private void chooseSourceFile(DataTransferPipe pipe) {
List<String> extensions = new ArrayList<>();
String extensionProp = CommonUtils.toString(propertySource.getPropertyValue(null, "extension"));
for (String ext : extensionProp.split(",")) {
extensions.add("*." + ext);
}
extensions.add("*");
DBRRunnableWithProgress initializer = null;
if (pipe.getConsumer() != null && pipe.getConsumer().getTargetObjectContainer() != null) {
File[] files = DialogUtils.openFileList(getShell(), "Select input files", extensions.toArray(new String[0]));
if (files != null && files.length > 0) {
initializer = monitor -> updateMultiConsumers(monitor, pipe, files);
}
} else {
File file = DialogUtils.openFile(getShell(), extensions.toArray(new String[0]));
if (file != null) {
initializer = monitor -> updateSingleConsumer(monitor, pipe, file);
}
}
if (initializer != null) {
try {
getWizard().getRunnableContext().run(true, true, initializer);
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Column mappings error", "Error reading column mappings from stream", e.getTargetException());
return;
} catch (InterruptedException e) {
// ignore
}
}
reloadPipes();
updatePageCompletion();
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class ResultSetFilterPanel method getProposals.
@Override
public IContentProposal[] getProposals(String contents, int position) {
if (!viewer.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_FILTER_AUTO_COMPLETE_PROPOSIAL)) {
return null;
}
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
DBPDataSource dataSource = viewer.getDataSource();
if (dataSource != null) {
syntaxManager.init(dataSource);
}
SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
String word = wordDetector.getFullWord();
final List<IContentProposal> proposals = new ArrayList<>();
if (CommonUtils.isEmptyTrimmed(word))
word = contents;
word = word.toLowerCase(Locale.ENGLISH);
String attrName = word;
final DBRRunnableWithProgress reader = monitor -> {
DBDAttributeBinding[] attributes = viewer.getModel().getAttributes();
for (DBDAttributeBinding attribute : attributes) {
if (attribute.isCustom()) {
continue;
}
final String name = DBUtils.getUnQuotedIdentifier(attribute.getDataSource(), attribute.getName());
if (CommonUtils.isEmpty(attrName) || name.toLowerCase(Locale.ENGLISH).startsWith(attrName)) {
final String content = DBUtils.getQuotedIdentifier(attribute) + " ";
proposals.add(new ContentProposalExt(content, attribute.getName(), DBInfoUtils.makeObjectDescription(monitor, attribute.getAttribute(), false), content.length(), DBValueFormatting.getObjectImage(attribute)));
}
}
};
SystemJob searchJob = new SystemJob("Extract attribute proposals", reader);
searchJob.schedule();
UIUtils.waitJobCompletion(searchJob);
String[] filterKeywords = { SQLConstants.KEYWORD_AND, SQLConstants.KEYWORD_OR, SQLConstants.KEYWORD_IS, SQLConstants.KEYWORD_NOT, SQLConstants.KEYWORD_NULL };
for (String kw : filterKeywords) {
if (attrName.isEmpty() || kw.startsWith(attrName.toUpperCase())) {
if (dataSource != null) {
kw = dataSource.getSQLDialect().storesUnquotedCase().transform(kw);
}
proposals.add(new ContentProposal(kw + " ", kw + ": SQL expression keyword"));
}
}
return proposals.toArray(new IContentProposal[0]);
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class ResultSetReferenceMenu method fillRefTablesActions.
static void fillRefTablesActions(@Nullable DBRProgressMonitor extMonitor, ResultSetViewer viewer, List<ResultSetRow> rows, DBSEntity singleSource, IMenuManager manager, boolean openInNewWindow) {
final List<DBSEntityAssociation> references = new ArrayList<>();
final List<DBSEntityAssociation> associations = new ArrayList<>();
DBRRunnableWithProgress refCollector = monitor -> {
try {
monitor.beginTask("Read references", 1);
Collection<? extends DBSEntityAssociation> refs = DBVUtils.getAllReferences(monitor, singleSource);
{
monitor.beginTask("Check references", refs.size());
for (DBSEntityAssociation ref : refs) {
if (monitor.isCanceled()) {
return;
}
monitor.subTask("Check references " + ref.getName());
boolean allMatch = true;
DBSEntityConstraint ownConstraint = ref.getReferencedConstraint();
if (ownConstraint instanceof DBSEntityReferrer) {
List<? extends DBSEntityAttributeRef> attributeReferences = ((DBSEntityReferrer) ownConstraint).getAttributeReferences(monitor);
if (attributeReferences != null) {
for (DBSEntityAttributeRef ownAttrRef : attributeReferences) {
if (viewer.getModel().getAttributeBinding(ownAttrRef.getAttribute()) == null) {
// Attribute is not in the list - skip this association
allMatch = false;
break;
}
}
} else {
allMatch = false;
}
}
if (allMatch) {
references.add(ref);
}
monitor.worked(1);
}
}
monitor.done();
if (monitor.isCanceled()) {
return;
}
monitor.beginTask("Read associations", 1);
Collection<? extends DBSEntityAssociation> fks = singleSource.getAssociations(monitor);
if (fks != null) {
monitor.beginTask("Check associations", fks.size());
for (DBSEntityAssociation fk : fks) {
if (monitor.isCanceled()) {
return;
}
monitor.subTask("Check association " + fk.getName());
boolean allMatch = true;
if (fk instanceof DBSEntityReferrer && fk.getReferencedConstraint() != null) {
for (DBSEntityAttributeRef ownAttr : ((DBSEntityReferrer) fk).getAttributeReferences(monitor)) {
if (viewer.getModel().getAttributeBinding(ownAttr.getAttribute()) == null) {
// Attribute is not in the list - skip this association
allMatch = false;
break;
}
}
}
if (allMatch) {
associations.add(fk);
}
monitor.worked(1);
}
}
monitor.done();
} catch (DBException e) {
throw new InvocationTargetException(e);
}
};
try {
if (extMonitor != null) {
refCollector.run(extMonitor);
} else {
UIUtils.runInProgressService(refCollector);
}
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Table References", "Error reading referencing tables for '" + singleSource.getName() + "'", e.getTargetException());
return;
} catch (InterruptedException e) {
return;
}
manager.removeAll();
if (CommonUtils.isEmpty(associations)) {
manager.add(NOFKS_ACTION);
} else {
manager.add(FKS_TITLE_ACTION);
manager.add(new Separator());
ArrayList<Action> entries = new ArrayList<>(associations.size());
for (DBSEntityAssociation association : associations) {
DBSEntity refTable = association.getReferencedConstraint().getParentObject();
entries.add(new Action(DBUtils.getObjectFullName(refTable, DBPEvaluationContext.UI) + " (" + association.getName() + ")", DBeaverIcons.getImageDescriptor(DBSEntityType.TABLE.getIcon())) {
@Override
public void run() {
new AbstractJob("Navigate association") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
viewer.navigateAssociation(new VoidProgressMonitor(), viewer.getModel(), association, rows, openInNewWindow);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
});
}
entries.sort(Comparator.comparing(Action::getText));
entries.forEach(manager::add);
}
manager.add(new Separator());
if (CommonUtils.isEmpty(references)) {
manager.add(NOREFS_ACTION);
} else {
manager.add(REFS_TITLE_ACTION);
manager.add(new Separator());
ArrayList<Action> entries = new ArrayList<>(references.size());
for (DBSEntityAssociation refAssociation : references) {
DBSEntity refTable = refAssociation.getParentObject();
entries.add(new Action(DBUtils.getObjectFullName(refTable, DBPEvaluationContext.UI) + " (" + refAssociation.getName() + ")", DBeaverIcons.getImageDescriptor(DBSEntityType.TABLE.getIcon())) {
@Override
public void run() {
new AbstractJob("Navigate reference") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
viewer.navigateReference(new VoidProgressMonitor(), viewer.getModel(), refAssociation, rows, openInNewWindow);
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
});
}
entries.sort(Comparator.comparing(Action::getText));
entries.forEach(manager::add);
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class SQLAttributeResolver method resolveAll.
@Override
protected String[] resolveAll(final TemplateContext context) {
final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
if (executionContext == null) {
return super.resolveAll(context);
}
TemplateVariable tableVariable = ((SQLContext) context).getTemplateVariable("table");
final String tableName = tableVariable == null ? null : tableVariable.getDefaultValue();
if (!CommonUtils.isEmpty(tableName)) {
final List<DBSEntityAttribute> attributes = new ArrayList<>();
DBRRunnableWithProgress runnable = new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<DBSEntity> entities = new ArrayList<>();
SQLEntityResolver.resolveTables(monitor, executionContext, context, entities);
if (!CommonUtils.isEmpty(entities)) {
DBSEntity table = DBUtils.findObject(entities, tableName);
if (table != null) {
attributes.addAll(CommonUtils.safeCollection(table.getAttributes(monitor)));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
};
RuntimeUtils.runTask(runnable, "Resolve attributes", 1000);
if (!CommonUtils.isEmpty(attributes)) {
String[] result = new String[attributes.size()];
for (int i = 0; i < attributes.size(); i++) {
DBSEntityAttribute entity = attributes.get(i);
result[i] = entity.getName();
}
return result;
}
}
return super.resolveAll(context);
}
Aggregations