overhauling constants, working on translations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-01-15 13:58:50 +01:00
parent 669853352e
commit 0d1cdd35d1
103 changed files with 2161 additions and 1207 deletions

View File

@@ -6,15 +6,16 @@ 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.bookmarks.Constants.*;
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.core.exceptions.UmbrellaException.notFound;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.constants.Text.BOOKMARK;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static java.text.MessageFormat.format;
import static java.time.ZoneOffset.UTC;
import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.model.Bookmark;
import de.srsoftware.umbrella.core.model.Translatable;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.LocalDateTime;
@@ -48,7 +49,7 @@ CREATE TABLE IF NOT EXISTS {0} (
PRIMARY KEY (`{1}`,`{2}`)
)""";
try {
var stmt = db.prepareStatement(format(sql,TABLE_URL_COMMENTS,URL_ID,USER_ID,COMMENT,TIMESTAMP));
var stmt = db.prepareStatement(format(sql,TABLE_URL_COMMENTS,URL_ID, USER_ID, COMMENT,TIMESTAMP));
stmt.execute();
stmt.close();
} catch (SQLException e) {
@@ -63,7 +64,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_URLS).causedBy(e);
throw failedToCreateTable(TABLE_URLS).causedBy(e);
}
}
@@ -76,7 +77,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();;
return map;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark list").causedBy(e);
throw failedToLoadObject("bookmark list").causedBy(e);
}
}
@@ -84,7 +85,7 @@ CREATE TABLE IF NOT EXISTS {0} (
public Map<Long, Bookmark> findUrls(long userId, Collection<String> keys) {
try {
var map = new HashMap<Long,Bookmark>();
var query = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS,ID)
var query = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS, ID)
.where(USER_ID, equal(userId));
for (var key : keys) query.where(COMMENT,like("%"+key+"%"));
var rs = query.sort(format("{0} DESC",TIMESTAMP)).exec(db);
@@ -95,7 +96,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();;
return map;
} catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY,"bookmark list").causedBy(e);
throw failedToDropObject("bookmark list").causedBy(e);
}
}
@@ -103,7 +104,7 @@ CREATE TABLE IF NOT EXISTS {0} (
public Map<Long, Bookmark> list(long userId, Long offset, Long limit) {
try {
var map = new HashMap<Long,Bookmark>();
var rs = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS,ID).where(USER_ID, equal(userId)).sort(format("{0} DESC",TIMESTAMP)).skip(offset).limit(limit).exec(db);
var rs = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS, ID).where(USER_ID, equal(userId)).sort(format("{0} DESC",TIMESTAMP)).skip(offset).limit(limit).exec(db);
while (rs.next()){
var bookmark = Bookmark.of(rs);
map.put(bookmark.urlId(),bookmark);
@@ -111,7 +112,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();;
return map;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark list").causedBy(e);
throw failedToLoadObject("bookmark list").causedBy(e);
}
}
@@ -123,9 +124,9 @@ CREATE TABLE IF NOT EXISTS {0} (
if (rs.next()) result = Bookmark.of(rs);
rs.close();
if (result != null) return result;
throw notFound(NO_BOOKMARK_FOR_URLID,id);
throw failedToLoadObject(Translatable.t(BOOKMARK),id);
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,"bookmark").causedBy(e);
throw failedToLoadObject(Translatable.t(BOOKMARK),id).causedBy(e);
}
}
@@ -143,12 +144,12 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
stmt.close();
}
var query = replaceInto(TABLE_URL_COMMENTS,URL_ID,USER_ID,COMMENT, TIMESTAMP);
var query = replaceInto(TABLE_URL_COMMENTS,URL_ID, USER_ID, COMMENT, TIMESTAMP);
for (long userId : userIds) query.values(urlId,userId,comment,timestamp.toEpochSecond(UTC));
query.execute(db).close();
return Bookmark.of(urlId,url,comment,timestamp);
} catch (SQLException e) {
throw databaseException(FAILED_TO_STORE_ENTITY,"url").causedBy(e);
throw failedToStoreObject(this).causedBy(e);
}
}
}