f4b28483051979d289987550b5452b4b36443c2d
[clsql.git] / sql / generics.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:     generics.lisp
6 ;;;; Purpose:  Generic function definitions for DB interfaces
7 ;;;; Author:   Kevin M. Rosenberg based on
8 ;;;; Created:  Apr 2004
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package #:clsql-sys)
20
21 (defgeneric update-record-from-slot (object slot &key database)
22   (:documentation
23    "Updates the value stored in the column represented by the
24 slot, specified by the CLOS slot name SLOT, of View Class
25 instance OBJECT. DATABASE defaults to *DEFAULT-DATABASE* and
26 specifies the database in which the update is made only if OBJECT
27 is not associated with a database. In this case, a record is
28 created in DATABASE and the attribute represented by SLOT is
29 initialised from the value of the supplied slots with other
30 attributes having default values. Furthermore, OBJECT becomes
31 associated with DATABASE."))
32
33 (defgeneric update-record-from-slots (object slots &key database)
34   (:documentation 
35    "Updates the values stored in the columns represented by the
36 slots, specified by the CLOS slot names SLOTS, of View Class
37 instance OBJECT. DATABASE defaults to *DEFAULT-DATABASE* and
38 specifies the database in which the update is made only if OBJECT
39 is not associated with a database. In this case, a record is
40 created in the appropriate table of DATABASE and the attributes
41 represented by SLOTS are initialised from the values of the
42 supplied slots with other attributes having default
43 values. Furthermore, OBJECT becomes associated with DATABASE."))
44
45 (defgeneric update-records-from-instance (object &key database)
46   (:documentation
47    "Using an instance of a View Class, OBJECT, update the table
48 that stores its instance data. DATABASE defaults to
49 *DEFAULT-DATABASE* and specifies the database in which the update
50 is made only if OBJECT is not associated with a database. In this
51 case, a record is created in the appropriate table of DATABASE
52 using values from the slot values of OBJECT, and OBJECT becomes
53 associated with DATABASE."))
54
55 (defgeneric delete-instance-records (object)
56   (:documentation
57    "Deletes the records represented by OBJECT in the appropriate
58 table of the database associated with OBJECT. If OBJECT is not
59 yet associated with a database, an error is signalled."))
60
61 (defgeneric update-instance-from-records (object &key database)
62   (:documentation
63    "Updates the slot values of the View Class instance OBJECT
64 using the attribute values of the appropriate table of DATABASE
65 which defaults to the database associated with OBJECT or, if
66 OBJECT is not associated with a database, *DEFAULT-DATABASE*.
67 Join slots are updated but instances of the class on which the
68 join is made are not updated."))
69
70 (defgeneric update-slot-from-record (object slot &key database)
71   (:documentation
72    "Updates the slot value, specified by the CLOS slot name SLOT,
73 of the View Class instance OBJECT using the attribute values of
74 the appropriate table of DATABASE which defaults to the database
75 associated with OBJECT or, if OBJECT is not associated with a
76 database, *DEFAULT-DATABASE*.  Join slots are updated but
77 instances of the class on which the join is made are not
78 updated."))
79
80 (defgeneric instance-refreshed (object) 
81   (:documentation 
82    "Provides a hook which is called within an object oriented
83 call to SELECT with a non-nil value of REFRESH when the View
84 Class instance OBJECT has been updated from the database. A
85 method specialised on STANDARD-DB-OBJECT is provided which has no
86 effects. Methods specialised on particular View Classes can be
87 used to specify any operations that need to be made on View
88 Classes instances which have been updated in calls to SELECT."))
89
90 (defgeneric update-slot-with-null (instance slotname slotdef)
91   (:documentation "Called to update a slot when its column has a NULL
92 value.  If nulls are allowed for the column, the slot's value will be
93 nil, otherwise its value will be set to the result of calling
94 DATABASE-NULL-VALUE on the type of the slot."))
95
96 (defgeneric output-sql (expr database)
97   )
98
99 (defgeneric output-sql-hash-key (arg database)
100   )
101
102 (defgeneric collect-table-refs (sql)
103   )
104 (defgeneric database-output-sql (arg database)
105   )
106 (defgeneric database-constraint-description  (constraint database)
107   )
108 (defgeneric database-pkey-constraint  (class database)
109   )
110 (defgeneric database-constraint-statement  (constraints database)
111   )
112 (defgeneric %install-class  (class database)
113   )
114 (defgeneric database-generate-column-definition  (class slotdef database)
115   )
116 (defgeneric update-slot-from-db  (instance slotdef val)
117   )
118 (defgeneric key-value-from-db  (slotdef value database)
119   )
120 (defgeneric get-slot-values-from-view  (obj slotdeflist values)
121   )
122 (defgeneric database-output-sql-as-type  (type val database db-type)
123   )
124 (defgeneric read-sql-value  (val type database db-type)
125   )
126