diff --git a/changelog.html b/changelog.html index 2a0aa6a72..5192092ce 100644 --- a/changelog.html +++ b/changelog.html @@ -48,6 +48,7 @@

1.12.0 July 4, 2025

diff --git a/plugin.xml b/plugin.xml index cf76295bb..d4c3d310a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -6,7 +6,7 @@ Allows administration over a RESTful API. Roman Soldatow ${project.version} - 2025-10-02 + 2025-10-09 5.0.0 diff --git a/src/java/org/jivesoftware/openfire/plugin/rest/controller/MsgArchiveController.java b/src/java/org/jivesoftware/openfire/plugin/rest/controller/MsgArchiveController.java index f87ad819c..004a3abc0 100644 --- a/src/java/org/jivesoftware/openfire/plugin/rest/controller/MsgArchiveController.java +++ b/src/java/org/jivesoftware/openfire/plugin/rest/controller/MsgArchiveController.java @@ -22,6 +22,7 @@ import java.sql.SQLException; import org.jivesoftware.database.DbConnectionManager; +import org.jivesoftware.database.DbConnectionManager.DatabaseType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xmpp.packet.JID; @@ -36,12 +37,29 @@ public class MsgArchiveController { /** The Constant INSTANCE. */ public static final MsgArchiveController INSTANCE = new MsgArchiveController(); + /** + * Builds the SQL query for counting unread messages based on the underlying database type. + * + * @param databaseType the database connection used to detect the database product name + * @return the database-specific SQL query string for counting unread messages + */ + private String buildUserMessageCountQuery(DatabaseType databaseType) { + String castExpr; + switch (databaseType) { + case mysql: + castExpr = "CAST(p.offlineDate AS SIGNED)"; break; + case oracle: + castExpr = "CAST(p.offlineDate AS NUMBER)"; break; + default: + // PostgreSQL, SQL Server, Sybase — all understand BIGINT in CAST + castExpr = "CAST(p.offlineDate AS BIGINT)"; + break; + } - /** The Constant USER_MESSAGE_COUNT. */ - private static final String USER_MESSAGE_COUNT = "select COUNT(1) from ofMessageArchive a " + - "join ofPresence p on (a.sentDate > p.offlineDate) " + + return "SELECT COUNT(1) FROM ofMessageArchive a " + + "JOIN ofPresence p ON (a.sentDate > " + castExpr + ") " + "WHERE a.toJID = ? AND p.username = ?"; - + } /** * Gets the single instance of MsgArchiveController. * @@ -70,7 +88,9 @@ public int getUnReadMessagesCount(JID jid) { ResultSet rs = null; try { con = DbConnectionManager.getConnection(); - pstmt = con.prepareStatement(USER_MESSAGE_COUNT); + DatabaseType databaseType = DbConnectionManager.getDatabaseType(); + String userMessageCountQuery = buildUserMessageCountQuery(databaseType); + pstmt = con.prepareStatement(userMessageCountQuery); pstmt.setString(1, jid.toBareJID()); pstmt.setString(2, jid.getNode()); rs = pstmt.executeQuery();