Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

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

Changeset 85

Show
Ignore:
Timestamp:
08/11/05 18:11:04
Author:
fumanchu
Message:

BACKWARDS INCOMPATIBILITY: Sandbox.recall now returns a list. Use xrecall to return an iterator. Note that SM.recall methods should still be generators.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/__init__.py

    r84 r85  
    2222    del newUnit # or otherwise release the reference. 
    2323 
    24 Using recall(), you get an iterator: 
     24Using recall(), you get a list; using xrecall(), you get an iterator: 
    2525    for unit in sandbox.recall(cls, expr): 
    2626        do_something_with(unit) 
     
    611611        """migrate_class(cls, new_store). Copy all units of cls to new_store.""" 
    612612        new_store.create_storage(cls) 
    613         for unit in self.new_sandbox().recall(cls): 
     613        for unit in self.new_sandbox().xrecall(cls): 
    614614            new_store.reserve(unit) 
    615615            new_store.save(unit, True) 
     
    683683     
    684684    def forget(self, unit): 
    685         """forget(unit). Destroy unit, both in the cache and storage.""" 
     685        """Destroy unit, both in the cache and storage.""" 
    686686        cls = unit.__class__ 
    687687        store = self.arena.storage(cls) 
     
    696696        unit.sandbox = None 
    697697     
    698     def recall(self, cls, expr=None): 
    699         """recall(cls, expr=None) -> Recall units of cls which match expr.""" 
     698    def xrecall(self, cls, expr=None): 
     699        """Iterator over units of cls which match expr.""" 
    700700         
    701701        store = self.arena.storage(cls) 
     
    746746                    if confirmed: 
    747747                        yield unit 
     748     
     749    def recall(self, cls, expr=None): 
     750        """List of units of class 'cls' which match expr.""" 
     751        return [x for x in self.xrecall(cls, expr)] 
    748752     
    749753    def multirecall(self, *pairs): 
     
    805809         
    806810        If you need a single Unit which matches a more complex 
    807             expression, use recall().next(). 
     811            expression, use recall()[0] or xrecall().next(). 
    808812        """ 
    809813        expr = None 
     
    811815            expr = logic.filter(**kwargs) 
    812816        try: 
    813             return self.recall(cls, expr).next() 
     817            return self.xrecall(cls, expr).next() 
    814818        except StopIteration: 
    815819            return None 
  • trunk/doc/intro.html

    r84 r85  
    110110<pre>>>> import zookeeper 
    111111>>> box = zookeeper.arena.new_sandbox() 
    112 >>> [x for x in box.recall(zookeeper.Animal)] 
     112>>> box.recall(zookeeper.Animal) 
    113113[&lt;zookeeper.Animal object at 0x013281F0>, &lt;zookeeper.Animal object at 0x01328150>, 
    114114 &lt;zookeeper.Animal object at 0x01328130>, &lt;zookeeper.Animal object at 0x01328230>] 
    115 >>> [x for x in box.recall(zookeeper.Zoo)] 
     115>>> box.recall(zookeeper.Zoo) 
    116116[] 
    117117>>> zoo = zookeeper.Zoo(Name='San Diego Zoo', Size='38') 
  • trunk/doc/managing.html

    r84 r85  
    419419 
    420420<h4>Sorting Units</h4> 
    421 <p>When you recall Units, you receive a generator, and must iterate over 
    422 the values in some way. Often, this is accomplished with a list 
    423 comprehension: 
    424 <pre>f = logic.Expression(lambda x: 'Aa' in x.Name) 
    425 people = [x for x in sandbox.recall(Person, f)] 
    426 </pre> 
    427 However, the <tt>recall</tt> method doesn't do any sorting; you must sort 
    428 your list in your Python code. Dejavu provides a <tt>sort(attrs, 
    429 descending=False)</tt> function to assist you. It returns a function, which 
    430 you can then use in Python's sort function. Continuing our example: 
     421<p>When you recall Units, you receive a list. However, the <tt>recall</tt> 
     422method doesn't do any sorting; you must sort your list in your Python code. 
     423Dejavu provides a <tt>sort(attrs, descending=False)</tt> function to assist 
     424you in sorting Units. It returns a function, which you can then use in 
     425Python's sort function. Continuing our example: 
    431426<pre>sorted_people = people.sort(dejavu.sort('Size', 'Name'))</pre> 
    432427The most important issue (and the reason we don't just use 2.4's attrgetter), 
  • trunk/doc/modeling.html

    r84 r85  
    275275<h4>Recalling</h4> 
    276276<p>Once you have memorized a Unit or two, you will probably want to 
    277 recall them at some point. Sandboxes possess two member functions to 
     277recall them at some point. Sandboxes possess four member functions to 
    278278accomplish this.</p> 
    279279 
     
    293293</pre> 
    294294If you do not supply an Expression, all Units of the given Unit class 
    295 will be retrieved. Notice that the return value is *not* a list; it is a 
    296 generator (or other iterable). You must iterate over it to retrieve all 
    297 values. By returning an iterator, we allow some Storage Managers to load 
    298 Units in a more lazy fashion. If this is a huge burden for you, let me 
    299 know; I might be convinced to add a <tt>recall_list</tt> method.</p> 
     295will be retrieved in a list.</p> 
    300296 
    301297<p>If your Unit class defines an <tt>on_recall()</tt> method, it will be 
     
    306302unit will not be yielded back to the caller, nor placed in the Sandbox 
    307303cache.</p> 
     304 
     305<h5>xrecall()</h5> 
     306<p>Just like recall, but returns an iterator instead of a list. Use xrecall 
     307to load Units in a more lazy fashion.</p> 
    308308 
    309309<h5>unit()</h5> 
  • trunk/doc/storage.html

    r84 r85  
    156156        subclass.</li> 
    157157</ul> 
    158 <p>The shelve module does not yet support multirecall().</p> 
    159158 
    160159<h5>Common Database Configuration Entries</h5> 
  • trunk/engines.py

    r84 r85  
    323323        """Unit Collections obtained by executing the rules sometime in the past.""" 
    324324        f = logic.filter(EngineID=self.ID) 
    325         allSnap = [x for x in self.sandbox.recall(UnitCollection, f)] 
     325        allSnap = self.sandbox.recall(UnitCollection, f) 
    326326        allSnap.sort(dejavu.sort(u'Timestamp')) 
    327327        return allSnap 
  • trunk/storage/zoo_fixture.py

    r84 r85  
    171171         
    172172        # Exhibits 
    173         exes = [x for x in box.recall(zoo.Exhibit)] 
     173        exes = box.recall(zoo.Exhibit) 
    174174        self.assertEqual(len(exes), 2) 
    175175        if exes[0].Name == 'The Penguin Encounter': 
     
    197197            # We flush_all to ensure a DB hit each time. 
    198198            box.flush_all() 
    199             units = box.recall(cls, logic.Expression(lam)) 
    200             return len([x for x in units]) 
    201          
    202         zoos = [x for x in box.recall(zoo.Zoo)] 
     199            return len(box.recall(cls, logic.Expression(lam))) 
     200         
     201        zoos = box.recall(zoo.Zoo) 
    203202        self.assertEqual(zoos[0].dirty(), False) 
    204203        self.assertEqual(len(zoos), 4) 
     
    251250        box.flush_all() 
    252251        units = box.recall(zoo.Zoo, logic.Expression(lambda x: "_" in x.Name)) 
    253         self.assertEqual(len([x for x in units]), 1) 
     252        self.assertEqual(len(units), 1) 
    254253         
    255254        # This broke in MSAccess (storeado) in April 2005, due to a bug in 
     
    262261        e.bind_args(Year=2004) 
    263262        units = box.recall(zoo.Animal, e) 
    264         self.assertEqual(len([x for x in units]), 1) 
     263        self.assertEqual(len(units), 1) 
    265264     
    266265    def test_3_Aggregates(self): 
     
    326325            # the order of thread execution can not be guaranteed. 
    327326            box = zoo.arena.new_sandbox() 
    328             quadrupeds = [x for x in box.recall(zoo.Animal, f)] 
     327            quadrupeds = box.recall(zoo.Animal, f) 
    329328            self.assertEqual(len(quadrupeds), 4) 
    330329         
     
    383382        box = zoo.arena.new_sandbox() 
    384383         
    385         # Test box.unit inside of recall 
    386         for ape in box.recall(zoo.Animal, logic.filter(Name='Ape')): 
     384        # Test box.unit inside of xrecall 
     385        for ape in box.xrecall(zoo.Animal, logic.filter(Name='Ape')): 
    387386            mother = box.unit(zoo.Animal, ID=ape.Mother) 
    388387            if ape.ID == 11: 
     
    391390                self.assertEqual(mother.ID, 11) 
    392391         
    393         # Test recall inside of recall 
    394         for ape in box.recall(zoo.Animal, logic.filter(Name='Ape')): 
     392        # Test recall inside of xrecall 
     393        for ape in box.xrecall(zoo.Animal, logic.filter(Name='Ape')): 
    395394            children = 0 
    396395            for child in box.recall(zoo.Animal, logic.filter(Mother=ape.ID)): 
     
    401400                self.assertEqual(children, 0) 
    402401         
    403         # Test far associations inside of recall 
    404         for ape in box.recall(zoo.Animal, logic.filter(Name='Ape')): 
     402        # Test far associations inside of xrecall 
     403        for ape in box.xrecall(zoo.Animal, logic.filter(Name='Ape')): 
    405404            mother = ape.first(zoo.Animal) 
    406405            if ape.ID == 11: