From 58e8d9a8168e0dc90baebd1f0a634706bce580a1 Mon Sep 17 00:00:00 2001 From: Daniel Nussenbaum Date: Thu, 31 Oct 2024 20:14:10 +0200 Subject: [PATCH] Implementation of effective standard slots for the mito metaclass --- src/core/class/column.lisp | 21 ++++++++++++++++++++- src/core/class/table.lisp | 25 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/core/class/column.lisp b/src/core/class/column.lisp index 1c6f7e8..a7c0d5f 100644 --- a/src/core/class/column.lisp +++ b/src/core/class/column.lisp @@ -7,7 +7,9 @@ #:delete-from-plist #:ensure-car) (:export #:table-column-class + #:column-standard-effective-slot-definitions #:table-column-type + #:%table-column-type #:table-column-not-null-p #:table-column-name #:primary-key-p @@ -29,7 +31,17 @@ (otherwise (values col-type t)))) -(defclass table-column-class (c2mop:standard-direct-slot-definition) + +(defgeneric %table-column-type (obj)) +(defmethod %table-column-type (ob) nil) +(defgeneric table-column-references (obj)) +(defmethod table-column-references (ob) nil) +(defgeneric primary-key-p (obj)) +(defmethod primary-key-p (ob) nil) +(defgeneric ghost-slot-p (obj)) +(defmethod ghost-slot-p (ob) nil) + +(defclass column-slot-definitions () ((col-type :type (or symbol cons null) :initarg :col-type :accessor %table-column-type) @@ -47,6 +59,13 @@ :accessor ghost-slot-p :documentation "Option to specify slots as ghost slots. Ghost slots do not depend on a database."))) +(defclass table-column-class (column-slot-definitions c2mop:standard-direct-slot-definition) + ()) + +(defclass column-standard-effective-slot-definitions (column-slot-definitions + c2mop:standard-effective-slot-definition) + ()) + (defgeneric table-column-type (column) (:method ((column table-column-class)) (values diff --git a/src/core/class/table.lisp b/src/core/class/table.lisp index 553a51e..e810b03 100644 --- a/src/core/class/table.lisp +++ b/src/core/class/table.lisp @@ -5,7 +5,10 @@ (:import-from #:mito.class.column #:parse-col-type #:table-column-class + #:table-column-references + #:column-standard-effective-slot-definitions #:table-column-type + #:%table-column-type #:table-column-name #:primary-key-p #:ghost-slot-p) @@ -140,9 +143,31 @@ (defmethod c2mop:direct-slot-definition-class ((class table-class) &key &allow-other-keys) 'table-column-class) +(defmethod c2mop:effective-slot-definition-class ((class table-class) &rest initargs) + (declare (ignorable initargs)) + (find-class 'column-standard-effective-slot-definitions)) + (defmethod c2mop:validate-superclass ((class table-class) (super standard-class)) t) +(defmethod c2mop:compute-effective-slot-definition + :around ((class table-class) name direct-slot-definitions) + (declare (ignorable name)) + (let ((result (call-next-method))) + (when result + ;; set here all the relevant slots. See column-standard-effective-slot-definitions + (setf (ghost-slot-p result) + (some #'ghost-slot-p direct-slot-definitions)) + (setf (%table-column-type result) + (some #'%table-column-type direct-slot-definitions)) + ;; table-column-references is a reader, not an accessor. Unclear if this should be set. + ;; (setf (table-column-references result) + ;; (some #'table-column-references direct-slot-definitions)) + (setf (primary-key-p result) + (some #'primary-key-p direct-slot-definitions)) + (setf ) + result))) + (defgeneric table-name (class) (:method ((class table-class)) (if (slot-value class 'table-name)