added licensing info
[clinton/lisp-on-lines.git] / src / meta-model.lisp
index 9ea1d3c..58b3fd4 100644 (file)
@@ -16,7 +16,8 @@
     :initform nil)
    (base-type
     :accessor meta-model.base-type
-    :initform 'clsql)))
+    :initarg :base-type
+    :initform :clsql)))
 
 (defmethod meta-model.metadata ((self (eql nil)))
   nil)
@@ -33,7 +34,7 @@
 (defmethod %def-meta-model ((base-type t) name supers slots &rest options)
   `(defclass ,name ,(gen-supers supers)
      ()
-     (:default-initargs :metadata ',slots)))
+     (:default-initargs :metadata ',slots :base-type ,base-type)))
   
   
 (defmacro def-meta-model (name supers slots &rest options)
      (let ((class ,(%def-meta-model (cadr (or (assoc :base-type options) '(t t))) name supers slots options)))
        class)))
 
-(defgeneric def-base-class-expander (model base-type name args))
+(defgeneric def-base-type-class-expander (base-type model name args))
 
+(defmethod def-base-class-expander ((model t) name args)
+  (def-base-type-class-expander (meta-model.base-type model) model name args))
 
 (defmacro def-base-class (name (model) &rest args)
   (let ((i (make-instance model)))
-    `(prog
-       ,(def-base-class-expander i :clsql name args)
+    `(prog1
+         (eval ,(def-base-class-expander i name args))
        (defmethod meta-model.metadata ((m ,name))
         ',(meta-model.metadata i)))))
   
     (when (equal (getf (cdr s) :home-key) slot)
       (let ((val (slot-value model (car s))))
       (return-from explode-foreign-key 
-       (values (if val val (make-instance (getf (cdr s) :join-class))) (getf (cdr s) :foreign-key)))))))
+       (values (if val val (make-instance (getf (cdr s) :join-class))) 
+               (getf (cdr s) :foreign-key)))))))
 
 (defun find-join-helper (foreign-key)
   (lambda (class slot) 
   "returns the SLOT in the foreign VIEW-CLASS that joins with FOREIGN-KEY"
   (car (list-relations-helper view (find-join-helper foreign-key) :return-key :foreign-key)))
 
+(defmethod explode-has-many ((view t) join-slot)
+  "returns the class of the join as the primary value, the second and third value is the home key and the foreign key"
+  (let ((att (assoc join-slot (list-join-attributes view))))
+    (values (getf (cdr att) :join-class) 
+           (getf (cdr att) :home-key) 
+           (getf (cdr att) :foreign-key))))
+  
+(defgeneric expr-= (instance slot-name value)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-> (instance slot-name value)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-< (instance slot-name value)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-ends-with (instance slot-name value)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-starts-with (instance slot-name value)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-contains (instance slot-name value)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-and (instance &rest args)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-or (instance &rest args)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric expr-not (instance &rest args)
+  (:documentation "Create search expression for appropriate backend."))
+
+(defgeneric select-instances (instance &rest args)
+  (:documentation "Select instances in backend dependent way"))
 
+(defmacro def-compare-expr (instance-type name expr &key value-format)
+  `(defmethod ,name ((instance ,instance-type) slot-name value)
+     (declare (ignore instance))
+     (,expr slot-name ,(typecase value-format
+                                 (null 'value)
+                                 (string `(format nil ,value-format value))
+                                 (t `(,value-format value))))))
 
+(defmacro def-logical-expr (instance-type name expr)
+  `(defmethod ,name ((instance ,instance-type) &rest args)
+     (declare (ignore instance))
+     (apply ,expr args)))
\ No newline at end of file