NextPrevUpTopContentsIndex

18.4.2.1 Example View Class definition

The following example shows a View Class corresponding to the traditional employees table, with the employee's department given by a join with the departments table. See def-view-class in the LispWorks Reference Manual for a description of the slot options.

(def-view-class employee (standard-db-object)
   ((employee-number :db-kind :key 
                     :column empno 
                     :type integer)
    (employee-name :db-kind :base 
                   :column ename 
                   :type (string 20)
                   :accessor employee-name)
    (employee-department :db-kind :base 
                         :column deptno 
                         :type integer
                         :accessor employee-department)
    (employee-job :db-kind :base 
                  :column job 
                  :type (string 9))
    (employee-manager :db-kind :base 
                      :column mgr 
                      :type integer)
    (employee-location :db-kind :join
                       :db-info (:join-class department
                                 :retrieval :deferred
                                 :set nil
                                 :home-key employee-department
                                 :foreign-key department-number
                                 :target-slot department-loc)
                       :accessor employee-location))
                (:base-table emp))

The def-view-class macro allows elements or lists of elements to follow :home-key and :foreign-key . The elements can be symbols, nil , strings, integers or floats.

This syntax means that an object from the join class is only included in the join slot if the values from the home-key are equal to the values in the foreign-key, in order. These values are calculated as follows:

Note that some vendors may have short maximum identifier lengths. The CLOS interface uses constructed alias names for tables in its SQL queries, and long table names or long class names may cause the constructed aliases to exceed the maximum identifier length for a particular vendor.


LispWorks User Guide - 8 Apr 2005

NextPrevUpTopContentsIndex