X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Fmetaclasses.lisp;h=1ae635a9eb9ea3679192c83ed51cddebc07b0999;hb=bad0cc74f5574b40b8f1f7338dee3cd7bdf56228;hp=2a0b4b9b2c835c30f194c46674b4c2fe795e65b0;hpb=86e9b31ba3b0348f2cc5c816e80d9109e555be94;p=clsql.git diff --git a/sql/metaclasses.lisp b/sql/metaclasses.lisp index 2a0b4b9..1ae635a 100644 --- a/sql/metaclasses.lisp +++ b/sql/metaclasses.lisp @@ -1,8 +1,6 @@ ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*- ;;;; ************************************************************************* ;;;; -;;;; $Id$ -;;;; ;;;; CLSQL metaclass for standard-db-objects created in the OODDL. ;;;; ;;;; This file is part of CLSQL. @@ -48,6 +46,9 @@ (key-slots :accessor key-slots :initform nil) + (normalizedp + :accessor normalizedp + :initform nil) (class-qualifier :accessor view-class-qualifier :initarg :qualifier @@ -111,10 +112,21 @@ base-table)) (class-name class))))) +(defgeneric ordered-class-direct-slots (class)) +(defmethod ordered-class-direct-slots ((self standard-db-class)) + (let ((direct-slot-names + (mapcar #'slot-definition-name (class-direct-slots self))) + (ordered-direct-class-slots '())) + (dolist (slot (ordered-class-slots self)) + (let ((slot-name (slot-definition-name slot))) + (when (find slot-name direct-slot-names) + (push slot ordered-direct-class-slots)))) + (nreverse ordered-direct-class-slots))) + (defmethod initialize-instance :around ((class standard-db-class) &rest all-keys &key direct-superclasses base-table - qualifier + qualifier normalizedp &allow-other-keys) (let ((root-class (find-class 'standard-db-object nil)) (vmc 'standard-db-class)) @@ -131,17 +143,19 @@ (remove-keyword-arg all-keys :direct-superclasses))) (call-next-method)) (set-view-table-slot class base-table) + (setf (normalizedp class) (car normalizedp)) (register-metaclass class (nth (1+ (position :direct-slots all-keys)) all-keys)))) (defmethod reinitialize-instance :around ((class standard-db-class) &rest all-keys - &key base-table + &key base-table normalizedp direct-superclasses qualifier &allow-other-keys) (let ((root-class (find-class 'standard-db-object nil)) (vmc 'standard-db-class)) (set-view-table-slot class base-table) + (setf (normalizedp class) (car normalizedp)) (setf (view-class-qualifier class) (car qualifier)) (if (and root-class (not (equal class root-class))) @@ -196,14 +210,18 @@ (setf (key-slots class) (remove-if-not (lambda (slot) (eql (slot-value slot 'db-kind) :key)) - (ordered-class-slots class))))) + (if (normalizedp class) + (ordered-class-direct-slots class) + (ordered-class-slots class)))))) #+(or sbcl allegro) (defmethod finalize-inheritance :after ((class standard-db-class)) (setf (key-slots class) (remove-if-not (lambda (slot) (eql (slot-value slot 'db-kind) :key)) - (ordered-class-slots class)))) + (if (normalizedp class) + (ordered-class-direct-slots class) + (ordered-class-slots class))))) ;; return the deepest view-class ancestor for a given view class @@ -296,7 +314,13 @@ column definition in the database.") :accessor specified-type :initarg specified-type :initform nil - :documentation "Internal slot storing the :type specified by user."))) + :documentation "Internal slot storing the :type specified by user.") + (autoincrement-sequence + :accessor view-class-slot-autoincrement-sequence + :initarg :autoincrement-sequence + :initform nil + :documentation "A string naming the (possibly automatically generated) sequence +for a slot with an :auto-increment constraint."))) (defparameter *db-info-lambda-list* '(&key join-class @@ -407,7 +431,7 @@ implementations." specified-type)))) (if (and type (not (member :not-null (listify db-constraints)))) `(or null ,type) - type))) + (or type t)))) ;; Compute the slot definition for slots in a view-class. Figures out ;; what kind of database value (if any) is stored there, generates and @@ -427,29 +451,19 @@ implementations." (car list) list)) -(defmethod initialize-instance :around ((obj view-class-direct-slot-definition) - &rest initargs) - (do* ((parsed (list obj)) - (name (first initargs) (first initargs)) - (val (second initargs) (second initargs)) - (type nil) - (db-constraints nil)) - ((null initargs) - (setq parsed - (append parsed - (list 'specified-type type - :type (compute-lisp-type-from-specified-type - type db-constraints)))) - (apply #'call-next-method parsed)) - (case name - (:db-constraints - (setq db-constraints val) - (setq parsed (append parsed (list name val)))) - (:type - (setq type val)) - (t - (setq parsed (append parsed (list name val))))) - (setq initargs (cddr initargs)))) +(defmethod initialize-instance :around + ((obj view-class-direct-slot-definition) + &rest initargs &key db-constraints db-kind type &allow-other-keys) + (when (and (not db-kind) (member :primary-key (listify db-constraints))) + (warn "Slot ~S constrained to be :primary-key, but not marked as :db-kind :key" + (slot-definition-name obj))) + (apply #'call-next-method obj + 'specified-type type + :type (if (and (eql db-kind :virtual) (null type)) + t + (compute-lisp-type-from-specified-type + type db-constraints)) + initargs)) (defmethod compute-effective-slot-definition ((class standard-db-class) #+kmr-normal-cesd slot-name