[Initial ucw-elephant-site clinton@unknownlamer.org**20081204014743 Automatically connects/disconnects from a store controller and provides a standard location to discover the store controller ] { hunk ./golgonooza.asd 27 - (:file "elephant-utils") - (:file "elephant-query-view")))) + (:file "elephant-utils" :depends-on ("elephant-packages")) + (:file "elephant-query-view" :depends-on ("elephant-packages")) + (:file "elephant-site" :depends-on ("elephant-packages"))))) hunk ./src/elephant/elephant-packages.lisp 21 - (:use :common-lisp :elephant :org.unknownlamer.golgonooza.web) + (:use :common-lisp :elephant :org.unknownlamer.golgonooza.web + :org.unknownlamer.golgonooza.site-control) hunk ./src/elephant/elephant-packages.lisp 28 - :elephant-query-view-mixin) + :elephant-query-view-mixin + + :ucw-elephant-site + :site-store-controller) addfile ./src/elephant/elephant-site.lisp hunk ./src/elephant/elephant-site.lisp 1 - +;; elephant-site.lisp --- + +;; Copyright (C) 2008 Clinton Ebadi + +;; Author: Clinton Ebadi + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +(in-package :org.unknownlamer.golgonooza.elephant) + +(defclass ucw-elephant-site (ucw-site) + ((store-spec :accessor store-spec :initarg :store-spec + :documentation "Either an elephant database spec or a + pathname. If the store spec is a list then it is passed + directly to elephant:open-store. If the store spec is a + pathname it is assumed to be a BDB backed db in the + DATA-ROOT of the site.") + (store :reader site-store-controller :initform nil)) + (:documentation "Automatically open and close an Elephant data store + when starting and stopping an application")) + +(defmethod start-site :before ((site ucw-elephant-site)) + (with-slots (store) site + (unless store + (setf store (open-store (let ((db-spec (store-spec site))) + (if (listp db-spec) + db-spec + (list :bdb (data-root-path site db-spec)))) + :recover t :deadlock-detect t))))) + +(defmethod stop-site :after ((site ucw-elephant-site)) + (with-slots (store) site + (when store + (close-store store) + (if (eq *store-controller* store) + (setq *store-controller* nil)) + (setf store nil)))) }