Changeset 3694
- Timestamp:
- 07/30/08 13:21:33 (4 months ago)
- Files:
-
- trunk/bknr/datastore/src/data/object-tests.lisp (modified) (2 diffs)
- trunk/bknr/datastore/src/data/object.lisp (modified) (7 diffs)
- trunk/bknr/datastore/src/data/package.lisp (modified) (1 diff)
- trunk/bknr/datastore/src/data/tutorial.lisp (modified) (2 diffs)
- trunk/bknr/modules/feed/feed.lisp (modified) (1 diff)
- trunk/bknr/modules/text/article.lisp (modified) (1 diff)
- trunk/bknr/web/src/rss/rss.lisp (modified) (1 diff)
- trunk/bknr/web/src/sysclasses/user.lisp (modified) (2 diffs)
- trunk/build.lisp (modified) (1 diff)
- trunk/projects/bos/m2/allocation.lisp (modified) (1 diff)
- trunk/projects/bos/m2/m2.lisp (modified) (1 diff)
- trunk/projects/bos/m2/poi.lisp (modified) (2 diffs)
- trunk/projects/lisp-ecoop/src/participant.lisp (modified) (2 diffs)
- trunk/projects/unmaintained/raw-data/mcp/bluetooth.lisp (modified) (1 diff)
- trunk/projects/unmaintained/raw-data/mcp/sensors.lisp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/bknr/datastore/src/data/object-tests.lisp
r3692 r3694 48 48 (defvar *tests* (make-hash-table)) 49 49 50 (defmacro define-datastore-test (name & bodybody)50 (defmacro define-datastore-test (name &rest body) 51 51 `(setf (gethash ,name *tests*) 52 52 (make-instance 'datastore-test-class … … 119 119 (test-equal (all-store-objects) nil)) 120 120 121 (define-datastore-test :make-instance-in-anon-txn122 (with-transaction ()123 (make-instance 'store-object)))124 125 (define-datastore-test :make-object-in-anon-txn126 (with-transaction ()127 (make-object 'store-object)))128 129 121 (define-persistent-class parent () 130 122 ((child :update :initform nil))) trunk/bknr/datastore/src/data/object.lisp
r3691 r3694 92 92 (when (and (persistent-slot-p slotd) 93 93 (not (eq :restore (store-state *store*))) 94 (not ( member slot-name '(last-change id))))94 (not (eq 'last-change slot-name))) 95 95 (setf (slot-value object 'last-change) (current-transaction-timestamp))))) 96 96 … … 191 191 (aclmop::finalize-inheritance (find-class 'store-object)) 192 192 193 (defmethod initialize-instance :around ((object store-object) &rest initargs &key) 193 (defmethod initialize-instance :around 194 ((object store-object) &key &allow-other-keys) 194 195 (if (in-anonymous-transaction-p) 195 196 (prog1 … … 198 199 :function-symbol 'make-instance 199 200 :timestamp (get-universal-time) 200 :args (cons (class-name (class-of object)) initargs)) 201 :args (cons (class-name (class-of object)) 202 (loop for slotd in (class-slots (class-of object)) 203 for slot-name = (slot-definition-name slotd) 204 for slot-initarg = (first (slot-definition-initargs slotd)) 205 when (and slot-initarg 206 (slot-boundp object slot-name)) 207 appending (list slot-initarg (slot-value object slot-name))))) 201 208 (anonymous-transaction-log-buffer *current-transaction*))) 202 209 (call-next-method))) 203 210 204 (defmethod allocate-instance :around ((class persistent-class) &key) 205 (let* ((object (call-next-method)) 206 (subsystem (store-object-subsystem)) 207 (id (next-object-id subsystem))) 208 (incf (next-object-id subsystem)) 209 (setf (slot-value object 'id) id) 210 object)) 211 212 (defmethod initialize-instance :after ((object store-object) &key) 213 ;; This is called only when initially creating the (persistent) 214 ;; instance, not during restore. During restore, the 215 ;; INITIALIZE-TRANSIENT-INSTANCE function is called after the 216 ;; snapshot has been read, but before running the transaction log. 217 (initialize-transient-instance object)) 211 (defmethod initialize-instance :after ((object store-object) &key id &allow-other-keys) 212 (let ((subsystem (store-object-subsystem))) 213 (cond (id 214 ;; during restore, use the given ID 215 (when (>= id (next-object-id subsystem)) 216 (setf (next-object-id subsystem) (1+ id)))) 217 (t 218 ;; normal transaction: assign a new ID 219 (setf id (next-object-id subsystem)) 220 (incf (next-object-id subsystem)) 221 (setf (slot-value object 'id) id))))) 218 222 219 223 (defmethod print-object ((object store-object) stream) … … 241 245 :args (append (list object (if (symbolp class) class (class-name class))) args)))) 242 246 247 (defgeneric initialize-persistent-instance (store-object &key &allow-other-keys) 248 (:documentation 249 "Initializes the persistent aspects of a persistent object. This 250 method is called at the creation of a persistent object, but not when 251 the object is loaded from a snapshot.")) 252 243 253 (defgeneric initialize-transient-instance (store-object) 244 254 (:documentation 245 255 "Initializes the transient aspects of a persistent object. This 246 method is called after a persistent object has beeninitialized, also247 when the object is loaded from a snapshot , but before reading the248 transaction log.")) 249 256 method is called whenever a persistent object is initialized, also 257 when the object is loaded from a snapshot.")) 258 259 (defmethod initialize-persistent-instance ((object store-object) &key)) 250 260 (defmethod initialize-transient-instance ((object store-object))) 251 261 … … 455 465 ;; running Lisp image and objects of this class will be ignored. 456 466 (when class 457 (setf (next-object-id (store-object-subsystem)) object-id) 458 (let ((object (allocate-instance class))) 459 (assert (= object-id (slot-value object 'id))) 460 (dolist (index (class-slot-indices class 'id)) 461 (index-add index object))))))) 467 (make-instance class :id object-id))))) 462 468 463 469 (defun snapshot-read-slots (stream layouts) … … 636 642 (remove-transient-slot-initargs (find-class class-name) initargs) 637 643 initargs))) 644 (apply #'initialize-persistent-instance obj initargs) 645 (initialize-transient-instance obj) 638 646 (setf error nil) 639 647 obj) … … 642 650 643 651 (defun make-object (class-name &rest initargs) 644 "Make a persistent object of class named CLASS-NAME. Calls MAKE-INSTANCE with INITARGS." 645 (if (in-anonymous-transaction-p) 646 (apply #'make-instance class-name initargs) 647 (with-store-guard () 648 (execute (make-instance 'transaction 649 :function-symbol 'tx-make-object 650 :args (append (list class-name 651 :id (next-object-id (store-object-subsystem))) 652 initargs)))))) 652 "Make a persistent object of class named CLASS-NAME. Calls MAKE-INSTANCE with INITARGS." 653 (with-store-guard () 654 (execute (make-instance 'transaction 655 :function-symbol 'tx-make-object 656 :args (append (list class-name 657 :id (next-object-id (store-object-subsystem))) 658 initargs))))) 653 659 654 660 (defun tx-delete-object (id) trunk/bknr/datastore/src/data/package.lisp
r3689 r3694 52 52 #:cascading-delete-object 53 53 54 #:initialize-persistent-instance 54 55 #:initialize-transient-instance 55 56 trunk/bknr/datastore/src/data/tutorial.lisp
r3689 r3694 459 459 ;;; to be created using the function `MAKE-OBJECT'. This creates an 460 460 ;;; instance of the object inside a transaction, sets its ID slot 461 ;;; appropriately, and then calls `INITIALIZE-TRANSIENT-INSTANCE'. The 462 ;;; standard CLOS function `INITIALIZE-INSTANCE' is called when the 463 ;;; object is created inside a transaction, but not if the object is 464 ;;; being restored from the snapshot file. 465 ;;; `INITIALIZE-TRANSIENT-INSTANCE' is called at object creation 466 ;;; inside a transaction and at object creation during restore. It 467 ;;; must be specialized to initialize the transient slots (not logged 461 ;;; appropriately, and then calls `INITIALIZE-PERSISTENT-INSTANCE' and 462 ;;; `INITIALIZE-TRANSIENT-INSTANCE'. The first method is called when 463 ;;; the object is created inside a transaction, but not if the object 464 ;;; is being restored from the snapshot file. This method has to be 465 ;;; overridden in order to initialize persistent 466 ;;; slots. `INITIALIZE-TRANSIENT-INSTANCE' is called at object 467 ;;; creation inside a transaction and at object creation during 468 ;;; restore. It is used to initialize the transient slots (not logged 468 469 ;;; to the snapshot file) of a persistent object. 469 470 ;;; … … 816 817 ;;; after each slot value has been set, the method 817 818 ;;; `INITIALIZE-TRANSIENT-INSTANCE' is called for each created 818 ;;; object. 819 ;;; object. The method `INITIALIZE-PERSISTENT-INSTANCE' is not called, 820 ;;; as it has to be executed only once at the time the persistent 821 ;;; object is created. 819 822 820 823 ;;;## Garbage collecting blobs trunk/bknr/modules/feed/feed.lisp
r3689 r3694 24 24 (type :update :documentation "(or :rss091 :rss10 :rss20 :atom)") 25 25 (encoding :update :initform :iso-8859-1 :documentation "(or :utf8 :iso-8859-1)"))) 26 27 ;(defmethod initialize-transient-instance ((feed feed)) 28 ; (ignore-errors (update-feed feed))) 26 29 27 30 (defmethod print-object ((object feed) stream) trunk/bknr/modules/text/article.lisp
r3689 r3694 37 37 (article-text article)))) 38 38 39 (defmethod initialize- instance :after ((article article) &key)39 (defmethod initialize-persistent-instance :after ((article article) &key) 40 40 (setf (article-search-vector article) 41 41 (article-to-search-vector article))) trunk/bknr/web/src/rss/rss.lisp
r3689 r3694 177 177 (warn "no RSS channel defined for item ~A" item))) 178 178 179 (defmethod initialize- instance :after ((rss-item rss-item) &key)179 (defmethod initialize-persistent-instance :after ((rss-item rss-item) &key) 180 180 (add-item (rss-item-channel rss-item) rss-item)) 181 181 trunk/bknr/web/src/sysclasses/user.lisp
r3689 r3694 61 61 "unbound")))) 62 62 63 (defmethod initialize- instance ((user user) &key)63 (defmethod initialize-persistent-instance ((user user) &key) 64 64 (let* ((plaintext-password (slot-value user 'password)) 65 65 (password (when plaintext-password (crypt-md5 plaintext-password (make-salt))))) … … 73 73 ()) 74 74 75 (defmethod initialize- instance ((user smb-user) &key)75 (defmethod initialize-persistent-instance ((user smb-user) &key) 76 76 (let* ((plaintext-password (slot-value user 'password))) 77 77 (when plaintext-password trunk/build.lisp
r3688 r3694 192 192 193 193 (defun test () 194 (cl-gd::load-gd-glue) 194 (cl-gd::load-gd-glue) 195 195 (format t "~&;;; --- running tests~%") 196 196 (run-tests 197 #+(or)198 (cl-ppcre-run-no-failures-p)199 (cl-gd-run-no-failures-p)200 #+(or)201 (flexi-streams-no-failures-p)202 (unit-test:run-all-tests)203 (rt:do-tests)204 (fiveam-run-no-failures-p :bknr.datastore)205 #-darwin (fiveam-run-no-failures-p :bos.test)206 (progn #+(or) (fiveam-run-no-failures-p :it.bese.FiveAM)207 (warn "skipping :it.bese.FiveAM tests")208 t)209 (fiveam-run-no-failures-p 'json-test::json)210 ))211 197 #+(or) 198 (cl-ppcre-run-no-failures-p) 199 (cl-gd-run-no-failures-p) 200 #+(or) 201 (flexi-streams-no-failures-p) 202 (unit-test:run-all-tests) 203 (rt:do-tests) 204 (fiveam-run-no-failures-p :bknr.datastore) 205 #-darwin (fiveam-run-no-failures-p :bos.test) 206 (progn #+(or) (fiveam-run-no-failures-p :it.bese.FiveAM) 207 (warn "skipping :it.bese.FiveAM tests") 208 t) 209 (fiveam-run-no-failures-p 'json-test::json) 210 )) 211 trunk/projects/bos/m2/allocation.lisp
r3689 r3694 35 35 (store-object-id allocation-area)))) 36 36 37 (defmethod initialize- instance :after ((allocation-area allocation-area) &key)37 (defmethod initialize-persistent-instance :after ((allocation-area allocation-area) &key) 38 38 (with-slots (total-m2s free-m2s) allocation-area 39 39 (setf total-m2s (calculate-total-m2-count allocation-area)) trunk/projects/bos/m2/m2.lisp
r3689 r3694 279 279 (equal (class-of object) (find-class 'contract))) 280 280 281 (defmethod initialize- instance :after ((contract contract) &key)281 (defmethod initialize-persistent-instance :after ((contract contract) &key) 282 282 (pushnew contract (sponsor-contracts (contract-sponsor contract))) 283 283 (dolist (m2 (contract-m2s contract)) trunk/projects/bos/m2/poi.lisp
r3689 r3694 36 36 (apply #'make-object class-name rest)) 37 37 38 (defmethod initialize- instance :after ((poi-medium poi-medium) &key language title subtitle description poi)38 (defmethod initialize-persistent-instance :after ((poi-medium poi-medium) &key language title subtitle description poi) 39 39 (when poi 40 40 (push poi-medium (poi-media poi))) … … 85 85 poi)) 86 86 87 (defmethod initialize- instance :after ((poi poi) &key language title subtitle description)87 (defmethod initialize-persistent-instance :after ((poi poi) &key language title subtitle description) 88 88 (update-textual-attributes poi language 89 89 :title title trunk/projects/lisp-ecoop/src/participant.lisp
r3689 r3694 8 8 (:default-initargs :type "application/pdf" :submission (error ":submission argument missing while creating document"))) 9 9 10 (defmethod initialize- instance :after ((document document) &key)10 (defmethod initialize-persistent-instance :after ((document document) &key) 11 11 (with-slots (submission) document 12 12 (push document (submission-documents submission)))) … … 93 93 (apply fun (append args more)))) 94 94 95 (defmethod initialize- instance :after ((participant participant) &key)95 (defmethod initialize-persistent-instance :after ((participant participant) &key) 96 96 (make-email-list)) 97 97 trunk/projects/unmaintained/raw-data/mcp/bluetooth.lisp
r3689 r3694 89 89 (:metaclass persistent-class)) 90 90 91 (defmethod initialize- instance :after ((event bluetooth-event) &key)91 (defmethod initialize-persistent-instance :after ((event bluetooth-event) &key) 92 92 (with-slots (device) event 93 93 (push event (bluetooth-device-events device)) trunk/projects/unmaintained/raw-data/mcp/sensors.lisp
r3689 r3694 61 61 (format nil "sample_event_~(~A~)" (sensor-type sensor))) 62 62 63 (defmethod initialize- instance :after ((sensor sensor) &key)63 (defmethod initialize-persistent-instance :after ((sensor sensor) &key) 64 64 (let ((id (store-object-id sensor))) 65 65 (with-slots (name unit type) sensor
