use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class ResultSetValueController method getValueManager.
@Override
public IValueManager getValueManager() {
DBSAttributeBase valueType = binding.getPresentationAttribute();
final DBCExecutionContext executionContext = getExecutionContext();
Class<?> valueObjectType = getValueHandler().getValueObjectType(valueType);
if (valueObjectType == Object.class) {
// Try to get type from value itself
Object value = getValue();
if (value != null) {
valueObjectType = value.getClass();
}
}
return ValueManagerRegistry.findValueManager(executionContext == null ? null : executionContext.getDataSource(), valueType, valueObjectType);
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class ResultSetValueController method getColumnId.
@NotNull
@Override
public String getColumnId() {
DBCExecutionContext context = getExecutionContext();
DBCAttributeMetaData metaAttribute = binding.getMetaAttribute();
return DBUtils.getSimpleQualifiedName(context == null ? null : context.getDataSource().getContainer().getName(), metaAttribute.getEntityName(), metaAttribute.getName());
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class SQLContextInformer method searchInformation.
public void searchInformation(IRegion region) {
initEditorCache();
ITextViewer textViewer = editor.getTextViewer();
final DBCExecutionContext executionContext = editor.getExecutionContext();
if (region == null || textViewer == null || executionContext == null) {
return;
}
IDocument document = textViewer.getDocument();
if (document == null) {
return;
}
SQLWordPartDetector wordDetector = new SQLWordPartDetector(document, syntaxManager, region.getOffset());
wordRegion = wordDetector.detectIdentifier(document, region);
if (wordRegion.word.length() == 0) {
return;
}
String fullName = wordRegion.identifier;
String tableName = wordRegion.word;
boolean caseSensitive = false;
if (wordDetector.isQuoted(tableName)) {
tableName = DBUtils.getUnQuotedIdentifier(tableName, syntaxManager.getQuoteSymbol());
caseSensitive = true;
}
String[] containerNames = null;
if (!CommonUtils.equalObjects(fullName, tableName)) {
int divPos = fullName.indexOf(syntaxManager.getStructSeparator());
if (divPos != -1) {
String[] parts = ArrayUtils.toArray(String.class, CommonUtils.splitString(fullName, syntaxManager.getStructSeparator()));
tableName = parts[parts.length - 1];
containerNames = ArrayUtils.remove(String.class, parts, parts.length - 1);
for (int i = 0; i < containerNames.length; i++) {
if (wordDetector.isQuoted(containerNames[i])) {
containerNames[i] = DBUtils.getUnQuotedIdentifier(containerNames[i], syntaxManager.getQuoteSymbol());
}
containerNames[i] = DBObjectNameCaseTransformer.transformName(editor.getDataSource(), containerNames[i]);
}
if (wordDetector.isQuoted(tableName)) {
tableName = DBUtils.getUnQuotedIdentifier(tableName, syntaxManager.getQuoteSymbol());
}
} else {
// Full name could be quoted
if (wordDetector.isQuoted(fullName)) {
String unquotedName = DBUtils.getUnQuotedIdentifier(tableName, syntaxManager.getQuoteSymbol());
if (unquotedName.equals(tableName)) {
caseSensitive = true;
}
}
}
}
final SQLDialect dialect = syntaxManager.getDialect();
keywordType = dialect.getKeywordType(fullName);
keywords = new String[] { fullName };
if (keywordType == DBPKeywordType.KEYWORD || keywordType == DBPKeywordType.FUNCTION) {
// Skip keywords
return;
}
DBSStructureAssistant structureAssistant = DBUtils.getAdapter(DBSStructureAssistant.class, editor.getDataSource());
if (structureAssistant == null) {
return;
}
final Map<String, ObjectLookupCache> contextCache = getLinksCache();
if (contextCache == null) {
return;
}
ObjectLookupCache tlc = contextCache.get(fullName);
if (tlc == null) {
// Start new word finder job
tlc = new ObjectLookupCache();
contextCache.put(fullName, tlc);
TablesFinderJob job = new TablesFinderJob(executionContext, structureAssistant, containerNames, tableName, caseSensitive, tlc);
job.schedule();
}
if (tlc.loading) {
// Wait for 1000ms maximum
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// interrupted - just go further
break;
}
if (!tlc.loading) {
break;
}
Display.getCurrent().readAndDispatch();
}
}
if (!tlc.loading) {
synchronized (this) {
objectReferences = tlc.references;
}
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext 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);
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class SQLDataTypeResolver method resolveAll.
@Override
protected String[] resolveAll(final TemplateContext context) {
final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
if (executionContext == null) {
return super.resolveAll(context);
}
DBPDataTypeProvider dataTypeProvider = DBUtils.getAdapter(DBPDataTypeProvider.class, executionContext.getDataSource());
if (dataTypeProvider != null) {
final Collection<? extends DBSDataType> localDataTypes = dataTypeProvider.getLocalDataTypes();
if (!CommonUtils.isEmpty(localDataTypes)) {
String[] result = new String[localDataTypes.size()];
int index = 0;
for (DBSDataType dataType : localDataTypes) {
result[index++] = dataType.getName();
}
return result;
}
}
return super.resolveAll(context);
}
Aggregations