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