Remove CVS $Id$ keyword
[clsql.git] / sql / initialize.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          initialize.lisp
6 ;;;; Purpose:       Initializion routines for db backend
7 ;;;; Programmers:   Kevin M. Rosenberg
8 ;;;; Date Started:  May 2002
9 ;;;;
10 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
11 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
12 ;;;;
13 ;;;; CLSQL users are granted the rights to distribute and use this software
14 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
15 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
16 ;;;; *************************************************************************
17
18 (in-package #:clsql-sys)
19
20 (defvar *loaded-database-types* nil
21   "Contains a list of database types which have been defined/loaded.")
22
23 (defmethod database-type-load-foreign (x)
24   (error "No generic function defined for database-type-load-foreign with parameters of ~S" x))
25
26 (defmethod database-type-load-foreign :after (database-type)
27   (when (database-type-library-loaded database-type)
28      (pushnew database-type *loaded-database-types*)))
29
30 (defun reload-database-types ()
31   "Reloads any foreign code for the loaded database types after a dump."
32   (mapc #'database-type-load-foreign *loaded-database-types*))
33
34 (defvar *default-database-type* nil
35   "Designates the default database type which is initialised by
36   the function INITIALISE-DATABASE-TYPE.")
37
38 (defvar *initialized-database-types* nil
39   "A list of database types which have currently been initialised
40 by calling INITIALIZE-DATABASE-TYPE.")
41
42 (defun initialize-database-type (&key (database-type *default-database-type*))
43   "Initializes the supplied DATABASE-TYPE, if it is not already
44 initialized, as indicated by *INITIALIZED-DATABASE-TYPES* and
45 returns DATABASE-TYPE. *DEFAULT-DATABASE-TYPE* is set to
46 DATABASE-TYPE and, if DATABASE-TYPE has not been initialised, it
47 is added to *INITIALIZED-DATABASE-TYPES*. "
48   (when (member database-type *initialized-database-types*)
49     (return-from initialize-database-type database-type))
50
51   (let ((system (intern (concatenate 'string
52                           (symbol-name '#:clsql-)
53                           (symbol-name database-type)))))
54     (when (not (find-package system))
55       (asdf:operate 'asdf:load-op system)))
56
57   (when (database-initialize-database-type database-type)
58     (push database-type *initialized-database-types*)
59     (setf *default-database-type* database-type)
60     database-type))
61