Mercurial > libervia-pubsub
changeset 55:7c4dfef5d964
Implement create_node() in Storage.
Add NodeCreationService.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Fri, 05 Nov 2004 17:06:08 +0000 |
parents | 62fdb37234e5 |
children | 55fa890ef60b |
files | idavoll/pgsql_backend.py |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/idavoll/pgsql_backend.py Fri Nov 05 17:05:36 2004 +0000 +++ b/idavoll/pgsql_backend.py Fri Nov 05 17:06:08 2004 +0000 @@ -156,9 +156,45 @@ return None + def create_node(self, node_id, owner): + return self.dbpool.runInteraction(self._create_node, node_id, + owner) + + def _create_node(self, cursor, node_id, owner): + try: + cursor.execute("""INSERT INTO nodes (node) VALUES (%s)""", + (node_id.encode('utf8'))) + except: + raise backend.NodeExists + + cursor.execute("""SELECT 1 from entities where jid=%s""", + (owner.encode('utf8'))) + + if not cursor.fetchone(): + cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", + (owner.encode('utf8'))) + + try: + cursor.execute("""INSERT INTO affiliations + (node_id, entity_id, affiliation) + SELECT n.id, e.id, 'owner' FROM + (SELECT id FROM nodes WHERE node=%s) AS n + CROSS JOIN + (SELECT id FROM entities WHERE jid=%s) AS e""", + (node_id.encode('utf8'), + owner.encode('utf8'))) + except Exception, e: + print e + + return None + + class BackendService(backend.BackendService): """ PostgreSQL backend Service for a JEP-0060 pubsub service """ +class NodeCreationService(backend.NodeCreationService): + pass + class PublishService(backend.PublishService): pass