first implementation of cal.db, that
- successfully connects to db - updated db sheme - succeeds in listing appointments Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -2,6 +2,10 @@ description = "OpenCloudCal : Application"
|
||||
|
||||
dependencies {
|
||||
implementation(project(":de.srsoftware.cal.api"))
|
||||
implementation(project(":de.srsoftware.cal.db"))
|
||||
implementation(project(":de.srsoftware.cal.importer"))
|
||||
|
||||
implementation("de.srsoftware:configuration.api:1.0.0")
|
||||
implementation("de.srsoftware:configuration.json:1.0.0")
|
||||
implementation("de.srsoftware:tools.util:1.1.1")
|
||||
}
|
||||
implementation("com.mysql:mysql-connector-j:9.1.0")}
|
||||
|
||||
@@ -1,38 +1,47 @@
|
||||
/* © SRSoftware 2024 */
|
||||
package de.srsoftware.cal.app;
|
||||
|
||||
import de.srsoftware.cal.importer.jena.Kassablanca;
|
||||
import de.srsoftware.cal.db.Database;
|
||||
import de.srsoftware.cal.db.MariaDB;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.configuration.JsonConfig;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Test application
|
||||
*/
|
||||
public class Application {
|
||||
private static final String JDBC = "opencloudcal.db.jdbc";
|
||||
private static final String USER = "opencloudcal.db.user";
|
||||
private static final String PASS = "opencloudcal.db.pass";
|
||||
private static final String MISSING = "missing required configuration property \"%s\"";
|
||||
|
||||
private Application() {
|
||||
}
|
||||
|
||||
private static Database connect(Configuration config) throws SQLException {
|
||||
Optional<String> jdbc = config.get(JDBC);
|
||||
if (jdbc.isEmpty()) throw new RuntimeException(MISSING.formatted(JDBC));
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* sandbox
|
||||
* @param args default
|
||||
*/
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException {
|
||||
|
||||
String host = null;
|
||||
String database = null;
|
||||
String user = null;
|
||||
String pass = null;
|
||||
int port = 3306;
|
||||
|
||||
// TODO: we need configuration here!
|
||||
|
||||
try (Connection con = DriverManager
|
||||
.getConnection("jdbc:mysql://%s:%s/%s".formatted(host,port,database), user, pass)) {
|
||||
// use con here
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, SQLException {
|
||||
JsonConfig jsonConfig = new JsonConfig("OpenCloudCal");
|
||||
var db = connect(jsonConfig);
|
||||
var appointments = db.list(null, null);
|
||||
for (var event : appointments) System.out.println(event);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user