Signed-off-by: Kevin Rosenberg <kevin@rosenberg.net>
+28 Jan 2009 Kevin Rosenberg <kevin@rosenberg.net>
+ * Change "normalise" from British spelling for consistency with
+ other American spellings in CLSQL.
+
28 Jan 2009 Kevin Rosenberg <kevin@rosenberg.net>
* db-mysql/Makefile: Add directory for Fedora 11/12 on 64-bit
platform (Thanks to Michael Pheasant) and remove a 32-bit directory
28 Jan 2009 Kevin Rosenberg <kevin@rosenberg.net>
* db-mysql/Makefile: Add directory for Fedora 11/12 on 64-bit
platform (Thanks to Michael Pheasant) and remove a 32-bit directory
- Another class option is <symbol>:normalisedp</symbol>, which signals
- &clsql; to use a normalised schema for the mapping from slots to
+ Another class option is <symbol>:normalizedp</symbol>, which signals
+ &clsql; to use a normalized schema for the mapping from slots to
&sql; columns. By default &clsql; includes all the slots of a parent
class that map to &sql; columns into the child class. This option
&sql; columns. By default &clsql; includes all the slots of a parent
class that map to &sql; columns into the child class. This option
- tells &clsql; to normalise the schema, so that a join is done on the
+ tells &clsql; to normalize the schema, so that a join is done on the
primary keys of the concerned tables to get a complete column set
for the classes. For more information, see <link linkend="def-view-class">
<function>def-view-class</function></link>.
primary keys of the concerned tables to get a complete column set
for the classes. For more information, see <link linkend="def-view-class">
<function>def-view-class</function></link>.
provides a mapping from &sql; tables to CLOS objects. By default class
inheritance is handled by including all the columns from parent
classes into the child class. This means your database schema becomes
provides a mapping from &sql; tables to CLOS objects. By default class
inheritance is handled by including all the columns from parent
classes into the child class. This means your database schema becomes
-very much denormalised. The class option <symbol>:normalisedp</symbol>
+very much denormalized. The class option <symbol>:normalizedp</symbol>
can be used to disable the default behaviour and have &clsql;
can be used to disable the default behaviour and have &clsql;
-normalise the database schemas of inherited classes.
+normalize the database schemas of inherited classes.
</listitem>
<listitem>
<para>
</listitem>
<listitem>
<para>
- <parameter>:normalisedp</parameter> - specifies whether
- this class uses normalised inheritance from parent classes.
- Defaults to nil, i.e. non-normalised schemas. When true,
+ <parameter>:normalizedp</parameter> - specifies whether
+ this class uses normalized inheritance from parent classes.
+ Defaults to nil, i.e. non-normalized schemas. When true,
SQL database tables that map to this class and parent
classes are joined on their primary keys to get the full
set of database columns for this class.
SQL database tables that map to this class and parent
classes are joined on their primary keys to get the full
set of database columns for this class.
- <title>Normalised inheritance schemas</title>
+ <title>Normalized inheritance schemas</title>
- Specifying that <symbol>:normalisedp</symbol> is <symbol>T</symbol>
- tells &clsql; to normalise the database schema for inheritance.
+ Specifying that <symbol>:normalizedp</symbol> is <symbol>T</symbol>
+ tells &clsql; to normalize the database schema for inheritance.
What this means is shown in the examples below.
</para>
<para>
What this means is shown in the examples below.
</para>
<para>
- With <symbol>:normalisedp</symbol> equal to <symbol>NIL</symbol>
+ With <symbol>:normalizedp</symbol> equal to <symbol>NIL</symbol>
(the default) the class inheritance would result in the following:
</para>
<screen>
(the default) the class inheritance would result in the following:
</para>
<screen>
- Using <symbol>:normalisedp</symbol> <symbol>T</symbol>, both
+ Using <symbol>:normalizedp</symbol> <symbol>T</symbol>, both
view-classes need a primary key to join them on:
</para>
<screen>
view-classes need a primary key to join them on:
</para>
<screen>
((user-id :accessor user-id :initarg :user-id
:type integer :db-kind :key :db-constraints (:not-null))
(nick :accessor nick :initarg :nick :type (varchar 64)))
((user-id :accessor user-id :initarg :user-id
:type integer :db-kind :key :db-constraints (:not-null))
(nick :accessor nick :initarg :nick :type (varchar 64)))
SQL table USER:
+---------+-------------+------+-----+---------+-------+
SQL table USER:
+---------+-------------+------+-----+---------+-------+
<para>
In this second case, all slots of the view-class 'node
are also available in view-class 'user, and can be used
<para>
In this second case, all slots of the view-class 'node
are also available in view-class 'user, and can be used
- as one would expect. For example, with the above normalised
+ as one would expect. For example, with the above normalized
view-classes 'node and 'user, and SQL tracing turned on:
</para>
<screen>
view-classes 'node and 'user, and SQL tracing turned on:
</para>
<screen>
(key-slots
:accessor key-slots
:initform nil)
(key-slots
:accessor key-slots
:initform nil)
- (normalisedp
- :accessor normalisedp
+ (normalizedp
+ :accessor normalizedp
:initform nil)
(class-qualifier
:accessor view-class-qualifier
:initform nil)
(class-qualifier
:accessor view-class-qualifier
(defmethod initialize-instance :around ((class standard-db-class)
&rest all-keys
&key direct-superclasses base-table
(defmethod initialize-instance :around ((class standard-db-class)
&rest all-keys
&key direct-superclasses base-table
&allow-other-keys)
(let ((root-class (find-class 'standard-db-object nil))
(vmc 'standard-db-class))
&allow-other-keys)
(let ((root-class (find-class 'standard-db-object nil))
(vmc 'standard-db-class))
(remove-keyword-arg all-keys :direct-superclasses)))
(call-next-method))
(set-view-table-slot class base-table)
(remove-keyword-arg all-keys :direct-superclasses)))
(call-next-method))
(set-view-table-slot class base-table)
- (setf (normalisedp class) (car normalisedp))
+ (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
(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 normalisedp
+ &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)
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 (normalisedp class) (car normalisedp))
+ (setf (normalizedp class) (car normalizedp))
(setf (view-class-qualifier class)
(car qualifier))
(if (and root-class (not (equal class root-class)))
(setf (view-class-qualifier class)
(car qualifier))
(if (and root-class (not (equal class root-class)))
(setf (key-slots class) (remove-if-not (lambda (slot)
(eql (slot-value slot 'db-kind)
:key))
(setf (key-slots class) (remove-if-not (lambda (slot)
(eql (slot-value slot 'db-kind)
:key))
- (if (normalisedp class)
+ (if (normalizedp class)
(ordered-class-direct-slots class)
(ordered-class-slots class))))))
(ordered-class-direct-slots class)
(ordered-class-slots class))))))
(setf (key-slots class) (remove-if-not (lambda (slot)
(eql (slot-value slot 'db-kind)
:key))
(setf (key-slots class) (remove-if-not (lambda (slot)
(eql (slot-value slot 'db-kind)
:key))
- (if (normalisedp class)
+ (if (normalizedp class)
(ordered-class-direct-slots class)
(ordered-class-slots class)))))
(ordered-class-direct-slots class)
(ordered-class-slots class)))))
(setf (slot-value instance slot-name)
(fault-join-slot class instance slot-object))
(setf (slot-value instance slot-name) nil)))
(setf (slot-value instance slot-name)
(fault-join-slot class instance slot-object))
(setf (slot-value instance slot-name) nil)))
- (when (and (normalisedp class)
+ (when (and (normalizedp class)
(not (member slot-name
(mapcar #'(lambda (esd) (slot-definition-name esd))
(ordered-class-direct-slots class))))
(not (member slot-name
(mapcar #'(lambda (esd) (slot-definition-name esd))
(ordered-class-direct-slots class))))
(let ((*db-deserializing* t))
(if (view-database instance)
(setf (slot-value instance slot-name)
(let ((*db-deserializing* t))
(if (view-database instance)
(setf (slot-value instance slot-name)
- (fault-join-normalised-slot class instance slot-object))
+ (fault-join-normalized-slot class instance slot-object))
(setf (slot-value instance slot-name) nil)))))))
(call-next-method))
(setf (slot-value instance slot-name) nil)))))))
(call-next-method))
(if tclass
(let ((*default-database* database)
(pclass (car (class-direct-superclasses tclass))))
(if tclass
(let ((*default-database* database)
(pclass (car (class-direct-superclasses tclass))))
- (when (and (normalisedp tclass) (not (table-exists-p (view-table pclass))))
+ (when (and (normalizedp tclass) (not (table-exists-p (view-table pclass))))
(create-view-from-class (class-name pclass)
:database database :transactions transactions))
(%install-class tclass database :transactions transactions))
(create-view-from-class (class-name pclass)
:database database :transactions transactions))
(%install-class tclass database :transactions transactions))
(defmethod %install-class ((self standard-db-class) database
&key (transactions t))
(let ((schemadef '())
(defmethod %install-class ((self standard-db-class) database
&key (transactions t))
(let ((schemadef '())
- (ordered-slots (if (normalisedp self)
+ (ordered-slots (if (normalizedp self)
(ordered-class-direct-slots self)
(ordered-class-slots self))))
(dolist (slotdef ordered-slots)
(ordered-class-direct-slots self)
(ordered-class-slots self))))
(dolist (slotdef ordered-slots)
(when res
(push res schemadef))))
(if (not schemadef)
(when res
(push res schemadef))))
(if (not schemadef)
- (unless (normalisedp self)
+ (unless (normalizedp self)
(error "Class ~s has no :base slots" self))
(progn
(create-table (sql-expression :table (view-table self)) (nreverse schemadef)
(error "Class ~s has no :base slots" self))
(progn
(create-table (sql-expression :table (view-table self)) (nreverse schemadef)
(defun generate-selection-list (vclass)
(let* ((sels nil)
(this-class vclass)
(defun generate-selection-list (vclass)
(let* ((sels nil)
(this-class vclass)
- (slots (if (normalisedp vclass)
+ (slots (if (normalizedp vclass)
(labels ((getdslots ()
(let ((sl (ordered-class-direct-slots this-class)))
(cond (sl)
(labels ((getdslots ()
(let ((sl (ordered-class-direct-slots this-class)))
(cond (sl)
(database *default-database*))
(let* ((database (or (view-database obj) database))
(view-class (class-of obj)))
(database *default-database*))
(let* ((database (or (view-database obj) database))
(view-class (class-of obj)))
- (when (normalisedp view-class)
- ;; If it's normalised, find the class that actually contains
+ (when (normalizedp view-class)
+ ;; If it's normalized, find the class that actually contains
;; the slot that's tied to the db
(setf view-class
(do ((this-class view-class
;; the slot that's tied to the db
(setf view-class
(do ((this-class view-class
(pk-slot (car (keyslots-for-class view-class)))
(view-class-table (view-table view-class))
(pclass (car (class-direct-superclasses view-class))))
(pk-slot (car (keyslots-for-class view-class)))
(view-class-table (view-table view-class))
(pclass (car (class-direct-superclasses view-class))))
- (when (normalisedp view-class)
+ (when (normalizedp view-class)
(setf pk (update-records-from-instance obj :database database
:this-class pclass))
(when pk-slot
(setf (slot-value obj (slot-definition-name pk-slot)) pk)))
(let* ((slots (remove-if-not #'slot-storedp
(setf pk (update-records-from-instance obj :database database
:this-class pclass))
(when pk-slot
(setf (slot-value obj (slot-definition-name pk-slot)) pk)))
(let* ((slots (remove-if-not #'slot-storedp
- (if (normalisedp view-class)
+ (if (normalizedp view-class)
(ordered-class-direct-slots view-class)
(ordered-class-slots view-class))))
(record-values (mapcar #'slot-value-list slots)))
(ordered-class-direct-slots view-class)
(ordered-class-slots view-class))))
(record-values (mapcar #'slot-value-list slots)))
- (cond ((and (not (normalisedp view-class))
+ (cond ((and (not (normalizedp view-class))
(not record-values))
(error "No settable slots."))
(not record-values))
(error "No settable slots."))
- ((and (normalisedp view-class)
+ ((and (normalizedp view-class)
(not record-values))
nil)
((view-database obj)
(not record-values))
nil)
((view-database obj)
(let* ((view-class (or this-class (class-of instance)))
(pclass (car (class-direct-superclasses view-class)))
(pres nil))
(let* ((view-class (or this-class (class-of instance)))
(pclass (car (class-direct-superclasses view-class)))
(pres nil))
- (when (normalisedp view-class)
+ (when (normalizedp view-class)
(setf pres (update-instance-from-records instance :database database
:this-class pclass)))
(let* ((view-table (sql-expression :table (view-table view-class)))
(setf pres (update-instance-from-records instance :database database
:this-class pclass)))
(let* ((view-table (sql-expression :table (view-table view-class)))
slot &key (database *default-database*))
(let* ((view-class (find-class (class-name (class-of instance))))
(slot-def (slotdef-for-slot-with-class slot view-class)))
slot &key (database *default-database*))
(let* ((view-class (find-class (class-name (class-of instance))))
(slot-def (slotdef-for-slot-with-class slot view-class)))
- (when (normalisedp view-class)
- ;; If it's normalised, find the class that actually contains
+ (when (normalizedp view-class)
+ ;; If it's normalized, find the class that actually contains
;; the slot that's tied to the db
(setf view-class
(do ((this-class view-class
;; the slot that's tied to the db
(setf view-class
(do ((this-class view-class
;;;; Should we not return the whole result, instead of only
;;;; the one slot-value? We get all the values from the db
;;;; anyway, so?
;;;; Should we not return the whole result, instead of only
;;;; the one slot-value? We get all the values from the db
;;;; anyway, so?
-(defun fault-join-normalised-slot (class object slot-def)
+(defun fault-join-normalized-slot (class object slot-def)
(labels ((getsc (this-class)
(let ((sc (car (class-direct-superclasses this-class))))
(if (key-slots sc)
(labels ((getsc (this-class)
(let ((sc (car (class-direct-superclasses this-class))))
(if (key-slots sc)
(slot-value object hk))
(t hk)))))
(slot-value object hk))
(t hk)))))
- ;; Caching nil in next select, because in normalised mode
+ ;; Caching nil in next select, because in normalized mode
;; records can be changed through other instances (children,
;; parents) so changes possibly won't be noticed
(let ((res (car (select (class-name sc) :where jq
;; records can be changed through other instances (children,
;; parents) so changes possibly won't be noticed
(let ((res (car (select (class-name sc) :where jq
:database (view-database object))))
(slot-name (slot-definition-name slot-def)))
:database (view-database object))))
(slot-name (slot-definition-name slot-def)))
- ;; If current class is normalised and wanted slot is not
+ ;; If current class is normalized and wanted slot is not
;; a direct member, recurse up
;; a direct member, recurse up
- (if (and (normalisedp class)
+ (if (and (normalizedp class)
(not (member slot-name
(mapcar #'(lambda (esd) (slot-definition-name esd))
(ordered-class-direct-slots class))))
(not (slot-boundp res slot-name)))
(not (member slot-name
(mapcar #'(lambda (esd) (slot-definition-name esd))
(ordered-class-direct-slots class))))
(not (slot-boundp res slot-name)))
- (fault-join-normalised-slot sc res slot-def)
+ (fault-join-normalized-slot sc res slot-def)
(slot-value res slot-name)))))) )
(defun join-qualifier (class object slot-def)
(slot-value res slot-name)))))) )
(defun join-qualifier (class object slot-def)
;; find all immediate-select slots and join-vals for this object
(let* ((jo-class (class-of jo))
(slots
;; find all immediate-select slots and join-vals for this object
(let* ((jo-class (class-of jo))
(slots
- (if (normalisedp jo-class)
+ (if (normalizedp jo-class)
(class-direct-slots jo-class)
(class-slots jo-class)))
(pos-list (remove-if #'null
(class-direct-slots jo-class)
(class-slots jo-class)))
(pos-list (remove-if #'null
-;; classes for testing the normalisedp stuff
+;; classes for testing the normalizedp stuff
(def-view-class node ()
((node-id :accessor node-id :initarg :node-id
:type integer :db-kind :key
(def-view-class node ()
((node-id :accessor node-id :initarg :node-id
:type integer :db-kind :key
((setting-id :accessor setting-id :initarg :setting-id
:type integer :db-kind :key :db-constraints (:not-null))
(vars :accessor vars :initarg :vars :type (varchar 240)))
((setting-id :accessor setting-id :initarg :setting-id
:type integer :db-kind :key :db-constraints (:not-null))
(vars :accessor vars :initarg :vars :type (varchar 240)))
(def-view-class user (node)
((user-id :accessor user-id :initarg :user-id
:type integer :db-kind :key :db-constraints (:not-null))
(nick :accessor nick :initarg :nick :type (varchar 64)))
(def-view-class user (node)
((user-id :accessor user-id :initarg :user-id
:type integer :db-kind :key :db-constraints (:not-null))
(nick :accessor nick :initarg :nick :type (varchar 64)))
(def-view-class theme (setting)
((theme-id :accessor theme-id :initarg :theme-id
:type integer :db-kind :key :db-constraints (:not-null))
(doc :accessor doc :initarg :doc :type (varchar 240)))
(def-view-class theme (setting)
((theme-id :accessor theme-id :initarg :theme-id
:type integer :db-kind :key :db-constraints (:not-null))
(doc :accessor doc :initarg :doc :type (varchar 240)))
;; A class that uses only a superclass db table
(def-view-class location (node)
()
(:base-table node)
;; A class that uses only a superclass db table
(def-view-class location (node)
()
(:base-table node)
(def-view-class subloc (location)
((subloc-id :accessor subloc-id :initarg :subloc-id
:type integer :db-kind :key :db-constraints (:not-null))
(loc :accessor loc :initarg :loc :type (varchar 64)))
(def-view-class subloc (location)
((subloc-id :accessor subloc-id :initarg :subloc-id
:type integer :db-kind :key :db-constraints (:not-null))
(loc :accessor loc :initarg :loc :type (varchar 64)))
(clsql-sys::class-slots (find-class 'company))))
t t t t t t)
(clsql-sys::class-slots (find-class 'company))))
t t t t t t)
-;; Ensure classes are correctly marked normalised or not, default not
+;; Ensure classes are correctly marked normalized or not, default not
;(deftest :ooddl/metaclass/3
; (values
;(deftest :ooddl/metaclass/3
; (values
-; (clsql-sys::normalisedp derivednode1)
-; (clsql-sys::normalisedp basenode)
-; (clsql-sys::normalisedp company1)
-; (clsql-sys::normalisedp employee3)
-; (clsql-sys::normalisedp derivednode-sc-2))
+; (clsql-sys::normalizedp derivednode1)
+; (clsql-sys::normalizedp basenode)
+; (clsql-sys::normalizedp company1)
+; (clsql-sys::normalizedp employee3)
+; (clsql-sys::normalizedp derivednode-sc-2))
; t nil nil nil t)
;(deftest :ooddl/metaclass/3
; (values
; t nil nil nil t)
;(deftest :ooddl/metaclass/3
; (values
-; (normalisedp (find-class 'baseclass))
-; (normalisedp (find-class 'normderivedclass)))
+; (normalizedp (find-class 'baseclass))
+; (normalizedp (find-class 'normderivedclass)))
; nil t)
(deftest :ooddl/join/1
; nil t)
(deftest :ooddl/join/1
(slot-value employee1 'email))))
"lenin@soviet.org" "lenin-nospam@soviet.org")
(slot-value employee1 'email))))
"lenin@soviet.org" "lenin-nospam@soviet.org")
-;; tests normalisedp update-instance-from-records
+;; tests normalizedp update-instance-from-records
(deftest :oodml/update-instance/3
(with-dataset *ds-nodes*
(values
(deftest :oodml/update-instance/3
(with-dataset *ds-nodes*
(values
"11 subloc-2 second subloc"
"11 Altered title Altered loc")
"11 subloc-2 second subloc"
"11 Altered title Altered loc")
-;; tests update-slot-from-record with normalisedp stuff
+;; tests update-slot-from-record with normalizedp stuff
(deftest :oodml/update-instance/6
(with-dataset *ds-nodes*
(values
(deftest :oodml/update-instance/6
(with-dataset *ds-nodes*
(values