[elephant-devel] storing instances of non-persistent class
Ian Eslick
eslick at csail.mit.edu
Sun Mar 18 20:49:46 UTC 2007
Frank,
We could certainly provide such an interface - currently we use the
MOP to find all the slots for a standard-object and serialize their
names and values. If we wrapped this in a method call, specific
classes could override the default behavior. The current default is
essentially like the example encode object example in the astore
manual, except that it uses the MOP to get all the effective slots
(see serializer2.lisp, the standard-object case in serialize).
And yes, you can rely on this behavior.
We have a more elegant means of implementing your example through the
use of derived indices. This makes sense if you don't need
durability of your standard objects, or do some complex computation
on them in memory and then store them to disk via an explicit store
to your persistent class slot. (i.e. persistent-class slots are
somewhat like btree index entries for persisting most lisp values)
========================
Derived Index Demo
========================
(in-package :elephant-tests)
(open-store *testbdb-spec*)
(defclass nonpers-class ()
((slot-a :accessor slot-a :initarg :slot-a)
(slot-b :accessor slot-b :initarg :slot-b)))
(defclass pers-class ()
((myslot :accessor myslot))
(:metaclass persistent-metaclass)
(:index t))
(defmethod derived-key-fn ((obj pers-class))
(slot-a (myslot obj)))
(add-class-derived-index 'pers-class 'nonpers-index-slot-a 'derived-
key-fn :populate nil)
(setf inst-1 (make-instance 'nonpers-class :slot-a "aaa" :slot-b "111"))
(setf inst-2 (make-instance 'nonpers-class :slot-a "bbb" :slot-b "222"))
(setf inst-3 (make-instance 'nonpers-class :slot-a "ccc" :slot-b "333"))
(setf pers-1 (make-instance 'pers-class))
(setf (myslot pers-1) inst-1)
(setf pers-2 (make-instance 'pers-class))
(setf (myslot pers-2) inst-2)
(setf pers-3 (make-instance 'pers-class))
(setf (myslot pers-3) inst-3)
(get-instances-by-value 'pers-class
'nonpers-index-slot-a
"bbb")
(get-instances-by-range 'pers-class
'nonpers-index-slot-a
"bbb" "ccc")
Let me know if you have questions about this. The Lispworks port is
making slow but steady progress!
Cheers,
Ian
On Mar 18, 2007, at 10:19 AM, Frank Schorr wrote:
>
> I was surprised to find that also objects which are
> not instances of a persistent-metaclass are handled and
> stored by elephant without complaints
> if they are slot values of a persistent class.
>
> In my code shown below, I expected to receive an undefined method
> error,
> similar to what is suggested by page 41 of
>
> http://www.franz.com/support/documentation/8.0/acache/doc/acache.pdf
>
> which requires that an encode-object method must be provided to
> indicate
> how a non-persitent object can be saved. Obviously, though this is not
> mentionned in the documentation, elephant can find this
> out by its own.
>
> Question 1: Can I rely on this, are there limitations ?
>
>
> The following commands work:
>
> (defclass nonpers-class ()
> ((slot-a :accessor slot-a :initarg :slot-a)
> (slot-b :accessor slot-b :initarg :slot-b)))
>
> (defmethod calc-key ((obj nonpers-class))
> (slot-a obj))
>
> (defclass pers-class ()
> ((myslot :accessor myslot)
> (myslot-key :index t))
> (:metaclass persistent-metaclass))
>
> (defmethod (setf myslot) :after (new-value (obj pers-class))
> (setf (slot-value obj 'myslot-key) (calc-key new-value)))
>
> (setf inst-1 (make-instance 'nonpers-class :slot-a "aaa" :slot-b
> "111"))
> (setf inst-2 (make-instance 'nonpers-class :slot-a "bbb" :slot-b
> "222"))
> (setf inst-3 (make-instance 'nonpers-class :slot-a "ccc" :slot-b
> "333"))
>
> (setf pers-1 (make-instance 'pers-class))
> (setf (myslot pers-1) inst-1)
>
> (setf pers-2 (make-instance 'pers-class))
> (setf (myslot pers-2) inst-2)
>
> (setf pers-3 (make-instance 'pers-class))
> (setf (myslot pers-3) inst-3)
>
> (get-instances-by-value 'pers-class
> 'myslot-key
> (calc-key (make-instance 'nonpers-
> class :slot-a "bbb" :slot-b "222")))
>
> This means a key is calculated for objects of a non-persistent class,
> and this key is used to retrieve such objects.
>
> Question 2: Do you think such approach is ok or way too complicated ?
>
> I would be happy to receive comments on the above.
>
> Best regards,
> Frank Schorr
>
> ______________________________________________________________________
> _
> Viren-Scan für Ihren PC! Jetzt für jeden. Sofort, online und
> kostenlos.
> Gleich testen! http://www.pc-sicherheit.web.de/freescan/?mc=022222
>
> _______________________________________________
> elephant-devel site list
> elephant-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/elephant-devel
More information about the elephant-devel
mailing list