comparison idavoll/pgsql_backend.py @ 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 40ac06941edc
children 0fa161c00ed9
comparison
equal deleted inserted replaced
54:62fdb37234e5 55:7c4dfef5d964
154 if cursor.rowcount != 1: 154 if cursor.rowcount != 1:
155 raise backend.NotSubscribed 155 raise backend.NotSubscribed
156 156
157 return None 157 return None
158 158
159 def create_node(self, node_id, owner):
160 return self.dbpool.runInteraction(self._create_node, node_id,
161 owner)
162
163 def _create_node(self, cursor, node_id, owner):
164 try:
165 cursor.execute("""INSERT INTO nodes (node) VALUES (%s)""",
166 (node_id.encode('utf8')))
167 except:
168 raise backend.NodeExists
169
170 cursor.execute("""SELECT 1 from entities where jid=%s""",
171 (owner.encode('utf8')))
172
173 if not cursor.fetchone():
174 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""",
175 (owner.encode('utf8')))
176
177 try:
178 cursor.execute("""INSERT INTO affiliations
179 (node_id, entity_id, affiliation)
180 SELECT n.id, e.id, 'owner' FROM
181 (SELECT id FROM nodes WHERE node=%s) AS n
182 CROSS JOIN
183 (SELECT id FROM entities WHERE jid=%s) AS e""",
184 (node_id.encode('utf8'),
185 owner.encode('utf8')))
186 except Exception, e:
187 print e
188
189 return None
190
191
159 class BackendService(backend.BackendService): 192 class BackendService(backend.BackendService):
160 """ PostgreSQL backend Service for a JEP-0060 pubsub service """ 193 """ PostgreSQL backend Service for a JEP-0060 pubsub service """
161 194
195 class NodeCreationService(backend.NodeCreationService):
196 pass
197
162 class PublishService(backend.PublishService): 198 class PublishService(backend.PublishService):
163 pass 199 pass
164 200
165 class NotificationService(backend.NotificationService): 201 class NotificationService(backend.NotificationService):
166 pass 202 pass