r9193: remove old :nulls-ok attribute. Add :void-value attribute.
[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: db-interface.lisp 9123 2004-04-21 20:34:42Z kevin $
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    "The generic function UPDATE-RECORD-FROM-SLOT updates an individual
24 data item in the column represented by SLOT. The DATABASE is only used
25 if OBJECT is not yet associated with any database, in which case a
26 record is created in DATABASE. Only SLOT is initialized in this case;
27 other columns in the underlying database receive default values. The
28 argument SLOT is the CLOS slot name; the corresponding column names
29 are derived from the View Class definition."))
30
31 (defgeneric update-record-from-slots (object slots &key database)
32   (:documentation 
33    "The generic function UPDATE-RECORD-FROM-SLOTS updates data in the
34 columns represented by SLOTS. The DATABASE is only used if OBJECT is
35 not yet associated with any database, in which case a record is
36 created in DATABASE. Only slots are initialized in this case; other
37 columns in the underlying database receive default values. The
38 argument SLOTS contains the CLOS slot names; the corresponding column
39 names are derived from the view class definition."))
40
41 (defgeneric update-records-from-instance (object &key database)
42   (:documentation
43    "Using an instance of a view class, OBJECT, update the database
44 table that stores its instance data. If OBJECT is already associated
45 with a database, that database is used, and DATABASE is ignored. If
46 OBJECT is not yet associated with a database, a record is created for
47 instance in the appropriate table of DATABASE and the instance becomes
48 associated with that database."))
49
50 (defgeneric delete-instance-records (instance)
51   (:documentation
52    "Deletes the records represented by INSTANCE from the database
53 associated with it. If INSTANCE has no associated database, an error
54 is signalled."))
55
56 (defgeneric update-instance-from-records (instance &key database)
57   (:documentation
58    "The generic function UPDATE-INSTANCE-FROM-RECORDS updates the
59 values in the slots of the View Class instance INSTANCE using the data
60 in the database DATABASE which defaults to the DATABASE that instance
61 is associated with, or the value of *DEFAULT-DATABASE*. If INSTANCE is
62 associated with a database, then DATABASE must be that same
63 database. The update is not recursive on joins. Join slots (that is,
64 slots with :db-kind :join ) are updated, but the joined objects are
65 not updated."))
66
67 (defgeneric update-slot-from-record (instance slot &key database)
68   (:documentation
69    "Updates the value in the slot SLOT of the View Class instance
70 INSTANCE using the data in the database DATABASE which defaults to the
71 database that INSTANCE is associated with, or the value of
72 *DEFAULT-DATABASE*. The argument SLOT is the CLOS slot name, the
73 corresponding column names are derived from the View Class
74 definition. The update is not recursive on joins. Join slots (that is,
75 slots with :db-kind :join) are updated, but the joined objects are not
76 updated."))
77
78 (defgeneric instance-refreshed (instance) 
79   (:documentation 
80    "The function INSTANCE-REFRESHED is called inside SELECT when its
81 REFRESH argument is true and the instance INSTANCE has just been
82 updated. The supplied method on STANDARD-DB-OBJECT does nothing. If
83 your application needs to take action when a View Class instance has
84 been updated by (select ... :refresh t) then add an INSTANCE-REFRESH
85 method specializing on your subclass of STANDARD-DB-OBJECT."))
86
87 (defgeneric update-slot-with-null (instance slotname slotdef)
88   (:documentation "Called to update a slot when its column has a NULL
89 value.  If nulls are allowed for the column, the slot's value will be
90 nil, otherwise its value will be set to the result of calling
91 DATABASE-NULL-VALUE on the type of the slot."))
92
93 (defgeneric output-sql (expr database)
94   )
95
96 (defgeneric output-sql-hash-key (arg database)
97   )
98
99 (defgeneric collect-table-refs (sql)
100   )
101 (defgeneric database-output-sql (arg database)
102   )
103 (defgeneric database-constraint-description  (constraint database)
104   )
105 (defgeneric database-pkey-constraint  (class database)
106   )
107 (defgeneric database-constraint-statement  (constraints database)
108   )
109 (defgeneric %install-class  (class database)
110   )
111 (defgeneric database-generate-column-definition  (class slotdef database)
112   )
113 (defgeneric update-slot-from-db  (instance slotdef val)
114   )
115 (defgeneric key-value-from-db  (slotdef value database)
116   )
117 (defgeneric get-slot-values-from-view  (obj slotdeflist values)
118   )
119 (defgeneric database-output-sql-as-type  (type val database)
120   )
121 (defgeneric read-sql-value  (val type database)
122   )
123 (defgeneric add-to-relation  (target slot-name value)
124   )
125 (defgeneric remove-from-relation  (target slot-name value)
126   )
127