changeset 62:8cdbc27c467a

Add get_affiliations() and get_subscriptions() to Storage. Add AffiliationsService as a subclass of backend.AffiliationsService.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 06 Nov 2004 21:03:31 +0000
parents ad08e021b4d5
children 60e95c60252d
files idavoll/pgsql_backend.py
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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