X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=mop.lisp;h=0a6f6f1da3fdd7fcc09d63e11f5745aa7e012818;hb=927d5f069190f0911510fac96298dde23e265840;hp=21c77bc288a563f74a6d3f306a65f3ed0f6dd16c;hpb=1255fdac4de4b06cf5e2c8fe5825a9d157dc1916;p=hyperobject.git diff --git a/mop.lisp b/mop.lisp index 21c77bc..0a6f6f1 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.74 2003/05/17 22:24:38 kevin Exp $ +;;;; $Id: mop.lisp,v 1.78 2003/06/20 08:50:38 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. @@ -215,51 +218,62 @@ (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)) - (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) +(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) + (multiple-value-bind (sql-type sql-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) - (dolist (name '(print-formatter subobject hyperlink hyperlink-parameters - description value-constraint index null-allowed user-name)) - (setf (slot-value esd name) (slot-value dsd name))) - esd))) - + (setf (slot-value esd 'sql-length) sql-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))))) + (setf (slot-value esd 'sql-name) + (aif (slot-value dsd 'sql-name) + it + (lisp-name-to-sql-name (slot-definition-name dsd)))) + (setf (slot-value esd 'sql-name) + (aif (slot-value dsd 'sql-name) + 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*)) @@ -272,10 +286,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 @@ -284,7 +301,7 @@ '(or null fixnum)) (:boolean '(or null boolean)) - (:integer + ((:integer :long-integer) '(or null integer)) ((:float :single-float) '(or null single-float)) @@ -295,17 +312,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) @@ -451,12 +470,16 @@ (user-name cl)) 2))) - (dolist (name '(user-name description)) + (dolist (name '(user-name description version guid sql-name)) (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"