[rucksack-devel] Re: Re: [rucksack-cvs] removing class instances from index

Arthur Lemmens alemmens at xs4all.nl
Thu Oct 19 19:11:52 UTC 2006


Vikram Bhandhoh wrote:

> I've tried this but it doesn't work for me.

OK, I've looked more closely at your code now.  The critical point
is that Rucksack's standard class and slot indexes map to the *ids*
of persistent objects, *not* to the objects themselves.

This is normally hidden from you when you use the implicit class and
slot indexing provided by Rucksack.  But in your case you're explicitly
manipulating the indexes, so instead of doing stuff like:

>     (index-delete (rucksack-class-index rs 'employee) (object-id emp) emp)

you should write:

      (index-delete (rucksack-class-index rs 'employee)
                    (object-id emp)
                    (object-id emp))

Ditto for the slot indexes.


Oh, and you're not supposed to keep references to persistent objects
outside of a WITH-TRANSACTION.  So the following part of your code
isn't safe:

> (defvar emp nil)
>
> (with-rucksack (rs *hacker-rucksack*)
>   (with-transaction ()
>     (setf emp (make-instance 'employee :person "vb" :salary 100 :job
> 'monkey :rucksack rs))
>     (add-rucksack-root emp rs)))

You don't really need this global EMP, because you can always find it
within a transaction by iterating across the rucksack roots or by
using the indexing mechanisms.

Arthur




More information about the rucksack-devel mailing list