# HG changeset patch # User Ralph Meijer # Date 1099775011 0 # Node ID 8cdbc27c467a788447bcf14cb67c596ad0832708 # Parent ad08e021b4d5df0a1b70f6ed667857ebb16b1e74 Add get_affiliations() and get_subscriptions() to Storage. Add AffiliationsService as a subclass of backend.AffiliationsService. diff -r ad08e021b4d5 -r 8cdbc27c467a idavoll/pgsql_backend.py --- a/idavoll/pgsql_backend.py Sat Nov 06 21:02:33 2004 +0000 +++ b/idavoll/pgsql_backend.py Sat Nov 06 21:03:31 2004 +0000 @@ -191,6 +191,29 @@ return None + def get_affiliations(self, entity): + return self.dbpool.runQuery("""SELECT node, affiliation FROM entities + JOIN affiliations ON + (affiliations.entity_id=entities.id) + JOIN nodes ON + (nodes.id=affiliations.node_id) + WHERE jid=%s""", + (entity.full().encode('utf8'),)) + + def get_subscriptions(self, entity): + d = self.dbpool.runQuery("""SELECT node, jid, resource, subscription + FROM entities JOIN subscriptions ON + (subscriptions.entity_id=entities.id) + JOIN nodes ON + (nodes.id=subscriptions.node_id) + WHERE jid=%s""", + (entity.full().encode('utf8'),)) + d.addCallback(self._convert_subscription_jids) + return d + + def _convert_subscription_jids(self, subscriptions): + return [(node, jid.JID('%s/%s' % (subscriber, resource)), subscription) + for node, subscriber, resource, subscription in subscriptions] class BackendService(backend.BackendService): """ PostgreSQL backend Service for a JEP-0060 pubsub service """ @@ -206,3 +229,6 @@ class SubscriptionService(backend.SubscriptionService): pass + +class AffiliationsService(backend.AffiliationsService): + pass