[elephant-devel] storing instances of non-persistent class
Frank Schorr
franks-muc at web.de
Sun Mar 18 14:19:07 UTC 2007
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
More information about the elephant-devel
mailing list