Search in sources :

Example 41 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class MavenArtifact method getAvailableVersions.

@Nullable
public Collection<String> getAvailableVersions(DBRProgressMonitor monitor, String versionSpec) throws IOException {
    if (CommonUtils.isEmpty(versions) && !metadataLoaded) {
        loadMetadata(monitor);
    }
    if (!isVersionPattern(versionSpec)) {
        return versions;
    }
    // Filter versions according to spec
    Pattern versionPattern = null;
    VersionRange versionRange = null;
    if (versionSpec.startsWith("{") && versionSpec.endsWith("}")) {
        // Regex - find most recent version matching this pattern
        try {
            versionPattern = Pattern.compile(versionSpec.substring(1, versionSpec.length() - 1));
        } catch (Exception e) {
            log.error("Bad version pattern: " + versionSpec);
        }
    } else {
        try {
            versionRange = VersionRange.createFromVersionSpec(versionSpec);
        } catch (Exception e) {
            log.error("Bad version specification: " + versionSpec);
        }
    }
    List<String> filtered = new ArrayList<>();
    for (String version : versions) {
        boolean matches;
        if (versionPattern != null) {
            matches = versionPattern.matcher(version).matches();
        } else if (versionRange != null) {
            matches = versionRange.containsVersion(new DefaultArtifactVersion(version));
        } else {
            matches = true;
        }
        if (matches) {
            filtered.add(version);
        }
    }
    return filtered;
}
Also used : Pattern(java.util.regex.Pattern) DefaultArtifactVersion(org.jkiss.dbeaver.registry.maven.versioning.DefaultArtifactVersion) VersionRange(org.jkiss.dbeaver.registry.maven.versioning.VersionRange) XMLException(org.jkiss.utils.xml.XMLException) IOException(java.io.IOException) Nullable(org.jkiss.code.Nullable)

Example 42 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class DataTypeProviderRegistry method getDataTypeProvider.

////////////////////////////////////////////////////
// DataType providers
@Nullable
public DBDValueHandlerProvider getDataTypeProvider(@NotNull DBPDataSource dataSource, @NotNull DBSTypedObject typedObject) {
    DBPDriver driver = dataSource.getContainer().getDriver();
    if (!(driver instanceof DriverDescriptor)) {
        log.warn("Bad datasource specified (driver is not recognized by registry) - " + dataSource);
        return null;
    }
    DataSourceProviderDescriptor dsProvider = ((DriverDescriptor) driver).getProviderDescriptor();
    // First try to find type provider for specific datasource type
    for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
        if (!dtProvider.isGlobal() && dtProvider.supportsDataSource(dataSource, dsProvider) && dtProvider.supportsType(typedObject)) {
            return dtProvider.getInstance();
        }
    }
    // Find in global providers
    for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
        if (dtProvider.isGlobal() && dtProvider.supportsType(typedObject)) {
            return dtProvider.getInstance();
        }
    }
    return null;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DataSourceProviderDescriptor(org.jkiss.dbeaver.registry.DataSourceProviderDescriptor) Nullable(org.jkiss.code.Nullable)

Example 43 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class DriverLibraryLocal method getLocalFile.

@Nullable
@Override
public File getLocalFile() {
    // Try to use direct path
    String localFilePath = this.getLocalFilePath();
    File libraryFile = new File(localFilePath);
    if (libraryFile.exists()) {
        return libraryFile;
    }
    // Try to get local file
    File platformFile = detectLocalFile();
    if (platformFile != null && platformFile.exists()) {
        // Relative file do not exists - use plain one
        return platformFile;
    }
    URL url = driver.getProviderDescriptor().getContributorBundle().getEntry(localFilePath);
    if (url == null) {
        // Find in external resources
        url = driver.getProviderDescriptor().getRegistry().findResourceURL(localFilePath);
    }
    if (url != null) {
        try {
            url = FileLocator.toFileURL(url);
        } catch (IOException ex) {
            log.warn(ex);
        }
        if (url != null) {
            return new File(url.getFile());
        }
    } else {
        try {
            url = FileLocator.toFileURL(new URL(localFilePath));
            File urlFile = new File(url.getFile());
            if (urlFile.exists()) {
                platformFile = urlFile;
            }
        } catch (IOException ex) {
        // ignore
        }
    }
    // Nothing fits - just return plain url
    return platformFile;
}
Also used : IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) Nullable(org.jkiss.code.Nullable)

Example 44 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class SQLCompletionProcessor method computeContextInformation.

/**
     * This method is incomplete in that it does not implement logic to produce
     * some context help relevant to SQL. It just hard codes two strings to
     * demonstrate the action
     *
     * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(ITextViewer,
     *      int)
     */
@Nullable
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
    SQLQuery statementInfo = editor.extractQueryAtPos(documentOffset);
    if (statementInfo == null || CommonUtils.isEmpty(statementInfo.getQuery())) {
        return null;
    }
    IContextInformation[] result = new IContextInformation[1];
    result[0] = new ContextInformation(statementInfo.getQuery(), statementInfo.getQuery());
    return result;
}
Also used : SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery) Nullable(org.jkiss.code.Nullable)

Example 45 with Nullable

use of org.jkiss.code.Nullable 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;
    }
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) DBSObjectReference(org.jkiss.dbeaver.model.struct.DBSObjectReference) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) EntityHyperlink(org.jkiss.dbeaver.ui.editors.entity.EntityHyperlink) Nullable(org.jkiss.code.Nullable)

Aggregations

Nullable (org.jkiss.code.Nullable)49 DBException (org.jkiss.dbeaver.DBException)6 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NotNull (org.jkiss.code.NotNull)5 SQLException (java.sql.SQLException)4 Matcher (java.util.regex.Matcher)4 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)3 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 Font (org.eclipse.swt.graphics.Font)2