Search in sources :

Example 46 with NotNull

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

the class ExasolStructureAssistant method findObjectsByMask.

@NotNull
@Override
public List<DBSObjectReference> findObjectsByMask(DBRProgressMonitor monitor, DBSObject parentObject, DBSObjectType[] objectTypes, String objectNameMask, boolean caseSensitive, boolean globalSearch, int maxResults) throws DBException {
    LOG.debug(objectNameMask);
    List<ExasolObjectType> exasolObjectTypes = new ArrayList<>(objectTypes.length);
    for (DBSObjectType dbsObjectType : objectTypes) {
        exasolObjectTypes.add((ExasolObjectType) dbsObjectType);
    }
    ExasolSchema schema = parentObject instanceof ExasolSchema ? (ExasolSchema) parentObject : null;
    try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Find objects by name")) {
        return searchAllObjects(session, schema, objectNameMask, exasolObjectTypes, caseSensitive, maxResults);
    } catch (SQLException ex) {
        throw new DBException(ex, dataSource);
    }
}
Also used : ExasolObjectType(org.jkiss.dbeaver.ext.exasol.editors.ExasolObjectType) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) DBSObjectType(org.jkiss.dbeaver.model.struct.DBSObjectType) ArrayList(java.util.ArrayList) NotNull(org.jkiss.code.NotNull)

Example 47 with NotNull

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

the class ContentUtils method getContentStringValue.

@NotNull
public static String getContentStringValue(@NotNull DBRProgressMonitor monitor, @NotNull DBDContent object) throws DBCException {
    DBDContentStorage data = object.getContents(monitor);
    if (data != null) {
        if (data instanceof DBDContentCached) {
            Object cachedValue = ((DBDContentCached) data).getCachedValue();
            if (cachedValue instanceof String) {
                return (String) cachedValue;
            }
        }
        try {
            Reader contentReader = data.getContentReader();
            if (contentReader != null) {
                try {
                    StringWriter buf = new StringWriter();
                    ContentUtils.copyStreams(contentReader, object.getContentLength(), buf, monitor);
                    return buf.toString();
                } finally {
                    IOUtils.close(contentReader);
                }
            }
        } catch (IOException e) {
            log.debug("Can't extract string from content", e);
        }
    }
    return object.toString();
}
Also used : DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) NotNull(org.jkiss.code.NotNull)

Example 48 with NotNull

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

the class ContentUtils method getContentBinaryValue.

@NotNull
public static byte[] getContentBinaryValue(@NotNull DBRProgressMonitor monitor, @NotNull DBDContent object) throws DBCException {
    DBDContentStorage data = object.getContents(monitor);
    if (data != null) {
        if (data instanceof DBDContentCached) {
            Object cachedValue = ((DBDContentCached) data).getCachedValue();
            if (cachedValue instanceof byte[]) {
                return (byte[]) cachedValue;
            }
        }
        try {
            InputStream contentStream = data.getContentStream();
            if (contentStream != null) {
                try {
                    ByteArrayOutputStream buf = new ByteArrayOutputStream();
                    ContentUtils.copyStreams(contentStream, object.getContentLength(), buf, monitor);
                    return buf.toByteArray();
                } finally {
                    IOUtils.close(contentStream);
                }
            }
        } catch (IOException e) {
            log.debug("Can't extract string from content", e);
        }
    }
    return null;
}
Also used : DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) NotNull(org.jkiss.code.NotNull)

Example 49 with NotNull

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

the class GeneralUtils method replaceVariables.

@NotNull
public static String replaceVariables(@NotNull String string, IVariableResolver resolver) {
    try {
        Matcher matcher = VAR_PATTERN.matcher(string);
        int pos = 0;
        while (matcher.find(pos)) {
            pos = matcher.end();
            String varName = matcher.group(2);
            String varValue = resolver.get(varName);
            if (varValue != null) {
                if (matcher.start() == 0 && matcher.end() == string.length() - 1) {
                    string = varValue;
                } else {
                    string = string.substring(0, matcher.start()) + varValue + string.substring(matcher.end());
                }
                matcher = VAR_PATTERN.matcher(string);
                pos = 0;
            }
        }
        return string;
    } catch (Exception e) {
        log.warn("Error matching regex", e);
        return string;
    }
}
Also used : Matcher(java.util.regex.Matcher) DBException(org.jkiss.dbeaver.DBException) ParseException(java.text.ParseException) NotNull(org.jkiss.code.NotNull)

Example 50 with NotNull

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

the class DriverDescriptor method validateFilesPresence.

@NotNull
private List<File> validateFilesPresence(boolean resetVersions) {
    boolean localLibsExists = false;
    final List<DBPDriverLibrary> downloadCandidates = new ArrayList<>();
    for (DBPDriverLibrary library : libraries) {
        if (library.isDisabled()) {
            // Nothing we can do about it
            continue;
        }
        if (!library.matchesCurrentPlatform()) {
            // Wrong OS or architecture
            continue;
        }
        if (library.isDownloadable()) {
            boolean allExists = true;
            if (resetVersions) {
                allExists = false;
            } else {
                List<DriverFileInfo> files = resolvedFiles.get(library);
                if (files == null) {
                    allExists = false;
                } else {
                    for (DriverFileInfo file : files) {
                        if (file.file == null || !file.file.exists()) {
                            allExists = false;
                            break;
                        }
                    }
                }
            }
            if (!allExists) {
                downloadCandidates.add(library);
            }
        } else {
            localLibsExists = true;
        }
    }
    //        if (!CommonUtils.isEmpty(fileSources)) {
    //            for (DriverFileSource source : fileSources) {
    //                for (DriverFileSource.FileInfo fileInfo : source.getFiles()) {
    //                    DriverLibraryLocal libraryLocal = new DriverLibraryLocal(this, DBPDriverLibrary.FileType.jar, fileInfo.getName());
    //                    final File localFile = libraryLocal.getLocalFile();
    //                }
    //            }
    //        }
    boolean downloaded = false;
    if (!downloadCandidates.isEmpty() || (!localLibsExists && !fileSources.isEmpty())) {
        final DriverDependencies dependencies = new DriverDependencies(downloadCandidates);
        boolean downloadOk = new UITask<Boolean>() {

            @Override
            protected Boolean runTask() {
                return DriverDownloadDialog.downloadDriverFiles(null, DriverDescriptor.this, dependencies);
            }
        }.execute();
        if (!downloadOk) {
            return Collections.emptyList();
        }
        if (resetVersions) {
            resetDriverInstance();
        /*
                for (DBPDriverLibrary library : libraries) {
                    if (!library.isDisabled()) {
                        library.resetVersion();
                    }
                }
*/
        }
        downloaded = true;
        for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryMap()) {
            List<DriverFileInfo> info = new ArrayList<>();
            resolvedFiles.put(node.library, info);
            collectLibraryFiles(node, info);
        }
        providerDescriptor.getRegistry().saveDrivers();
    }
    List<File> result = new ArrayList<>();
    for (DBPDriverLibrary library : libraries) {
        if (library.isDisabled() || !library.matchesCurrentPlatform()) {
            // Wrong OS or architecture
            continue;
        }
        if (library.isDownloadable()) {
            List<DriverFileInfo> files = resolvedFiles.get(library);
            if (files != null) {
                for (DriverFileInfo file : files) {
                    result.add(file.file);
                }
            }
        } else {
            result.add(library.getLocalFile());
        }
    }
    // Now check driver version
    if (DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.UI_DRIVERS_VERSION_UPDATE) && !downloaded) {
        // TODO: implement new version check
        if (false) {
            try {
                DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            checkDriverVersion(monitor);
                        } catch (IOException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
            } catch (InvocationTargetException e) {
                log.error(e.getTargetException());
            } catch (InterruptedException e) {
            // ignore
            }
        }
    }
    return result;
}
Also used : IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) File(java.io.File) NotNull(org.jkiss.code.NotNull)

Aggregations

NotNull (org.jkiss.code.NotNull)58 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)11 SQLException (java.sql.SQLException)9 DBCException (org.jkiss.dbeaver.model.exec.DBCException)9 DBException (org.jkiss.dbeaver.DBException)7 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)7 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)6 ArrayList (java.util.ArrayList)5 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 Nullable (org.jkiss.code.Nullable)5 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)5 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)5 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)5 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)5 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DBDValueHandler (org.jkiss.dbeaver.model.data.DBDValueHandler)3 SQLDataSource (org.jkiss.dbeaver.model.sql.SQLDataSource)3 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)3