Commit 3bb95cb6 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added #creationDate and #modificationDate to MUCRoom.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@453 b35dd754-fafc-0310-a699-88a17e54d16e
parent b0afaa1e
...@@ -13,6 +13,7 @@ package org.jivesoftware.messenger.muc; ...@@ -13,6 +13,7 @@ package org.jivesoftware.messenger.muc;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Date;
import org.jivesoftware.messenger.muc.spi.IQAdminHandler; import org.jivesoftware.messenger.muc.spi.IQAdminHandler;
import org.jivesoftware.messenger.muc.spi.IQOwnerHandler; import org.jivesoftware.messenger.muc.spi.IQOwnerHandler;
...@@ -59,6 +60,36 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -59,6 +60,36 @@ public interface MUCRoom extends ChatDeliverer {
*/ */
void setID(long roomID); void setID(long roomID);
/**
* Returns the date when the room was created.
*
* @return the date when the room was created.
*/
Date getCreationDate();
/**
* Sets the date when the room was created.
*
* @param creationDate the date when the room was created.
*/
void setCreationDate(Date creationDate);
/**
* Returns the last date when the room's configuration was modified. If the room's configuration
* was never modified then the creation date will be returned.
*
* @return the last date when the room's configuration was modified.
*/
Date getModificationDate();
/**
* Sets the last date when the room's configuration was modified. If the room's configuration
* was never modified then the initial value will be the same as the creation date.
*
* @param modificationDate the last date when the room's configuration was modified.
*/
void setModificationDate(Date modificationDate);
/** /**
* Obtain the role of the chat server (mainly for addressing messages and presence). * Obtain the role of the chat server (mainly for addressing messages and presence).
* *
......
...@@ -455,7 +455,11 @@ public class IQOwnerHandler { ...@@ -455,7 +455,11 @@ public class IQOwnerHandler {
booleanValue = (values.hasNext() ? values.next() : "1"); booleanValue = (values.hasNext() ? values.next() : "1");
room.setLogEnabled(("1".equals(booleanValue) ? true : false)); room.setLogEnabled(("1".equals(booleanValue) ? true : false));
} }
// Update the modification date to reflect the last time when the room's configuration
// was modified
room.setModificationDate(new Date());
if (room.isPersistent()) { if (room.isPersistent()) {
room.saveToDB(); room.saveToDB();
} }
......
...@@ -41,16 +41,16 @@ import org.jivesoftware.util.StringUtils; ...@@ -41,16 +41,16 @@ import org.jivesoftware.util.StringUtils;
public class MUCPersistenceManager { public class MUCPersistenceManager {
private static final String LOAD_ROOM_SURROGATES = private static final String LOAD_ROOM_SURROGATES =
"SELECT roomID, name, naturalName, description, canChangeSubject, maxUsers, " + "SELECT roomID, creationDate, modificationDate, name, naturalName, description, " +
"moderated, invitationRequired, canInvite, " + "canChangeSubject, maxUsers, moderated, invitationRequired, canInvite, " +
"password, canDiscoverJID, logEnabled, subject, rolesToBroadcast " + "password, canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"FROM mucRoom WHERE inMemory=0 and publicRoom=1"; "FROM mucRoom WHERE inMemory=0 and publicRoom=1";
private static final String GET_RESERVED_NAME = private static final String GET_RESERVED_NAME =
"SELECT nickname FROM mucMember WHERE roomID=? AND jid=?"; "SELECT nickname FROM mucMember WHERE roomID=? AND jid=?";
private static final String LOAD_ROOM = private static final String LOAD_ROOM =
"SELECT roomID, naturalName, description, canChangeSubject, maxUsers, " + "SELECT roomID, creationDate, modificationDate, naturalName, description, " +
"publicRoom, moderated, invitationRequired, canInvite, password, " + "canChangeSubject, maxUsers, publicRoom, moderated, invitationRequired, canInvite, " +
"canDiscoverJID, logEnabled, subject, rolesToBroadcast " + "password, canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"FROM mucRoom WHERE name=?"; "FROM mucRoom WHERE name=?";
private static final String LOAD_AFFILIATIONS = private static final String LOAD_AFFILIATIONS =
"SELECT jid,affiliation FROM mucAffiliation WHERE roomID=?"; "SELECT jid,affiliation FROM mucAffiliation WHERE roomID=?";
...@@ -106,21 +106,23 @@ public class MUCPersistenceManager { ...@@ -106,21 +106,23 @@ public class MUCPersistenceManager {
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
MUCPersistentRoomSurrogate room = null; MUCPersistentRoomSurrogate room = null;
while (rs.next()) { while (rs.next()) {
room = new MUCPersistentRoomSurrogate(chatserver, rs.getString(2), packetRouter); room = new MUCPersistentRoomSurrogate(chatserver, rs.getString(4), packetRouter);
room.setID(rs.getLong(1)); room.setID(rs.getLong(1));
room.setNaturalLanguageName(rs.getString(3)); room.setCreationDate(new Date(Long.parseLong(rs.getString(2).trim()))); // creation date
room.setDescription(rs.getString(4)); room.setModificationDate(new Date(Long.parseLong(rs.getString(3).trim()))); // modification date
room.setCanOccupantsChangeSubject(rs.getInt(5) == 1 ? true : false); room.setNaturalLanguageName(rs.getString(5));
room.setMaxUsers(rs.getInt(6)); room.setDescription(rs.getString(6));
room.setModerated(rs.getInt(7) == 1 ? true : false); room.setCanOccupantsChangeSubject(rs.getInt(7) == 1 ? true : false);
room.setInvitationRequiredToEnter(rs.getInt(8) == 1 ? true : false); room.setMaxUsers(rs.getInt(8));
room.setCanOccupantsInvite(rs.getInt(9) == 1 ? true : false); room.setModerated(rs.getInt(9) == 1 ? true : false);
room.setPassword(rs.getString(10)); room.setInvitationRequiredToEnter(rs.getInt(10) == 1 ? true : false);
room.setCanAnyoneDiscoverJID(rs.getInt(11) == 1 ? true : false); room.setCanOccupantsInvite(rs.getInt(11) == 1 ? true : false);
room.setLogEnabled(rs.getInt(12) == 1 ? true : false); room.setPassword(rs.getString(12));
room.setSubject(rs.getString(13)); room.setCanAnyoneDiscoverJID(rs.getInt(13) == 1 ? true : false);
room.setLogEnabled(rs.getInt(14) == 1 ? true : false);
room.setSubject(rs.getString(15));
List rolesToBroadcast = new ArrayList(); List rolesToBroadcast = new ArrayList();
String roles = Integer.toBinaryString(rs.getInt(14)); String roles = Integer.toBinaryString(rs.getInt(16));
if (roles.charAt(0) == '1') { if (roles.charAt(0) == '1') {
rolesToBroadcast.add("moderator"); rolesToBroadcast.add("moderator");
} }
...@@ -200,20 +202,22 @@ public class MUCPersistenceManager { ...@@ -200,20 +202,22 @@ public class MUCPersistenceManager {
throw new IllegalArgumentException("Room " + room.getName() + " was not found in the database."); throw new IllegalArgumentException("Room " + room.getName() + " was not found in the database.");
} }
room.setID(rs.getLong(1)); room.setID(rs.getLong(1));
room.setNaturalLanguageName(rs.getString(2)); room.setCreationDate(new Date(Long.parseLong(rs.getString(2).trim()))); // creation date
room.setDescription(rs.getString(3)); room.setModificationDate(new Date(Long.parseLong(rs.getString(3).trim()))); // modification date
room.setCanOccupantsChangeSubject(rs.getInt(4) == 1 ? true : false); room.setNaturalLanguageName(rs.getString(4));
room.setMaxUsers(rs.getInt(5)); room.setDescription(rs.getString(5));
room.setPublicRoom(rs.getInt(6) == 1 ? true : false); room.setCanOccupantsChangeSubject(rs.getInt(6) == 1 ? true : false);
room.setModerated(rs.getInt(7) == 1 ? true : false); room.setMaxUsers(rs.getInt(7));
room.setInvitationRequiredToEnter(rs.getInt(8) == 1 ? true : false); room.setPublicRoom(rs.getInt(8) == 1 ? true : false);
room.setCanOccupantsInvite(rs.getInt(9) == 1 ? true : false); room.setModerated(rs.getInt(9) == 1 ? true : false);
room.setPassword(rs.getString(10)); room.setInvitationRequiredToEnter(rs.getInt(10) == 1 ? true : false);
room.setCanAnyoneDiscoverJID(rs.getInt(11) == 1 ? true : false); room.setCanOccupantsInvite(rs.getInt(11) == 1 ? true : false);
room.setLogEnabled(rs.getInt(12) == 1 ? true : false); room.setPassword(rs.getString(12));
room.setSubject(rs.getString(13)); room.setCanAnyoneDiscoverJID(rs.getInt(13) == 1 ? true : false);
room.setLogEnabled(rs.getInt(14) == 1 ? true : false);
room.setSubject(rs.getString(15));
List rolesToBroadcast = new ArrayList(); List rolesToBroadcast = new ArrayList();
String roles = Integer.toBinaryString(rs.getInt(14)); String roles = Integer.toBinaryString(rs.getInt(16));
if (roles.charAt(0) == '1') { if (roles.charAt(0) == '1') {
rolesToBroadcast.add("moderator"); rolesToBroadcast.add("moderator");
} }
...@@ -287,15 +291,13 @@ public class MUCPersistenceManager { ...@@ -287,15 +291,13 @@ public class MUCPersistenceManager {
* @param room The room to save its configuration. * @param room The room to save its configuration.
*/ */
public static void saveToDB(MUCRoom room) { public static void saveToDB(MUCRoom room) {
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();
if (room.wasSavedToDB()) { if (room.wasSavedToDB()) {
pstmt = con.prepareStatement(UPDATE_ROOM); pstmt = con.prepareStatement(UPDATE_ROOM);
pstmt.setString(1, StringUtils.dateToMillis(nowDate)); pstmt.setString(1, StringUtils.dateToMillis(room.getModificationDate()));
pstmt.setString(2, room.getNaturalLanguageName()); pstmt.setString(2, room.getNaturalLanguageName());
pstmt.setString(3, room.getDescription()); pstmt.setString(3, room.getDescription());
pstmt.setInt(4, (room.canOccupantsChangeSubject() ? 1 : 0)); pstmt.setInt(4, (room.canOccupantsChangeSubject() ? 1 : 0));
...@@ -315,8 +317,8 @@ public class MUCPersistenceManager { ...@@ -315,8 +317,8 @@ public class MUCPersistenceManager {
else { else {
pstmt = con.prepareStatement(ADD_ROOM); pstmt = con.prepareStatement(ADD_ROOM);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, StringUtils.dateToMillis(nowDate)); pstmt.setString(2, StringUtils.dateToMillis(room.getCreationDate()));
pstmt.setString(3, StringUtils.dateToMillis(nowDate)); pstmt.setString(3, StringUtils.dateToMillis(room.getModificationDate()));
pstmt.setString(4, room.getName()); pstmt.setString(4, room.getName());
pstmt.setString(5, room.getNaturalLanguageName()); pstmt.setString(5, room.getNaturalLanguageName());
pstmt.setString(6, room.getDescription()); pstmt.setString(6, room.getDescription());
...@@ -331,7 +333,7 @@ public class MUCPersistenceManager { ...@@ -331,7 +333,7 @@ public class MUCPersistenceManager {
pstmt.setInt(15, (room.isLogEnabled() ? 1 : 0)); pstmt.setInt(15, (room.isLogEnabled() ? 1 : 0));
pstmt.setString(16, room.getSubject()); pstmt.setString(16, room.getSubject());
pstmt.setInt(17, marshallRolesToBroadcast(room)); pstmt.setInt(17, marshallRolesToBroadcast(room));
pstmt.setString(18, StringUtils.dateToMillis(nowDate)); pstmt.setString(18, StringUtils.dateToMillis(new Date()));
pstmt.setInt(19, 1); // the room starts always "in memory" pstmt.setInt(19, 1); // the room starts always "in memory"
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
...@@ -400,14 +402,12 @@ public class MUCPersistenceManager { ...@@ -400,14 +402,12 @@ 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.setString(1, StringUtils.dateToMillis(nowDate)); pstmt.setString(1, StringUtils.dateToMillis(new Date()));
pstmt.setBoolean(2, inMemory); pstmt.setBoolean(2, inMemory);
pstmt.setLong(3, room.getID()); pstmt.setLong(3, room.getID());
pstmt.executeUpdate(); pstmt.executeUpdate();
...@@ -429,14 +429,12 @@ public class MUCPersistenceManager { ...@@ -429,14 +429,12 @@ 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.setString(1, StringUtils.dateToMillis(new Date()));
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
......
...@@ -11,10 +11,7 @@ ...@@ -11,10 +11,7 @@
package org.jivesoftware.messenger.muc.spi; package org.jivesoftware.messenger.muc.spi;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.messenger.muc.*; import org.jivesoftware.messenger.muc.*;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
...@@ -141,6 +138,16 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable { ...@@ -141,6 +138,16 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
*/ */
private long roomID = -1; private long roomID = -1;
/**
* The date when the room was created.
*/
private Date creationDate;
/**
* The last date when the room's configuration was modified.
*/
private Date modificationDate;
/** /**
* Create a new chat room. * Create a new chat room.
* *
...@@ -168,6 +175,22 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable { ...@@ -168,6 +175,22 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
this.roomID = roomID; this.roomID = roomID;
} }
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(Date modificationDate) {
this.modificationDate = modificationDate;
}
public MUCRole getRole() throws UnauthorizedException { public MUCRole getRole() throws UnauthorizedException {
return role; return role;
} }
......
...@@ -235,7 +235,17 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -235,7 +235,17 @@ public class MUCRoomImpl implements MUCRoom {
* will always be -1. Otherwise a value will be obtained from the database. * will always be -1. Otherwise a value will be obtained from the database.
*/ */
private long roomID = -1; private long roomID = -1;
/**
* The date when the room was created.
*/
private Date creationDate;
/**
* The last date when the room's configuration was modified.
*/
private Date modificationDate;
/** /**
* Indicates if the room is present in the database. * Indicates if the room is present in the database.
*/ */
...@@ -255,6 +265,8 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -255,6 +265,8 @@ public class MUCRoomImpl implements MUCRoom {
this.description = roomname; this.description = roomname;
this.router = packetRouter; this.router = packetRouter;
this.startTime = System.currentTimeMillis(); this.startTime = System.currentTimeMillis();
this.creationDate = new Date(startTime);
this.modificationDate = new Date(startTime);
// TODO Allow to set the history strategy from the configuration form? // TODO Allow to set the history strategy from the configuration form?
roomHistory = new MUCRoomHistory(this, new HistoryStrategy(server.getHistoryStrategy())); roomHistory = new MUCRoomHistory(this, new HistoryStrategy(server.getHistoryStrategy()));
role = new RoomRole(this); role = new RoomRole(this);
...@@ -297,6 +309,22 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -297,6 +309,22 @@ public class MUCRoomImpl implements MUCRoom {
this.roomID = roomID; this.roomID = roomID;
} }
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(Date modificationDate) {
this.modificationDate = modificationDate;
}
public MUCRole getRole() { public MUCRole getRole() {
return role; return role;
} }
......
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