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);
}
}
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();
}
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;
}
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;
}
}
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;
}
Aggregations