working on backend-side translations

This commit is contained in:
2025-12-14 23:42:19 +01:00
parent 878365a83d
commit 9f0857e753
5 changed files with 40 additions and 44 deletions

View File

@@ -6,6 +6,7 @@ import static de.srsoftware.tools.jdbc.Condition.like;
import static de.srsoftware.tools.jdbc.Query.*;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.notes.Constants.*;
import static java.lang.System.Logger.Level.*;
@@ -55,8 +56,7 @@ ADD COLUMN entity_id VARCHAR(255);
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,"Failed to add \"entity_id\" column to table {0}",TABLE_NOTES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_UPDATE_COLUMN,"(not existing)",ENTITY_ID,TABLE_NOTES).causedBy(e);
}
}
@@ -70,8 +70,7 @@ ADD COLUMN module VARCHAR(20);
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,"Failed to add \"module\" column to table {0}",TABLE_NOTES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_UPDATE_COLUMN,"(not existing)",MODULE,TABLE_NOTES).causedBy(e);
}
}
@@ -86,8 +85,7 @@ SET module = SUBSTR(uri, 1, INSTR(uri, ':') - 1),
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,"Failed fill \"module\" and \"entity_id\" columns",e);
throw new RuntimeException(e);
throw databaseException("Failed to fill \"{0}\" and \"{1}\" columns",MODULE,ENTITY_ID).causedBy(e);
}
}
@@ -104,8 +102,7 @@ CREATE TABLE IF NOT EXISTS notes (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_NOTES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_NOTES).causedBy(e);
}
}
@@ -124,8 +121,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_NOTES,e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_NOTES).causedBy(e);
}
}
@@ -137,7 +133,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
.execute(db);
return noteId;
} catch (SQLException e){
throw new UmbrellaException("Failed to delete note {0}",noteId);
throw databaseException(FAILED_TO_DROP_ENTITY,"note",noteId);
}
}
@@ -148,7 +144,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
.where(MODULE,equal(module)).where(ENTITY_ID,equal(entityId))
.execute(db);
} catch (SQLException e){
throw new UmbrellaException("Failed to delete notes of ({0} {1})",module,entityId);
throw databaseException(FAILED_TO_DROP_NOTES,module,entityId).causedBy(e);
}
}
@@ -159,8 +155,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,"Failed drop \"uri\" column",e);
throw new RuntimeException(e);
throw databaseException(FAILED_TO_DROP_ENTITY,"uri","column").causedBy(e);
}
}
@@ -178,7 +173,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return notes;
} catch (SQLException e) {
throw databaseException("Failed to search notes");
throw databaseException(FAILED_TO_SEARCH_DB,TABLE_NOTES).causedBy(e);
}
}
@@ -195,7 +190,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return notes;
} catch (SQLException e) {
throw databaseException("Failed to load notes");
throw databaseException(FAILED_TO_LOAD_ENTITY,TABLE_NOTES).causedBy(e);
}
}
@@ -213,7 +208,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return notes;
} catch (SQLException e) {
throw databaseException("Failed to load notes");
throw databaseException(FAILED_TO_LOAD_ENTITY,TABLE_NOTES).causedBy(e);
}
}
@@ -226,7 +221,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
rs.close();
return note;
} catch (SQLException e) {
throw databaseException("Failed to load note {0}",noteId);
throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"note",noteId).causedBy(e);
}
}
@@ -250,7 +245,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
}
return note;
} catch (SQLException e){
throw databaseException("Failed to save note: {0}",note.text());
throw databaseException(FAILED_TO_STORE_ENTITY,"note").causedBy(e);
}
}
@@ -260,7 +255,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
update(TABLE_NOTES).set(ENTITY_ID).where(MODULE,equal(module)).where(ENTITY_ID,equal(oldId)).prepare(db).apply(newId).close();
LOG.log(DEBUG,"Updated note @ {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 {0}.{1} → {0}.{2}",module,oldId,newId).causedBy(e);
}
}
}