started to implemente SQLite backend
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
package de.srsoftware.cal.app;
|
||||
|
||||
import static java.lang.System.Logger.Level.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import de.srsoftware.cal.*;
|
||||
import de.srsoftware.cal.db.Database;
|
||||
import de.srsoftware.cal.db.MariaDB;
|
||||
import de.srsoftware.cal.db.SqlDb;
|
||||
import de.srsoftware.cal.db.SQlite;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.configuration.JsonConfig;
|
||||
import de.srsoftware.tools.ColorLogger;
|
||||
@@ -36,13 +39,20 @@ public class Application {
|
||||
private static Database connect(Configuration config) throws SQLException {
|
||||
Optional<String> jdbc = config.get(JDBC);
|
||||
if (jdbc.isEmpty()) throw new RuntimeException(MISSING.formatted(JDBC));
|
||||
if (jdbc.get().contains(":mysql:") || jdbc.get().contains(":mariadb:")) return connectMariaDB(config, jdbc.get());
|
||||
if (jdbc.get().contains(":sqlite:")) return SQlite.connect(jdbc.get());
|
||||
throw new RuntimeException(format("Unknown database: {0}",jdbc.get()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static Database connectMariaDB(Configuration config, String jdbc) throws SQLException {
|
||||
String user = config.get(USER, "opencloudcal");
|
||||
|
||||
Optional<String> pass = config.get(PASS);
|
||||
if (pass.isEmpty()) throw new RuntimeException(MISSING.formatted(PASS));
|
||||
|
||||
return MariaDB.connect(jdbc.get(), user, pass.get());
|
||||
return MariaDB.connect(jdbc, user, pass.get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user