working on hamonization of db implementations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-08-01 22:18:44 +02:00
parent 64e925c83f
commit eed0ce0e8e
8 changed files with 97 additions and 96 deletions

View File

@@ -5,7 +5,6 @@ public class Constants {
private Constants(){}
public static final String CONFIG_DATABASE = "umbrella.modules.project.database";
public static final String DB_VERSION = "project_db_version";
public static final String PERMISSIONS = "permissions";
public static final String TABLE_CUSTOM_STATES = "custom_states";
public static final String TABLE_PROJECTS = "projects";

View File

@@ -14,6 +14,7 @@ import static java.lang.System.Logger.Level.INFO;
import static java.text.MessageFormat.format;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Permission;
import de.srsoftware.umbrella.core.model.Project;
@@ -26,15 +27,12 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class SqliteDb implements ProjectDb {
public class SqliteDb extends BaseDb implements ProjectDb {
private static final System.Logger LOG = System.getLogger("Sqlite4Project");
private static final int INITIAL_DB_VERSION = 1;
private final Connection db;
public SqliteDb(Connection connection) {
db = connection;
init();
super(connection);
}
private void createProjectTable() {
@@ -77,7 +75,7 @@ PRIMARY KEY (project_id, code)
}
private int createTables() {
protected int createTables() {
int currentVersion = createSettingsTable();
switch (currentVersion){
case 0:
@@ -107,31 +105,6 @@ CREATE TABLE IF NOT EXISTS {0} (
}
}
private int createSettingsTable() {
var createTable = """
CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255) NOT NULL);
""";
try {
var stmt = db.prepareStatement(format(createTable,TABLE_SETTINGS, KEY, VALUE));
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_SETTINGS,e);
throw new RuntimeException(e);
}
var version = 0;
try {
var rs = Query.select(VALUE).from(TABLE_SETTINGS).where(KEY, equal(DB_VERSION)).exec(db);
if (rs.next()) version = rs.getInt(VALUE);
rs.close();
return version;
} catch (SQLException e) {
LOG.log(ERROR,ERROR_READ_TABLE,DB_VERSION,TABLE_SETTINGS,e);
throw new RuntimeException(e);
}
}
@Override
public void dropMember(long projectId, long userId) {
@@ -270,13 +243,4 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
throw new UmbrellaException("Failed to create custom state!");
}
}
private int setCurrentVersion(int version) {
try {
replaceInto(TABLE_SETTINGS, KEY, VALUE).values(DB_VERSION,version).execute(db).close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return version;
}
}