Search in sources :

Example 6 with DBCExecutionContext

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);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

Example 7 with DBCExecutionContext

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());
}
Also used : DBCAttributeMetaData(org.jkiss.dbeaver.model.exec.DBCAttributeMetaData) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) NotNull(org.jkiss.code.NotNull)

Example 8 with DBCExecutionContext

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;
        }
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) ITextViewer(org.eclipse.jface.text.ITextViewer) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with DBCExecutionContext

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);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 10 with DBCExecutionContext

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);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBPDataTypeProvider(org.jkiss.dbeaver.model.DBPDataTypeProvider)

Aggregations

DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)23 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)7 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)5 ArrayList (java.util.ArrayList)3 DBException (org.jkiss.dbeaver.DBException)3 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 NotNull (org.jkiss.code.NotNull)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2 DBCTransactionManager (org.jkiss.dbeaver.model.exec.DBCTransactionManager)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 QMEventFilter (org.jkiss.dbeaver.model.qm.QMEventFilter)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)2 IDocument (org.eclipse.jface.text.IDocument)1