Mercurial > p > roundup > code
comparison roundup/backends/rdbms_common.py @ 3489:87e512f87bae
common initialization code and detectors interface
moved to hyperdb.py (patch from rfe [SF#413165])
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Tue, 24 Jan 2006 08:27:54 +0000 |
| parents | 602bb26a9485 |
| children | 7be25d75c3d5 |
comparison
equal
deleted
inserted
replaced
| 3488:e4177cf4d30d | 3489:87e512f87bae |
|---|---|
| 1 # $Id: rdbms_common.py,v 1.162 2006-01-20 02:42:35 richard Exp $ | 1 # $Id: rdbms_common.py,v 1.163 2006-01-24 08:27:54 a1s Exp $ |
| 2 ''' Relational database (SQL) backend common code. | 2 ''' Relational database (SQL) backend common code. |
| 3 | 3 |
| 4 Basics: | 4 Basics: |
| 5 | 5 |
| 6 - map roundup classes to relational tables | 6 - map roundup classes to relational tables |
| 1227 ''' The handle to a particular class of nodes in a hyperdatabase. | 1227 ''' The handle to a particular class of nodes in a hyperdatabase. |
| 1228 | 1228 |
| 1229 All methods except __repr__ and getnode must be implemented by a | 1229 All methods except __repr__ and getnode must be implemented by a |
| 1230 concrete backend Class. | 1230 concrete backend Class. |
| 1231 ''' | 1231 ''' |
| 1232 | |
| 1233 def __init__(self, db, classname, **properties): | |
| 1234 '''Create a new class with a given name and property specification. | |
| 1235 | |
| 1236 'classname' must not collide with the name of an existing class, | |
| 1237 or a ValueError is raised. The keyword arguments in 'properties' | |
| 1238 must map names to property objects, or a TypeError is raised. | |
| 1239 ''' | |
| 1240 for name in 'creation activity creator actor'.split(): | |
| 1241 if properties.has_key(name): | |
| 1242 raise ValueError, '"creation", "activity", "creator" and '\ | |
| 1243 '"actor" are reserved' | |
| 1244 | |
| 1245 self.classname = classname | |
| 1246 self.properties = properties | |
| 1247 self.db = weakref.proxy(db) # use a weak ref to avoid circularity | |
| 1248 self.key = '' | |
| 1249 | |
| 1250 # should we journal changes (default yes) | |
| 1251 self.do_journal = 1 | |
| 1252 | |
| 1253 # do the db-related init stuff | |
| 1254 db.addclass(self) | |
| 1255 | |
| 1256 self.auditors = {'create': [], 'set': [], 'retire': [], 'restore': []} | |
| 1257 self.reactors = {'create': [], 'set': [], 'retire': [], 'restore': []} | |
| 1258 | 1232 |
| 1259 def schema(self): | 1233 def schema(self): |
| 1260 ''' A dumpable version of the schema that we can store in the | 1234 ''' A dumpable version of the schema that we can store in the |
| 1261 database | 1235 database |
| 1262 ''' | 1236 ''' |
| 2317 for prop, propclass in self.getprops().items(): | 2291 for prop, propclass in self.getprops().items(): |
| 2318 if isinstance(propclass, String) and propclass.indexme: | 2292 if isinstance(propclass, String) and propclass.indexme: |
| 2319 self.db.indexer.add_text((self.classname, nodeid, prop), | 2293 self.db.indexer.add_text((self.classname, nodeid, prop), |
| 2320 str(self.get(nodeid, prop))) | 2294 str(self.get(nodeid, prop))) |
| 2321 | 2295 |
| 2322 | |
| 2323 # | |
| 2324 # Detector interface | |
| 2325 # | |
| 2326 def audit(self, event, detector): | |
| 2327 '''Register a detector | |
| 2328 ''' | |
| 2329 l = self.auditors[event] | |
| 2330 if detector not in l: | |
| 2331 self.auditors[event].append(detector) | |
| 2332 | |
| 2333 def fireAuditors(self, action, nodeid, newvalues): | |
| 2334 '''Fire all registered auditors. | |
| 2335 ''' | |
| 2336 for audit in self.auditors[action]: | |
| 2337 audit(self.db, self, nodeid, newvalues) | |
| 2338 | |
| 2339 def react(self, event, detector): | |
| 2340 '''Register a detector | |
| 2341 ''' | |
| 2342 l = self.reactors[event] | |
| 2343 if detector not in l: | |
| 2344 self.reactors[event].append(detector) | |
| 2345 | |
| 2346 def fireReactors(self, action, nodeid, oldvalues): | |
| 2347 '''Fire all registered reactors. | |
| 2348 ''' | |
| 2349 for react in self.reactors[action]: | |
| 2350 react(self.db, self, nodeid, oldvalues) | |
| 2351 | |
| 2352 # | 2296 # |
| 2353 # import / export support | 2297 # import / export support |
| 2354 # | 2298 # |
| 2355 def export_list(self, propnames, nodeid): | 2299 def export_list(self, propnames, nodeid): |
| 2356 ''' Export a node - generate a list of CSV-able data in the order | 2300 ''' Export a node - generate a list of CSV-able data in the order |
