X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=mop.lisp;h=4ea60683b33184e8e93e2d66b54380639512baf1;hb=6ff5ef506bb52b4a98cb7a0b3726f5d3a9637944;hp=695b4e9ef790e8a5bca7ea8d78e2ba6315999ea3;hpb=d6af219e32386c64ef95b8ff0dd8900ea92371fc;p=hyperobject.git diff --git a/mop.lisp b/mop.lisp index 695b4e9..4ea6068 100644 --- a/mop.lisp +++ b/mop.lisp @@ -11,15 +11,12 @@ ;;;; in Text, HTML, and XML formats. This includes hyperlinking ;;;; capability and sub-objects. ;;;; -;;;; $Id: mop.lisp,v 1.75 2003/05/26 21:43:05 kevin Exp $ +;;;; $Id: mop.lisp,v 1.83 2003/07/11 18:02:41 kevin Exp $ ;;;; ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg ;;;; ************************************************************************* -(in-package :hyperobject) - -(eval-when (:compile-toplevel :execute) - (declaim (optimize (speed 2) (safety 2) (compilation-speed 0) (debug 2)))) +(in-package #:hyperobject) ;; Main class @@ -40,7 +37,13 @@ (version :initarg :version :initform nil :accessor version :documentation "Version number for class") - (sql-name :initarg :sql-name :initform nil) + (closures :initarg :closures :initform nil + :accessor closures + :documentation "Closures to call on slot chnages") + (sql-name :initarg :sql-name :accessor sql-name :initform nil + :documentation "SQL Name for this class") + (guid :initarg :guid :accessor guid :initform nil + :documentation "ID string for this class") ;;; The remainder of these fields are calculated one time ;;; in finalize-inheritence. @@ -53,6 +56,9 @@ (direct-rules :type list :initform nil :initarg :direct-rules :accessor direct-rules :documentation "List of rules to fire on slot changes.") + (direct-views :type list :initform nil :initarg :direct-views + :accessor direct-views + :documentation "List of views") (class-id :type integer :initform nil :accessor class-id :documentation "Unique ID for the class") @@ -98,7 +104,6 @@ (print-unreadable-object (obj s :type t :identity t) (format s "~S" (name obj)))) -#+(or cmu scl sbcl) (defmethod validate-superclass ((class hyperobject-class) (superclass standard-class)) t) @@ -146,7 +151,7 @@ (when (and ,required (null value)) (error "hyperobject class slot ~A must have a value" name)) (list name `',value)) - #+(or allegro sbcl cmu scl) + #+(or allegro sbcl cmu scl openmcl) (declare (ignore slot-name required)) ) @@ -215,55 +220,67 @@ (atom (ensure-keyword vt)) (cons - (cons (ensure-keyword (car vt)) (cdr vt))) + (list (ensure-keyword (car vt)) (cadr vt))) (t t))) -#+ignore -(defmethod compute-effective-slot-definition :around ((cl hyperobject-class) #+ho-normal-cesd name dsds) - #+allegro (declare (ignore name)) +(defmethod compute-effective-slot-definition :around ((cl hyperobject-class) + #+ho-normal-cesd name + dsds) + (declare (ignore #+ho-normal-cesd name)) + (let ((esd (call-next-method))) + (if (typep esd 'hyperobject-esd) + (compute-hyperobject-esd esd dsds) + esd))) + +(defun compute-hyperobject-esd (esd dsds) (let* ((dsd (car dsds)) (value-type (canonicalize-value-type (slot-value dsd 'value-type)))) - (multiple-value-bind (sql-type length) (value-type-to-sql-type value-type) - (setf (slot-value dsd 'sql-type) sql-type) - (setf (slot-value dsd 'type) (value-type-to-lisp-type value-type)) - (let ((ia (compute-effective-slot-definition-initargs cl #+lispworks name dsds))) - (apply - #'make-instance 'hyperobject-esd - :value-type value-type - :sql-type sql-type - :length length - :print-formatter (slot-value dsd 'print-formatter) - :subobject (slot-value dsd 'subobject) - :hyperlink (slot-value dsd 'hyperlink) - :hyperlink-parameters (slot-value dsd 'hyperlink-parameters) - :description (slot-value dsd 'description) - :user-name (slot-value dsd 'user-name) - :user-name-plural (slot-value dsd 'user-name-plural) - :index (slot-value dsd 'index) - :value-constraint (slot-value dsd 'value-constraint) - :null-allowed (slot-value dsd 'null-allowed) - ia))))) - -(defmethod compute-effective-slot-definition :around ((cl hyperobject-class) #+ho-normal-cesd name dsds) - #+ho-normal-cesd (declare (ignore name)) - (let* ((esd (call-next-method)) - (dsd (car dsds)) - (value-type (canonicalize-value-type (slot-value dsd 'value-type)))) - (multiple-value-bind (sql-type length) (value-type-to-sql-type value-type) - (setf (slot-value esd 'sql-type) sql-type) - (setf (slot-value esd 'length) length) - (setf (slot-value esd 'type) (value-type-to-lisp-type value-type)) - (setf (slot-value esd 'value-type) value-type) - (setf (slot-value esd 'user-name) - (aif (slot-value dsd 'user-name) - it - (string-downcase (symbol-name (slot-definition-name dsd))))) - (dolist (name '(print-formatter subobject hyperlink hyperlink-parameters - description value-constraint index null-allowed)) - (setf (slot-value esd name) (slot-value dsd name))) - esd))) - + (multiple-value-bind (sql-type sql-length) + (value-type-to-sql-type value-type) + (setf (esd-sql-type esd) sql-type) + (setf (esd-sql-length esd) sql-length)) + (setf (slot-value esd 'type) (value-type-to-lisp-type value-type)) + (setf (esd-value-type esd) value-type) + (setf (esd-user-name esd) + (aif (dsd-user-name dsd) + it + (string-downcase (symbol-name (slot-definition-name dsd))))) + (setf (esd-sql-name esd) + (aif (dsd-sql-name dsd) + it + (lisp-name-to-sql-name (slot-definition-name dsd)))) + (setf (esd-sql-name esd) + (aif (dsd-sql-name dsd) + it + (lisp-name-to-sql-name (slot-definition-name dsd)))) + (dolist (name '(print-formatter subobject hyperlink hyperlink-parameters + description value-constraint indexed null-allowed + unique short-description void-text read-only-groups + hidden-groups unit disable-predicate view-type + list-of-values stored)) + (setf (slot-value esd name) (slot-value dsd name))) + esd)) + +(defun lisp-name-to-sql-name (lisp) + "Convert a lisp name (atom or list, string or symbol) into a canonical +SQL name" + (unless (stringp lisp) + (setq lisp + (typecase lisp + (symbol (symbol-name lisp)) + (t (write-to-string lisp))))) + (do* ((len (length lisp)) + (sql (make-string len)) + (i 0 (1+ i))) + ((= i len) (string-upcase sql)) + (declare (fixnum i) + (simple-string sql)) + (setf (schar sql i) + (let ((c (char lisp i))) + (case c + ((#\- #\$ #\+ #\#) #\_) + (otherwise c)))))) #+ho-normal-cesd (setq cl:*features* (delete :ho-normal-cesd cl:*features*)) @@ -276,10 +293,13 @@ (or (eq type 'string) (and (listp type) (some #'(lambda (x) (eq x 'string)) type)))) +(defun base-value-type (value-type) + (if (atom value-type) + value-type + (car value-type))) + (defun value-type-to-lisp-type (value-type) - (case (if (atom value-type) - value-type - (car value-type)) + (case (base-value-type value-type) ((:string :cdata :varchar :char) '(or null string)) (:character @@ -288,7 +308,7 @@ '(or null fixnum)) (:boolean '(or null boolean)) - (:integer + ((:integer :long-integer) '(or null integer)) ((:float :single-float) '(or null single-float)) @@ -299,17 +319,19 @@ (defun value-type-to-sql-type (value-type) "Return two values, the sql type and field length." - (let ((type (if (atom value-type) - value-type - (car value-type))) + (let ((type (base-value-type value-type)) (length (when (consp value-type) (cadr value-type)))) (values (case type - ((:string :cdata) - :string) + ((:char :character) + :char) + (:varchar + :varchar) ((:fixnum :integer) :integer) + (:long-integer + :long-integer) (:boolean :boolean) ((:float :single-float) @@ -375,7 +397,7 @@ ':function (compile nil method-lambda) init-args-values))))) -#+(or allegro scl) +#+(or allegro scl openmcl) (progn ;; One entry for each class with lazy readers defined. The value is a plist mapping ;; slot-name to a lazy reader, each of which is a list of a function and slot-names. @@ -404,7 +426,7 @@ (setf (getf (gethash (find-class class-name) *lazy-readers*) slot-name) nil)) - ) ;; #+(or allegro scl) + ) ;; #+(or allegro sc openmcll) (defun finalize-subobjects (cl) @@ -430,7 +452,7 @@ `(hyperobject::def-lazy-reader ,(name-class subobject) ,(name-slot subobject) ,(lookup subobject) ,@(lookup-keys subobject))) - #+(or sbcl cmu lispworks allegro scl) + #+(or sbcl cmu lispworks allegro scl openmcl) (apply #'ensure-lazy-reader (name-class subobject) (name-slot subobject) (lookup subobject) (lookup-keys subobject))) @@ -455,12 +477,17 @@ (user-name cl)) 2))) - (dolist (name '(user-name description)) + (dolist (name '(user-name description version guid sql-name + direct-views direct-rules)) (awhen (slot-value cl name) (setf (slot-value cl name) (etypecase (slot-value cl name) (cons (car it)) - ((or string symbol) it)))))) + ((or string symbol) it))))) + + (unless (sql-name cl) + (setf (sql-name cl) (lisp-name-to-sql-name (class-name cl)))) + ) (defun finalize-documentation (cl) "Calculate class documentation slot"