Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 458

Show
Ignore:
Timestamp:
06/11/07 22:44:18
Author:
fumanchu
Message:

Added logging to db.py.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/storage/db.py

    r457 r458  
    8686    def xrecall(self, cls, expr=None): 
    8787        """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         
    8891        clsname = cls.__name__ 
    8992         
     
    120123            unit.cleanse() 
    121124            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)] 
    126125     
    127126    def reserve(self, unit): 
     
    169168    def save(self, unit, forceSave=False): 
    170169        """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(): 
    172174            self.schema[unit.__class__.__name__].save(**unit._properties) 
    173175            unit.cleanse() 
     
    175177    def destroy(self, unit): 
    176178        """Delete the unit.""" 
     179        if self.logflags & logflags.DESTROY: 
     180            self.log(logflags.DESTROY.message(unit)) 
     181         
    177182        table = self.schema[unit.__class__.__name__] 
    178183        table.delete(**unit._properties) 
     
    233238        if not isinstance(query, dejavu.Query): 
    234239            query = dejavu.Query(*query) 
     240         
     241        if self.logflags & logflags.VIEW: 
     242            self.log(logflags.VIEW.message(query, distinct)) 
    235243         
    236244        data = self.select(query, distinct=distinct) 
     
    253261    def multirecall(self, relation, expr): 
    254262        """Yield Unit instance sets which satisfy the expression.""" 
     263        if self.logflags & logflags.RECALL: 
     264            self.log(logflags.RECALL.message(relation, expr)) 
     265         
    255266        # Gather attribute list. 
    256267        allattrs = [] 
     
    307318     
    308319    def create_database(self): 
     320        if self.logflags & logflags.DDL: 
     321            self.log(logflags.DDL.message("create database")) 
    309322        self.schema.create_database() 
    310323     
    311324    def drop_database(self): 
     325        if self.logflags & logflags.DDL: 
     326            self.log(logflags.DDL.message("drop database")) 
    312327        self.schema.drop_database() 
    313328     
     
    331346    def create_storage(self, cls): 
    332347        """Create storage for the given class.""" 
     348        if self.logflags & logflags.DDL: 
     349            self.log(logflags.DDL.message("create storage %s" % cls)) 
    333350        # Attach to self.schema, which should call CREATE TABLE. 
    334351        self.schema[cls.__name__] = self._make_table(cls) 
     
    348365     
    349366    def drop_storage(self, cls): 
     367        if self.logflags & logflags.DDL: 
     368            self.log(logflags.DDL.message("drop storage %s" % cls)) 
    350369        del self.schema[cls.__name__] 
    351370     
    352371    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))) 
    353375        self.schema.rename(oldname, newname) 
    354376     
    355377    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))) 
    356381        if not self.has_property(cls, name): 
    357382            table = self.schema[cls.__name__] 
     
    362387     
    363388    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))) 
    364392        if self.has_property(cls, name): 
    365393            del self.schema[cls.__name__][name] 
    366394     
    367395    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))) 
    368400        t = self.schema[cls.__name__] 
    369401