Commit 5b571fec authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

1. Modified queries to include new column "naturalLanguageName" in mucRoom.

2. Added missing Statement.execute() to save new room's subject.
3. Replaced several #execute with #executeUpdate


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@220 b35dd754-fafc-0310-a699-88a17e54d16e
parent 045b3cc2
...@@ -41,15 +41,15 @@ import org.jivesoftware.util.StringUtils; ...@@ -41,15 +41,15 @@ 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, description, canChangeSubject, maxUsers, " + "SELECT roomID, name, naturalLanguageRoom, description, canChangeSubject, maxUsers, " +
"moderated, invitationRequired, canInvite, " + "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, description, canChangeSubject, maxUsers, publicRoom, " + "SELECT roomID, naturalLanguageRoom, description, canChangeSubject, maxUsers, " +
"moderated, invitationRequired, canInvite, password, " + "publicRoom, moderated, invitationRequired, canInvite, password, " +
"canDiscoverJID, logEnabled, subject, rolesToBroadcast " + "canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"FROM mucRoom WHERE name=?"; "FROM mucRoom WHERE name=?";
private static final String LOAD_AFFILIATIONS = private static final String LOAD_AFFILIATIONS =
...@@ -57,14 +57,15 @@ public class MUCPersistenceManager { ...@@ -57,14 +57,15 @@ 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 modificationDate=?, name=?, description=?, canChangeSubject=?, maxUsers=?, " + "UPDATE mucRoom SET modificationDate=?, naturalLanguageRoom=?, description=?, " +
"publicRoom=?, moderated=?, invitationRequired=?, canInvite=?, password=?, " + "canChangeSubject=?, maxUsers=?, publicRoom=?, moderated=?, invitationRequired=?, " +
"canDiscoverJID=?, logEnabled=?, rolesToBroadcast=?, inMemory=? WHERE roomID=?"; "canInvite=?, password=?, 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, naturalLanguageRoom, " +
"maxUsers, publicRoom, moderated, invitationRequired, canInvite, password, canDiscoverJID, " + "description, canChangeSubject, maxUsers, publicRoom, moderated, invitationRequired, " +
"logEnabled, subject, rolesToBroadcast, lastActiveDate, inMemory) " + "canInvite, password, canDiscoverJID, logEnabled, subject, rolesToBroadcast, " +
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; "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 =
...@@ -107,18 +108,19 @@ public class MUCPersistenceManager { ...@@ -107,18 +108,19 @@ public class MUCPersistenceManager {
while (rs.next()) { while (rs.next()) {
room = new MUCPersistentRoomSurrogate(chatserver, rs.getString(2), packetRouter); room = new MUCPersistentRoomSurrogate(chatserver, rs.getString(2), packetRouter);
room.setID(rs.getLong(1)); room.setID(rs.getLong(1));
room.setDescription(rs.getString(3)); room.setNaturalLanguageName(rs.getString(3));
room.setCanOccupantsChangeSubject(rs.getInt(4) == 1 ? true : false); room.setDescription(rs.getString(4));
room.setMaxUsers(rs.getInt(5)); room.setCanOccupantsChangeSubject(rs.getInt(5) == 1 ? true : false);
room.setModerated(rs.getInt(6) == 1 ? true : false); room.setMaxUsers(rs.getInt(6));
room.setInvitationRequiredToEnter(rs.getInt(7) == 1 ? true : false); room.setModerated(rs.getInt(7) == 1 ? true : false);
room.setCanOccupantsInvite(rs.getInt(8) == 1 ? true : false); room.setInvitationRequiredToEnter(rs.getInt(8) == 1 ? true : false);
room.setPassword(rs.getString(9)); room.setCanOccupantsInvite(rs.getInt(9) == 1 ? true : false);
room.setCanAnyoneDiscoverJID(rs.getInt(10) == 1 ? true : false); room.setPassword(rs.getString(10));
room.setLogEnabled(rs.getInt(11) == 1 ? true : false); room.setCanAnyoneDiscoverJID(rs.getInt(11) == 1 ? true : false);
room.setSubject(rs.getString(12)); room.setLogEnabled(rs.getInt(12) == 1 ? true : false);
room.setSubject(rs.getString(13));
List rolesToBroadcast = new ArrayList(); List rolesToBroadcast = new ArrayList();
String roles = Integer.toBinaryString(rs.getInt(13)); String roles = Integer.toBinaryString(rs.getInt(14));
if (roles.charAt(0) == '1') { if (roles.charAt(0) == '1') {
rolesToBroadcast.add("moderator"); rolesToBroadcast.add("moderator");
} }
...@@ -198,19 +200,20 @@ public class MUCPersistenceManager { ...@@ -198,19 +200,20 @@ 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.setDescription(rs.getString(2)); room.setNaturalLanguageName(rs.getString(2));
room.setCanOccupantsChangeSubject(rs.getInt(3) == 1 ? true : false); room.setDescription(rs.getString(3));
room.setMaxUsers(rs.getInt(4)); room.setCanOccupantsChangeSubject(rs.getInt(4) == 1 ? true : false);
room.setPublicRoom(rs.getInt(5) == 1 ? true : false); room.setMaxUsers(rs.getInt(5));
room.setModerated(rs.getInt(6) == 1 ? true : false); room.setPublicRoom(rs.getInt(6) == 1 ? true : false);
room.setInvitationRequiredToEnter(rs.getInt(7) == 1 ? true : false); room.setModerated(rs.getInt(7) == 1 ? true : false);
room.setCanOccupantsInvite(rs.getInt(8) == 1 ? true : false); room.setInvitationRequiredToEnter(rs.getInt(8) == 1 ? true : false);
room.setPassword(rs.getString(9)); room.setCanOccupantsInvite(rs.getInt(9) == 1 ? true : false);
room.setCanAnyoneDiscoverJID(rs.getInt(10) == 1 ? true : false); room.setPassword(rs.getString(10));
room.setLogEnabled(rs.getInt(11) == 1 ? true : false); room.setCanAnyoneDiscoverJID(rs.getInt(11) == 1 ? true : false);
room.setSubject(rs.getString(12)); room.setLogEnabled(rs.getInt(12) == 1 ? true : false);
room.setSubject(rs.getString(13));
List rolesToBroadcast = new ArrayList(); List rolesToBroadcast = new ArrayList();
String roles = Integer.toBinaryString(rs.getInt(13)); String roles = Integer.toBinaryString(rs.getInt(14));
if (roles.charAt(0) == '1') { if (roles.charAt(0) == '1') {
rolesToBroadcast.add("moderator"); rolesToBroadcast.add("moderator");
} }
...@@ -293,7 +296,7 @@ public class MUCPersistenceManager { ...@@ -293,7 +296,7 @@ public class MUCPersistenceManager {
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(nowDate));
pstmt.setString(2, room.getName()); 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));
pstmt.setInt(5, room.getMaxUsers()); pstmt.setInt(5, room.getMaxUsers());
...@@ -315,21 +318,22 @@ public class MUCPersistenceManager { ...@@ -315,21 +318,22 @@ public class MUCPersistenceManager {
pstmt.setString(2, StringUtils.dateToMillis(nowDate)); pstmt.setString(2, StringUtils.dateToMillis(nowDate));
pstmt.setString(3, StringUtils.dateToMillis(nowDate)); pstmt.setString(3, StringUtils.dateToMillis(nowDate));
pstmt.setString(4, room.getName()); pstmt.setString(4, room.getName());
pstmt.setString(5, room.getDescription()); pstmt.setString(5, room.getNaturalLanguageName());
pstmt.setInt(6, (room.canOccupantsChangeSubject() ? 1 : 0)); pstmt.setString(6, room.getDescription());
pstmt.setInt(7, room.getMaxUsers()); pstmt.setInt(7, (room.canOccupantsChangeSubject() ? 1 : 0));
pstmt.setInt(8, (room.isPublicRoom() ? 1 : 0)); pstmt.setInt(8, room.getMaxUsers());
pstmt.setInt(9, (room.isModerated() ? 1 : 0)); pstmt.setInt(9, (room.isPublicRoom() ? 1 : 0));
pstmt.setInt(10, (room.isInvitationRequiredToEnter() ? 1 : 0)); pstmt.setInt(10, (room.isModerated() ? 1 : 0));
pstmt.setInt(11, (room.canOccupantsInvite() ? 1 : 0)); pstmt.setInt(11, (room.isInvitationRequiredToEnter() ? 1 : 0));
pstmt.setString(12, room.getPassword()); pstmt.setInt(12, (room.canOccupantsInvite() ? 1 : 0));
pstmt.setInt(13, (room.canAnyoneDiscoverJID() ? 1 : 0)); pstmt.setString(13, room.getPassword());
pstmt.setInt(14, (room.isLogEnabled() ? 1 : 0)); pstmt.setInt(14, (room.canAnyoneDiscoverJID() ? 1 : 0));
pstmt.setString(15, room.getSubject()); pstmt.setInt(15, (room.isLogEnabled() ? 1 : 0));
pstmt.setInt(16, marshallRolesToBroadcast(room)); pstmt.setString(16, room.getSubject());
pstmt.setString(17, StringUtils.dateToMillis(nowDate)); pstmt.setInt(17, marshallRolesToBroadcast(room));
pstmt.setInt(18, 1); // the room starts always "in memory" pstmt.setString(18, StringUtils.dateToMillis(nowDate));
pstmt.execute(); pstmt.setInt(19, 1); // the room starts always "in memory"
pstmt.executeUpdate();
} }
} }
catch (SQLException sqle) { catch (SQLException sqle) {
...@@ -359,17 +363,17 @@ public class MUCPersistenceManager { ...@@ -359,17 +363,17 @@ public class MUCPersistenceManager {
con = DbConnectionManager.getTransactionConnection(); con = DbConnectionManager.getTransactionConnection();
pstmt = con.prepareStatement(DELETE_AFFILIATIONS); pstmt = con.prepareStatement(DELETE_AFFILIATIONS);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.execute(); pstmt.executeUpdate();
pstmt.close(); pstmt.close();
pstmt = con.prepareStatement(DELETE_MEMBERS); pstmt = con.prepareStatement(DELETE_MEMBERS);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.execute(); pstmt.executeUpdate();
pstmt.close(); pstmt.close();
pstmt = con.prepareStatement(DELETE_ROOM); pstmt = con.prepareStatement(DELETE_ROOM);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.execute(); pstmt.executeUpdate();
// Update the room (in memory) to indicate the it's no longer in the database. // Update the room (in memory) to indicate the it's no longer in the database.
room.setSavedToDB(false); room.setSavedToDB(false);
...@@ -464,7 +468,7 @@ public class MUCPersistenceManager { ...@@ -464,7 +468,7 @@ public class MUCPersistenceManager {
pstmt = con.prepareStatement(UPDATE_SUBJECT); pstmt = con.prepareStatement(UPDATE_SUBJECT);
pstmt.setString(1, subject); pstmt.setString(1, subject);
pstmt.setLong(2, room.getID()); pstmt.setLong(2, room.getID());
pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -504,7 +508,7 @@ public class MUCPersistenceManager { ...@@ -504,7 +508,7 @@ public class MUCPersistenceManager {
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.setString(3, nickname); pstmt.setString(3, nickname);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -526,7 +530,7 @@ public class MUCPersistenceManager { ...@@ -526,7 +530,7 @@ public class MUCPersistenceManager {
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.setInt(3, newAffiliation); pstmt.setInt(3, newAffiliation);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -550,7 +554,7 @@ public class MUCPersistenceManager { ...@@ -550,7 +554,7 @@ public class MUCPersistenceManager {
pstmt.setString(1, nickname); pstmt.setString(1, nickname);
pstmt.setLong(2, room.getID()); pstmt.setLong(2, room.getID());
pstmt.setString(3, bareJID); pstmt.setString(3, bareJID);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -572,7 +576,7 @@ public class MUCPersistenceManager { ...@@ -572,7 +576,7 @@ public class MUCPersistenceManager {
pstmt = con.prepareStatement(DELETE_AFFILIATION); pstmt = con.prepareStatement(DELETE_AFFILIATION);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.execute(); pstmt.executeUpdate();
pstmt.close(); pstmt.close();
// Add them as a member. // Add them as a member.
...@@ -580,7 +584,7 @@ public class MUCPersistenceManager { ...@@ -580,7 +584,7 @@ public class MUCPersistenceManager {
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.setString(3, nickname); pstmt.setString(3, nickname);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -601,14 +605,14 @@ public class MUCPersistenceManager { ...@@ -601,14 +605,14 @@ public class MUCPersistenceManager {
pstmt = con.prepareStatement(DELETE_MEMBER); pstmt = con.prepareStatement(DELETE_MEMBER);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.execute(); pstmt.executeUpdate();
pstmt.close(); pstmt.close();
pstmt = con.prepareStatement(ADD_AFFILIATION); pstmt = con.prepareStatement(ADD_AFFILIATION);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.setInt(3, newAffiliation); pstmt.setInt(3, newAffiliation);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -630,7 +634,7 @@ public class MUCPersistenceManager { ...@@ -630,7 +634,7 @@ public class MUCPersistenceManager {
pstmt.setInt(1, newAffiliation); pstmt.setInt(1, newAffiliation);
pstmt.setLong(2, room.getID()); pstmt.setLong(2, room.getID());
pstmt.setString(3, bareJID); pstmt.setString(3, bareJID);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -663,7 +667,7 @@ public class MUCPersistenceManager { ...@@ -663,7 +667,7 @@ public class MUCPersistenceManager {
pstmt = con.prepareStatement(DELETE_MEMBER); pstmt = con.prepareStatement(DELETE_MEMBER);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -684,7 +688,7 @@ public class MUCPersistenceManager { ...@@ -684,7 +688,7 @@ public class MUCPersistenceManager {
pstmt = con.prepareStatement(DELETE_AFFILIATION); pstmt = con.prepareStatement(DELETE_AFFILIATION);
pstmt.setLong(1, room.getID()); pstmt.setLong(1, room.getID());
pstmt.setString(2, bareJID); pstmt.setString(2, bareJID);
pstmt.execute(); pstmt.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -717,7 +721,7 @@ public class MUCPersistenceManager { ...@@ -717,7 +721,7 @@ public class MUCPersistenceManager {
pstmt.setString(4, StringUtils.dateToMillis(entry.getDate())); pstmt.setString(4, StringUtils.dateToMillis(entry.getDate()));
pstmt.setString(5, entry.getSubject()); pstmt.setString(5, entry.getSubject());
pstmt.setString(6, entry.getBody()); pstmt.setString(6, entry.getBody());
pstmt.execute(); pstmt.executeUpdate();
return true; return true;
} }
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