Commit a69cad26 authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Cleanup Code

parent 311c4372
Pipeline #12319 passed with stage
in 2 minutes and 4 seconds
......@@ -48,7 +48,7 @@ public class EmbeddedDatabaseHandler {
String jdbcUrl;
try {
if (config.inMemoryMode()) {
jdbcUrl = setupInMemoryDataBase(config.getInMemoryH2Url());
jdbcUrl = createEmbeddedDataBase(config.getInMemoryH2Url());
} else if (config.tempFileMode()){
Path tmpDir = Files.createTempDirectory(config.databaseDirectory());
tmpDir.toFile().deleteOnExit();
......@@ -67,7 +67,7 @@ public class EmbeddedDatabaseHandler {
if (config.attemptFallback()){
logger.info("Attempting fallback to in-memory database");
try {
jdbcUrl = setupInMemoryDataBase(config.getFallbackH2Url());
jdbcUrl = createEmbeddedDataBase(config.getFallbackH2Url());
} catch (Exception e1) {
throw new EmbeddedDatabaseHandlerException("Fallback to in-memory database failed, embedded database could not be created", e1);
}
......@@ -93,19 +93,9 @@ public class EmbeddedDatabaseHandler {
Runtime.getRuntime().addShutdownHook(new Thread(ds::close));
}
// Embedded database can only ever be accessed by the local machine, suppress linter-warning about password leak
@SuppressWarnings("java:S6437")
private String createEmbeddedDataBase(String dbUrl) throws SQLException {
// DataSource source = H2GISDBFactory.createDataSource("file://"+dbUrl,
// true, config.getH2ParametersSuffix());
// try (Connection con = source.getConnection()) {
// return con.getMetaData().getURL();
// }
try (Connection con = DriverManager.getConnection(dbUrl,"sa","sa")){
H2GISFunctions.load(con);
return con.getMetaData().getURL();
}
}
private String setupInMemoryDataBase(String dbUrl) throws SQLException{
try (Connection con = DriverManager.getConnection(dbUrl,"sa","sa")){
H2GISFunctions.load(con);
return con.getMetaData().getURL();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment