Commit 5f348ec6 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-40] Automatically wiping existing pseudo roster items on new create.

[GATE-46] Logistical error causes buddy list to be wiped on migration from py transports.  Disabled deletes for now.
[GATE-45] Pseudo roster is now cleaned up.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5423 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0bf16614
......@@ -3,7 +3,7 @@ ALTER TABLE gatewayRegistration ADD nickname NVARCHAR(255);
/* Add pseudo roster table */
CREATE TABLE gatewayPseudoRoster (
registrationID INTEGER NOT NULL,
registrationID BIGINT NOT NULL,
username NVARCHAR(255) NOT NULL,
nickname NVARCHAR(255),
groups NVARCHAR(255)
......
......@@ -1303,17 +1303,17 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* @see org.jivesoftware.wildfire.roster.RosterEventListener#contactDeleted(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem)
*/
public void contactDeleted(Roster roster, RosterItem item) {
if (!item.getJid().getDomain().equals(this.getJID().getDomain())) {
// Not ours, not our problem.
return;
}
try {
TransportSession session = sessionManager.getSession(roster.getUsername());
session.removeContact(item);
}
catch (NotFoundException e) {
// TODO: Should maybe do something about this
}
// if (!item.getJid().getDomain().equals(this.getJID().getDomain())) {
// // Not ours, not our problem.
// return;
// }
// try {
// TransportSession session = sessionManager.getSession(roster.getUsername());
// session.removeContact(item);
// }
// catch (NotFoundException e) {
// // TODO: Should maybe do something about this
// }
}
/**
......
......@@ -10,7 +10,6 @@
package org.jivesoftware.wildfire.gateway;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.container.Plugin;
import org.jivesoftware.wildfire.container.PluginManager;
......@@ -100,7 +99,6 @@ public class GatewayPlugin implements Plugin {
private void maybeStartService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName);
trInstance.startInstance();
Log.info("Starting transport service: "+serviceName);
}
/**
......@@ -109,7 +107,6 @@ public class GatewayPlugin implements Plugin {
public void enableService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName);
trInstance.enable();
Log.info("Enabling transport service: "+serviceName);
}
/**
......@@ -118,7 +115,6 @@ public class GatewayPlugin implements Plugin {
public void disableService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName);
trInstance.disable();
Log.info("Disabling transport service: "+serviceName);
}
/**
......
......@@ -15,7 +15,6 @@ import org.jivesoftware.database.DbConnectionManager;
import java.sql.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.List;
import java.util.Set;
/**
......
......@@ -35,6 +35,8 @@ public class PseudoRosterItem {
"UPDATE gatewayPseudoRoster SET nickname=? WHERE registrationID=? AND username=?";
private static final String SET_GROUPS =
"UPDATE gatewayPseudoRoster SET groups=? WHERE registrationID=? AND username=?";
private static final String REMOVE_ROSTER_ITEM =
"DELETE FROM gatewayPseudoRoster WHERE registrationID=? AND username=?";
private long registrationID;
private String username;
......@@ -58,7 +60,15 @@ public class PseudoRosterItem {
this.nickname = nickname;
this.groups = groups;
try {
insertIntoDb();
// Clean up potentially already existing item.
removeFromDb();
try {
// Insert new roster item.
insertIntoDb();
}
catch (Exception e) {
Log.error(e);
}
}
catch (Exception e) {
Log.error(e);
......@@ -207,7 +217,7 @@ public class PseudoRosterItem {
}
/**
* Inserts a new registration into the database.
* Inserts a new roster item into the database.
*/
private void insertIntoDb() throws SQLException {
Connection con = null;
......@@ -241,6 +251,29 @@ public class PseudoRosterItem {
}
}
/**
* Removeds a roster item from the database.
*/
private void removeFromDb() throws SQLException {
Connection con = null;
PreparedStatement pstmt = null;
boolean abortTransaction = false;
try {
con = DbConnectionManager.getTransactionConnection();
pstmt = con.prepareStatement(REMOVE_ROSTER_ITEM);
pstmt.setLong(1, registrationID);
pstmt.setString(2, username);
pstmt.executeUpdate();
}
catch (SQLException sqle) {
abortTransaction = true;
throw sqle;
}
finally {
DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction);
}
}
private void loadFromDb() throws NotFoundException {
Connection con = null;
PreparedStatement pstmt = null;
......
......@@ -12,8 +12,12 @@ package org.jivesoftware.wildfire.gateway;
import org.xmpp.packet.JID;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.database.DbConnectionManager;
import java.util.Collection;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;
/**
* Handles retrieving pseudo rosters and other related tasks.
......@@ -22,6 +26,9 @@ import java.util.Collection;
*/
public class PseudoRosterManager {
private static final String REMOVE_ROSTER =
"DELETE FROM gatewayPseudoRoster WHERE registrationID=?";
/**
* Manages registration information.
* @see org.jivesoftware.wildfire.gateway.RegistrationManager
......@@ -65,4 +72,28 @@ public class PseudoRosterManager {
return getPseudoRoster(registration);
}
/**
* Removes a pseudo roster entirely.
*
* @param registrationID ID to be removed.
*/
public void removePseudoRoster(Long registrationID) throws SQLException {
Connection con = null;
PreparedStatement pstmt = null;
boolean abortTransaction = false;
try {
con = DbConnectionManager.getTransactionConnection();
pstmt = con.prepareStatement(REMOVE_ROSTER);
pstmt.setLong(1, registrationID);
pstmt.executeUpdate();
}
catch (SQLException sqle) {
abortTransaction = true;
throw sqle;
}
finally {
DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction);
}
}
}
......@@ -44,6 +44,8 @@ public class RegistrationManager implements Startable {
"SELECT registrationID FROM gatewayRegistration WHERE transportType=? ORDER BY jid";
private static final String USER_GATEWAY_REGISTRATIONS =
"SELECT registrationID FROM gatewayRegistration WHERE jid=? AND transportType=?";
private static final String DELETE_PSEUDO_ROSTER =
"DELETE FROM gatewayPseudoRoster WHERE registrationID=?";
public void start() {
......@@ -82,6 +84,10 @@ public class RegistrationManager implements Startable {
pstmt = con.prepareStatement(DELETE_REGISTRATION);
pstmt.setLong(1, registration.getRegistrationID());
pstmt.executeUpdate();
pstmt = con.prepareStatement(DELETE_PSEUDO_ROSTER);
pstmt.setLong(1, registration.getRegistrationID());
pstmt.executeUpdate();
}
catch (SQLException sqle) {
Log.error(sqle);
......
......@@ -110,6 +110,8 @@ public class TransportInstance implements PropertyEventListener {
return;
}
Log.info("Starting transport service: "+type.toString());
transport = null;
//Log.debug("Loading class "+nameOfClass);
......@@ -146,6 +148,8 @@ public class TransportInstance implements PropertyEventListener {
return;
}
Log.info("Stopping transport service: "+type.toString());
PropertyEventDispatcher.removeListener(this);
try {
componentManager.removeComponent(this.subDomain);
......
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