[elephant-devel] make-instance with :from-oid

Lukas Gießmann lukas.giessmann at hotmail.de
Wed Feb 24 08:58:07 UTC 2010


Hi list,

I need to create some objects from their oid. But I noticed that there is always created an object of the given type even if there is no object stored with the passed oid or if there is stored another object (another class) with the passed oid.
Here is a simple example of this problem:

CL-USER> (elephant:defpclass TopicC ()
      ((id :accessor id
    :initarg :id
    :index t)
       (name :accessor name
      :initarg :name
      :index t))
    (:index t))
#<ELEPHANT:PERSISTENT-METACLASS TOPICC>
CL-USER> (elephant:defpclass OccurrenceC ()
      ((id :accessor id
    :initarg :id
    :index t)
       (value :accessor value
       :initarg :value
       :index t))
      (:index t))
#<ELEPHANT:PERSISTENT-METACLASS OCCURRENCEC>

CL-USER> (make-instance 'TopicC :id "top-1" :name "name-1")
#<TOPICC oid:2>
CL-USER> (make-instance 'OccurrenceC :id "occ-1" :value "value-1")
#<OCCURRENCEC oid:5>

CL-USER> (make-instance 'TopicC :from-oid 5)
#<TOPICC oid:5>
CL-USER> (type-of (make-instance 'TopicC :from-oid 5))
TOPICC

CL-USER> (id (make-instance 'TopicC :from-oid 5))
"occ-1"
CL-USER> (name (make-instance 'TopicC :from-oid 5))
;causes the following error:
;The slot NAME is unbound in the object #<TOPICC oid:5>.
;   [Condition of type UNBOUND-SLOT]
CL-USER> (value (make-instance 'TopicC :from-oid 5))
;causes the following error:
;There is no applicable method for the generic function
;  #<STANDARD-GENERIC-FUNCTION VALUE (1)>
;when called with arguments
;  (#<TOPICC oid:5>).
;   [Condition of type SIMPLE-ERROR]

CL-USER> (make-instance 'TopicC :from-oid 999) ;works even if the passed oid does not exist
#<TOPICC oid:999>


So when I use an oid that stores an object that is not of the given class, there is no error thrown or no warning.
Is there any possibility to be sure that the given oid stores an object of the given class?


Best regards

Lukas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/elephant-devel/attachments/20100224/b20ccd09/attachment.html>


More information about the elephant-devel mailing list