comparison sat_pubsub/pgsql_storage.py @ 260:f0cd02c032b3

publish model management
author Goffi <goffi@goffi.org>
date Mon, 06 May 2013 00:26:37 +0200
parents 6fe7da6b4b32
children 7b821432d012
comparison
equal deleted inserted replaced
259:6fe7da6b4b32 260:f0cd02c032b3
72 'leaf': { 72 'leaf': {
73 "pubsub#persist_items": True, 73 "pubsub#persist_items": True,
74 "pubsub#deliver_payloads": True, 74 "pubsub#deliver_payloads": True,
75 "pubsub#send_last_published_item": 'on_sub', 75 "pubsub#send_last_published_item": 'on_sub',
76 const.OPT_ACCESS_MODEL: const.VAL_AMODEL_DEFAULT, 76 const.OPT_ACCESS_MODEL: const.VAL_AMODEL_DEFAULT,
77 const.OPT_PUBLISH_MODEL: const.VAL_PMODEL_DEFAULT,
77 }, 78 },
78 'collection': { 79 'collection': {
79 "pubsub#deliver_payloads": True, 80 "pubsub#deliver_payloads": True,
80 "pubsub#send_last_published_item": 'on_sub', 81 "pubsub#send_last_published_item": 'on_sub',
81 const.OPT_ACCESS_MODEL: const.VAL_AMODEL_DEFAULT, 82 const.OPT_ACCESS_MODEL: const.VAL_AMODEL_DEFAULT,
83 const.OPT_PUBLISH_MODEL: const.VAL_PMODEL_DEFAULT,
82 } 84 }
83 } 85 }
84 86
85 def __init__(self, dbpool): 87 def __init__(self, dbpool):
86 self.dbpool = dbpool 88 self.dbpool = dbpool
94 cursor.execute("""SELECT node_type, 96 cursor.execute("""SELECT node_type,
95 persist_items, 97 persist_items,
96 deliver_payloads, 98 deliver_payloads,
97 send_last_published_item, 99 send_last_published_item,
98 access_model, 100 access_model,
101 publish_model
99 FROM nodes 102 FROM nodes
100 WHERE node=%s""", 103 WHERE node=%s""",
101 (nodeIdentifier,)) 104 (nodeIdentifier,))
102 row = cursor.fetchone() 105 row = cursor.fetchone()
103 106
108 configuration = { 111 configuration = {
109 'pubsub#persist_items': row[1], 112 'pubsub#persist_items': row[1],
110 'pubsub#deliver_payloads': row[2], 113 'pubsub#deliver_payloads': row[2],
111 'pubsub#send_last_published_item': row[3], 114 'pubsub#send_last_published_item': row[3],
112 const.OPT_ACCESS_MODEL:row[4], 115 const.OPT_ACCESS_MODEL:row[4],
116 const.OPT_PUBLISH_MODEL:row[5],
113 } 117 }
114 node = LeafNode(nodeIdentifier, configuration) 118 node = LeafNode(nodeIdentifier, configuration)
115 node.dbpool = self.dbpool 119 node.dbpool = self.dbpool
116 return node 120 return node
117 elif row[0] == 'collection': 121 elif row[0] == 'collection':
118 configuration = { 122 configuration = {
119 'pubsub#deliver_payloads': row[2], 123 'pubsub#deliver_payloads': row[2],
120 'pubsub#send_last_published_item': row[3], 124 'pubsub#send_last_published_item': row[3],
121 const.OPT_ACCESS_MODEL: row[4], 125 const.OPT_ACCESS_MODEL: row[4],
126 const.OPT_PUBLISH_MODEL:row[5],
122 } 127 }
123 node = CollectionNode(nodeIdentifier, configuration) 128 node = CollectionNode(nodeIdentifier, configuration)
124 node.dbpool = self.dbpool 129 node.dbpool = self.dbpool
125 return node 130 return node
126 131
143 148
144 owner = owner.userhost() 149 owner = owner.userhost()
145 try: 150 try:
146 cursor.execute("""INSERT INTO nodes 151 cursor.execute("""INSERT INTO nodes
147 (node, node_type, persist_items, 152 (node, node_type, persist_items,
148 deliver_payloads, send_last_published_item, access_model) 153 deliver_payloads, send_last_published_item, access_model, publish_model)
149 VALUES 154 VALUES
150 (%s, 'leaf', %s, %s, %s, %s)""", 155 (%s, 'leaf', %s, %s, %s, %s, %s)""",
151 (nodeIdentifier, 156 (nodeIdentifier,
152 config['pubsub#persist_items'], 157 config['pubsub#persist_items'],
153 config['pubsub#deliver_payloads'], 158 config['pubsub#deliver_payloads'],
154 config['pubsub#send_last_published_item'], 159 config['pubsub#send_last_published_item'],
155 config[const.OPT_ACCESS_MODEL], 160 config[const.OPT_ACCESS_MODEL],
161 config[const.OPT_PUBLISH_MODEL],
156 ) 162 )
157 ) 163 )
158 except cursor._pool.dbapi.IntegrityError: 164 except cursor._pool.dbapi.IntegrityError:
159 raise error.NodeExists() 165 raise error.NodeExists()
160 166