Commit 8a5a5784 authored by ryszard.szopa's avatar ryszard.szopa
Browse files

Bugfixes and documentation: with-class-connection, set-fields.

darcs-hash:7438dca65ddfaedcf8f75372b9ef70251066b8fa
parent a234d722
......@@ -30,7 +30,7 @@
(save-dao s-value))))))
(defgeneric dao-exists-p (dao)
(:documentation "Return a boolean indicating whether the given dao
(:documentation "Return a boolean indicating whether the given DAO
exists in the database.")
(:method ((dao dao))
(with-class-connection (dao)
......@@ -40,7 +40,7 @@ exists in the database.")
(defun set-fields (object)
(iter (for field in (slots-of object))
(appending `(',field ,(slot-value-or-id-if-foreign object field)))))
(appending `(,field ,(slot-value-or-id-if-foreign object field)))))
(defun id-seq-name (class)
(intern (format nil "~A-ID-SEQ" (class-name class)) :keyword))
......
......@@ -59,5 +59,7 @@ ignored in all database related operations.")))
;; case.
(declare (ignore rest))
(finalize-inheritance class)
;; DAO is just a class to inherit from, and a table for it shouldn't
;; be created
(unless (eq (class-name class) 'dao)
(create-table class)))
......@@ -43,10 +43,13 @@
(lambda () (progn ,@body))))
(defun with-class-connection-fun (object what-to-do)
(with-connection-fun (car (db-class-connection-spec object))
(funcall what-to-do)))
"Functional interface to the macro WITH-CLASS-CONNECTION."
(with-connection-fun (db-class-connection-spec (class-of object))
what-to-do))
(defmacro with-class-connection ((object) &body body)
"Run BODY in an environment with a connection to the database specified by the DB-CLASS-CONNECTION-SPEC of CLASS."
`(with-class-connection-fun (car (db-class-connection-spec (class-of ,object)))
"Run BODY in an environment with a connection to the database
specified by the DB-CLASS-CONNECTION-SPEC of the class of OBJECT."
`(with-class-connection-fun ,object
(lambda () (progn ,@body))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment