use of org.jkiss.dbeaver.model.struct.DBSObjectReference in project dbeaver by serge-rider.
the class SearchMetadataQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
List<DBSObjectType> objectTypes = params.getObjectTypes();
String objectNameMask = params.getObjectNameMask();
if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_STARTS_WITH) {
if (!objectNameMask.endsWith("%")) {
//$NON-NLS-1$
//$NON-NLS-1$
objectNameMask = objectNameMask + "%";
}
} else if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_CONTAINS) {
if (!objectNameMask.startsWith("%")) {
//$NON-NLS-1$
//$NON-NLS-1$
objectNameMask = "%" + objectNameMask;
}
if (!objectNameMask.endsWith("%")) {
//$NON-NLS-1$
//$NON-NLS-1$
objectNameMask = objectNameMask + "%";
}
}
DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
Collection<DBSObjectReference> objects = structureAssistant.findObjectsByMask(localMonitor, params.getParentObject(), objectTypes.toArray(new DBSObjectType[objectTypes.size()]), objectNameMask, params.isCaseSensitive(), true, params.getMaxResults());
for (DBSObjectReference reference : objects) {
if (monitor.isCanceled()) {
break;
}
try {
DBSObject object = reference.resolveObject(localMonitor);
if (object != null) {
DBNNode node = navigatorModel.getNodeByObject(localMonitor, object, false);
if (node != null) {
searchResult.addObjects(Collections.singletonList(node));
}
}
} catch (DBException e) {
log.error(e);
}
}
return Status.OK_STATUS;
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectReference in project dbeaver by serge-rider.
the class SQLHyperlinkDetector method detectHyperlinks.
@Nullable
@Override
public synchronized IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
this.contextInformer.searchInformation(region);
if (!this.contextInformer.hasObjects()) {
// Long task - just return no links for now
return null;
} else {
// Create hyperlinks based on references
final SQLIdentifierDetector.WordRegion wordRegion = this.contextInformer.getWordRegion();
final IRegion hlRegion = new Region(wordRegion.identStart, wordRegion.identEnd - wordRegion.identStart);
final List<DBSObjectReference> references = this.contextInformer.getObjectReferences();
IHyperlink[] links = new IHyperlink[references.size()];
for (int i = 0, objectsSize = references.size(); i < objectsSize; i++) {
links[i] = new EntityHyperlink(contextInformer.getEditor().getSite(), references.get(i), hlRegion);
}
return links;
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectReference in project dbeaver by serge-rider.
the class SQLInformationProvider method getInformation2.
@Override
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
if (implementation != null) {
Object s = implementation.getHoverInfo2(textViewer, subject);
if (s != null) {
return s;
}
}
//SQLCompletionProposal proposal = new SQLCompletionProposal();
SQLContextInformer informer = new SQLContextInformer(editor, editor.getSyntaxManager());
informer.searchInformation(subject);
DBSObject object = null;
if (informer.hasObjects()) {
// Make object description
DBRProgressMonitor monitor = VoidProgressMonitor.INSTANCE;
final DBSObjectReference objectRef = informer.getObjectReferences().get(0);
try {
object = objectRef.resolveObject(monitor);
} catch (DBException e) {
// Can't resolve
return e.getMessage();
}
} else if (ArrayUtils.isEmpty(informer.getKeywords())) {
return null;
}
return SQLContextInformer.readAdditionalProposalInfo(null, editor.getDataSource(), object, informer.getKeywords(), informer.getKeywordType());
}
Aggregations