Changeset 458
- Timestamp:
- 06/11/07 22:44:18
- Files:
-
- trunk/storage/db.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/storage/db.py
r457 r458 86 86 def xrecall(self, cls, expr=None): 87 87 """Yield a sequence of Unit instances which satisfy the expression.""" 88 if self.logflags & logflags.RECALL: 89 self.log(logflags.RECALL.message(unit_cls, expr)) 90 88 91 clsname = cls.__name__ 89 92 … … 120 123 unit.cleanse() 121 124 yield unit 122 123 def recall(self, cls, expr=None):124 """Return a sequence of Unit instances which satisfy the expression."""125 return [x for x in self.xrecall(cls, expr)]126 125 127 126 def reserve(self, unit): … … 169 168 def save(self, unit, forceSave=False): 170 169 """Update storage from unit's data (if unit.dirty()).""" 171 if unit.dirty() or forceSave: 170 if self.logflags & logflags.SAVE: 171 self.log(logflags.SAVE.message(unit, forceSave)) 172 173 if forceSave or unit.dirty(): 172 174 self.schema[unit.__class__.__name__].save(**unit._properties) 173 175 unit.cleanse() … … 175 177 def destroy(self, unit): 176 178 """Delete the unit.""" 179 if self.logflags & logflags.DESTROY: 180 self.log(logflags.DESTROY.message(unit)) 181 177 182 table = self.schema[unit.__class__.__name__] 178 183 table.delete(**unit._properties) … … 233 238 if not isinstance(query, dejavu.Query): 234 239 query = dejavu.Query(*query) 240 241 if self.logflags & logflags.VIEW: 242 self.log(logflags.VIEW.message(query, distinct)) 235 243 236 244 data = self.select(query, distinct=distinct) … … 253 261 def multirecall(self, relation, expr): 254 262 """Yield Unit instance sets which satisfy the expression.""" 263 if self.logflags & logflags.RECALL: 264 self.log(logflags.RECALL.message(relation, expr)) 265 255 266 # Gather attribute list. 256 267 allattrs = [] … … 307 318 308 319 def create_database(self): 320 if self.logflags & logflags.DDL: 321 self.log(logflags.DDL.message("create database")) 309 322 self.schema.create_database() 310 323 311 324 def drop_database(self): 325 if self.logflags & logflags.DDL: 326 self.log(logflags.DDL.message("drop database")) 312 327 self.schema.drop_database() 313 328 … … 331 346 def create_storage(self, cls): 332 347 """Create storage for the given class.""" 348 if self.logflags & logflags.DDL: 349 self.log(logflags.DDL.message("create storage %s" % cls)) 333 350 # Attach to self.schema, which should call CREATE TABLE. 334 351 self.schema[cls.__name__] = self._make_table(cls) … … 348 365 349 366 def drop_storage(self, cls): 367 if self.logflags & logflags.DDL: 368 self.log(logflags.DDL.message("drop storage %s" % cls)) 350 369 del self.schema[cls.__name__] 351 370 352 371 def rename_storage(self, oldname, newname): 372 if self.logflags & logflags.DDL: 373 self.log(logflags.DDL.message("rename storage from %s to %s" 374 % (oldname, newname))) 353 375 self.schema.rename(oldname, newname) 354 376 355 377 def add_property(self, cls, name): 378 if self.logflags & logflags.DDL: 379 self.log(logflags.DDL.message("add property %s %s" % 380 (cls, name))) 356 381 if not self.has_property(cls, name): 357 382 table = self.schema[cls.__name__] … … 362 387 363 388 def drop_property(self, cls, name): 389 if self.logflags & logflags.DDL: 390 self.log(logflags.DDL.message("drop property %s %s" % 391 (cls, name))) 364 392 if self.has_property(cls, name): 365 393 del self.schema[cls.__name__][name] 366 394 367 395 def rename_property(self, cls, oldname, newname): 396 if self.logflags & logflags.DDL: 397 self.log(logflags.DDL.message( 398 "rename property %s from %s to %s" % 399 (cls, oldname, newname))) 368 400 t = self.schema[cls.__name__] 369 401
