Commit 4a077704 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Saves lastActiveDate, creationDate and modificationDate to the database. (code was tested)


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@152 b35dd754-fafc-0310-a699-88a17e54d16e
parent cdffdf5f
...@@ -57,19 +57,20 @@ public class MUCPersistenceManager { ...@@ -57,19 +57,20 @@ public class MUCPersistenceManager {
private static final String LOAD_MEMBERS = private static final String LOAD_MEMBERS =
"SELECT jid, nickname FROM mucMember WHERE roomID=?"; "SELECT jid, nickname FROM mucMember WHERE roomID=?";
private static final String UPDATE_ROOM = private static final String UPDATE_ROOM =
"UPDATE mucRoom SET name=?, modificationDate=?, description=?, canChangeSubject=?, maxUsers=?, " + "UPDATE mucRoom SET modificationDate=?, name=?, description=?, canChangeSubject=?, maxUsers=?, " +
"publicRoom=?, moderated=?, invitationRequired=?, canInvite=?, password=?, " + "publicRoom=?, moderated=?, invitationRequired=?, canInvite=?, password=?, " +
"canDiscoverJID=?, logEnabled=?, rolesToBroadcast=?, inMemory=? WHERE roomID=?"; "canDiscoverJID=?, logEnabled=?, rolesToBroadcast=?, inMemory=? WHERE roomID=?";
private static final String ADD_ROOM = private static final String ADD_ROOM =
"INSERT INTO mucRoom (roomID, creationDate, modificationDate, name, description, canChangeSubject, " + "INSERT INTO mucRoom (roomID, creationDate, modificationDate, name, description, canChangeSubject, " +
"maxUsers, publicRoom, moderated, invitationRequired, canInvite, password, canDiscoverJID, " + "maxUsers, publicRoom, moderated, invitationRequired, canInvite, password, canDiscoverJID, " +
"logEnabled, subject, rolesToBroadcast, inMemory) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; "logEnabled, subject, rolesToBroadcast, lastActiveDate, inMemory) " +
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private static final String UPDATE_SUBJECT = private static final String UPDATE_SUBJECT =
"UPDATE mucRoom SET subject=? WHERE roomID=?"; "UPDATE mucRoom SET subject=? WHERE roomID=?";
private static final String UPDATE_IN_MEMORY = private static final String UPDATE_IN_MEMORY =
"UPDATE mucRoom SET inMemory=? WHERE roomID=?"; "UPDATE mucRoom SET lastActiveDate=?, inMemory=? WHERE roomID=?";
private static final String RESET_IN_MEMORY = private static final String RESET_IN_MEMORY =
"UPDATE mucRoom SET inMemory=0 WHERE inMemory=1"; "UPDATE mucRoom SET lastActiveDate=?, inMemory=0 WHERE inMemory=1";
private static final String DELETE_ROOM = private static final String DELETE_ROOM =
"DELETE FROM mucRoom WHERE roomID=?"; "DELETE FROM mucRoom WHERE roomID=?";
private static final String DELETE_AFFILIATIONS = private static final String DELETE_AFFILIATIONS =
...@@ -326,7 +327,8 @@ public class MUCPersistenceManager { ...@@ -326,7 +327,8 @@ public class MUCPersistenceManager {
pstmt.setInt(14, (room.isLogEnabled() ? 1 : 0)); pstmt.setInt(14, (room.isLogEnabled() ? 1 : 0));
pstmt.setString(15, room.getSubject()); pstmt.setString(15, room.getSubject());
pstmt.setInt(16, marshallRolesToBroadcast(room)); pstmt.setInt(16, marshallRolesToBroadcast(room));
pstmt.setInt(17, 1); // the room starts always "in memory" pstmt.setString(17, StringUtils.dateToMillis(nowDate));
pstmt.setInt(18, 1); // the room starts always "in memory"
pstmt.execute(); pstmt.execute();
} }
} }
...@@ -394,13 +396,16 @@ public class MUCPersistenceManager { ...@@ -394,13 +396,16 @@ public class MUCPersistenceManager {
return; return;
} }
long now = System.currentTimeMillis();
Date nowDate = new Date(now);
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_IN_MEMORY); pstmt = con.prepareStatement(UPDATE_IN_MEMORY);
pstmt.setBoolean(1, inMemory); pstmt.setString(1, StringUtils.dateToMillis(nowDate));
pstmt.setLong(2, room.getID()); pstmt.setBoolean(2, inMemory);
pstmt.setLong(3, room.getID());
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
...@@ -420,11 +425,14 @@ public class MUCPersistenceManager { ...@@ -420,11 +425,14 @@ public class MUCPersistenceManager {
* the service is starting up (again). * the service is starting up (again).
*/ */
public static void resetRoomInMemory() { public static void resetRoomInMemory() {
long now = System.currentTimeMillis();
Date nowDate = new Date(now);
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(RESET_IN_MEMORY); pstmt = con.prepareStatement(RESET_IN_MEMORY);
pstmt.setString(1, StringUtils.dateToMillis(nowDate));
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment