working on backend-side translations

This commit is contained in:
2025-12-15 21:17:45 +01:00
parent 0c909d6d7c
commit a275b5065d
4 changed files with 35 additions and 37 deletions

View File

@@ -11,6 +11,7 @@ import static de.srsoftware.umbrella.bookmarks.Constants.*;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
import static de.srsoftware.umbrella.core.Constants.USER_ID;
import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.tags.Constants.*;
import static java.lang.System.Logger.Level.*;
@@ -104,7 +105,7 @@ public class SqliteDb extends BaseDb implements TagDB{
}
commentedURLS.close();
} catch (SQLException e) {
throw new RuntimeException(e);
throw databaseException(FAILED_TO_UPDATE_TABLE,TABLE_URLS).causedBy(e);
}
}
@@ -115,8 +116,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "Comments (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"Comments (legacy)").causedBy(e);
}
}
@@ -127,8 +127,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "Tags (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"Tags (legacy)").causedBy(e);
}
}
@@ -139,8 +138,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "URLs (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"URLs (legacy)").causedBy(e);
}
}
@@ -151,8 +149,7 @@ public class SqliteDb extends BaseDb implements TagDB{
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, "URL_comments (legacy)", e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,"URL_comments (legacy)").causedBy(e);
}
}
@@ -171,20 +168,20 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TAGS_NEW,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TAGS_NEW).causedBy(e);
}
}
private void dropOldTables(){
var sql = "DROP TABLE IF EXISTS {0}";
for (var table : List.of(TABLE_TAGS,TABLE_COMMENTS,TABLE_TOKENS,TABLE_URL_COMMENTS,TABLE_URLS)) try {
String table = null;
for (var t : List.of(TABLE_TAGS,TABLE_COMMENTS,TABLE_TOKENS,TABLE_URL_COMMENTS,TABLE_URLS)) try {
table = t;
var stmt = db.prepareStatement(format(sql,table));
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TAGS_NEW,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_DROP_ENTITY,table).causedBy(e);
}
}
@@ -195,8 +192,8 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_TAGS_NEW,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TAGS).causedBy(e);
}
}
@@ -211,7 +208,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.execute(db);
return tag;
} catch (SQLException e){
throw new UmbrellaException("Failed to delete tag {0}",tag);
throw databaseException(FAILED_TO_DROP_ENTITY,tag);
}
}
@@ -222,7 +219,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.where(MODULE,iEqual(module)).where(ENTITY_ID,equal(entityId))
.execute(db);
} catch (SQLException e){
throw new UmbrellaException("Failed to save tags ({0} {1})",module,entityId);
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,entityId,module).causedBy(e);
}
}
@@ -246,7 +243,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return result;
} catch (SQLException e){
throw new UmbrellaException("Failed to load uses of tag \"{0}\"!",tag);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"uses",tag).causedBy(e);
}
}
@@ -266,7 +263,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return tags;
} catch (SQLException e) {
throw new UmbrellaException("Failed to load tags");
throw databaseException(FAILED_TO_LIST_ENTITIES,"tags").causedBy(e);
}
}
@@ -284,7 +281,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return list;
} catch (SQLException e) {
throw databaseException("Failed to load tags for user {0}",userId);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"tags",userId).causedBy(e);
}
}
@@ -304,7 +301,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return tags;
} catch (SQLException e) {
throw new UmbrellaException("Failed to load tags");
throw databaseException(FAILED_TO_LIST_ENTITIES,"tags").causedBy(e);
}
}
@@ -321,7 +318,7 @@ CREATE TABLE IF NOT EXISTS {0} (
}
query.execute(db).close();
} catch (SQLException e){
throw new UmbrellaException("Failed to save tags: {0}",String.join(", ",tags));
throw databaseException(FAILED_TO_STORE_ENTITY,String.join(", ",tags)).causedBy(e);
}
}
@@ -331,7 +328,7 @@ CREATE TABLE IF NOT EXISTS {0} (
update(TABLE_TAGS).set(ENTITY_ID).where(MODULE,iEqual(module)).where(ENTITY_ID,equal(oldId)).prepare(db).apply(newId).close();
LOG.log(DEBUG,"Updated tag @ {0}.{1} → {0}.{2}",module,oldId,newId);
} catch (SQLException e) {
throw databaseException("Failed to update {0}.{1} → {0}.{2}",module,oldId,newId);
throw databaseException(FAILED_TO_UPDATE_ENTITY,format("{0}.{1} → {0}.{2}",module,oldId,newId)).causedBy(e);
}
}
}