Skip to content

Commit

Permalink
#17305 Fix error message on unable to create new default data source …
Browse files Browse the repository at this point in the history
…config file (#17385)

#17305 Create default data sources config file if there is no such

#17305 Fix code style

#17305 Fix code style

#17305 Refactor legacy data sources config path detection

#17305 Fix data sources config loading
  • Loading branch information
E1izabeth committed Aug 18, 2022
1 parent c1b4fb2 commit c138b79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public List<DBPDataSourceConfigurationStorage> getConfigurationStorages() {
@Override
public InputStream readConfiguration(@NotNull String name) throws IOException {
Path path = getConfigurationPath(false).resolve(name);
if (!Files.exists(path)) {
if (Files.notExists(path)) {
// maybe it's .dbeaver-data-sources*.xml in the project folder (DBeaver < 6.1.3 (Legacy))
path = project.getAbsolutePath().resolve(name);
}
if (Files.notExists(path)) {
return null;
}
return Files.newInputStream(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -170,7 +173,16 @@ DBPDataSourceConfigurationStorage getDefaultStorage() {
}
}
// No default storage. Seems to be an internal error
throw new IllegalStateException("no default storage in registry " + this);
log.warn("no default storage in registry " + this);
try {
java.nio.file.Path configPath = this.getProject().getMetadataFolder(false).resolve(MODERN_CONFIG_FILE_NAME);
Files.createFile(configPath);
DBPDataSourceConfigurationStorage defaultStorage = new DataSourceFileStorage(configPath, false, true);
this.storages.add(defaultStorage);
return defaultStorage;
} catch (IOException e) {
throw new IllegalStateException("Unable to create a default storage in registry " + this, e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ public void parseDataSources(
credJson,
new TypeToken<Map<String, Map<String, Map<String, String>>>>() {
}.getType());
secureProperties.putAll(res);
if (res != null) {
secureProperties.putAll(res);
}
} catch (Exception e) {
log.error("Error decrypting secure credentials", e);
}
Expand Down Expand Up @@ -526,7 +528,7 @@ public void parseDataSources(
}
dataSource = new DataSourceDescriptor(
registry,
registry.getDefaultStorage(),
configurationStorage,
origin,
id,
driver,
Expand Down

0 comments on commit c138b79

Please sign in to comment.