[Implement elephant-store-application-mixin and rename ucw-elephant-site clinton@unknownlamer.org**20081208075259 * ucw-elephant-site was renamed to elephant-store-site-mixin to better reflect its purpose * elephant-store-application-mixin opens and closes a store on startup and shutdown and binds elephant:*store-controller* to this controller around action execution. * When elephant-store-site/application-mixin are used together and the app-store-spec is nil the store-controller of the application is set to the store controller of the site. ] { hunk ./src/elephant/elephant-packages.lisp 30 - :ucw-elephant-site - :site-store-controller) + :elephant-store-site-mixin + :site-store-spec + :site-store-controller + :elephant-store-application-mixin + :app-store-spec + :app-store-controller) hunk ./src/elephant/elephant-site.lisp 22 -(defclass ucw-elephant-site (ucw-site) - ((store-spec :accessor store-spec :initarg :store-spec +(defclass elephant-store-site-mixin () + ((store-spec :accessor site-store-spec :initarg :store-spec hunk ./src/elephant/elephant-site.lisp 33 -(defmethod start-site :before ((site ucw-elephant-site)) +(defmethod start-site :before ((site elephant-store-site-mixin)) hunk ./src/elephant/elephant-site.lisp 36 - (setf store (open-store (let ((db-spec (store-spec site))) + (setf store (open-store (let ((db-spec (site-store-spec site))) hunk ./src/elephant/elephant-site.lisp 42 -(defmethod stop-site :after ((site ucw-elephant-site)) +(defmethod stop-site :after ((site elephant-store-site-mixin)) hunk ./src/elephant/elephant-site.lisp 49 + +(defclass elephant-store-application-mixin () + ((store-spec :accessor app-store-spec :initarg :store-spec + :initform nil + :documentation "An elephant database spec to be passed + directly to elephant:open-store.") + (store :accessor app-store-controller :initform nil)) + (:documentation "Open and close an elephant database at application + startup and shutdown and bind elephant:*store-controller* around + actions.")) + +(defmethod ucw-core:startup-application :before ((app elephant-store-application-mixin)) + (unless (app-store-controller app) + (setf (app-store-controller app) (apply #'open-store (app-store-spec app))))) + +(defmethod ucw-core:shutdown-application :after ((app elephant-store-application-mixin)) + (when (app-store-controller app) + (close-store (app-store-controller app)))) + +(defmethod ucw-core:handle-action :around (action + (app elephant-store-application-mixin) + session + frame) + (let ((*store-controller* (app-store-controller app))) + (call-next-method))) + +(defmethod start-site-application :before ((site elephant-store-site-mixin) (app elephant-store-application-mixin)) + (unless (app-store-spec app) + (setf (app-store-controller app) (site-store-controller site)))) + +(defmethod stop-site-application :before ((site elephant-store-site-mixin) (app elephant-store-application-mixin)) + (unless (app-store-spec app) + (setf (app-store-controller app) nil))) }