~ubuntu-branches/ubuntu/quantal/gconf/quantal

« back to all changes in this revision

Viewing changes to backends/bdb.h

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2007-11-01 18:47:26 UTC
  • mto: (7.1.1 lenny) (1.2.1) (76.1.1 oneiric-proposed)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20071101184726-e3e4cxfcp41tz6ui
Tags: upstream-2.20.1
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * GConf BerkeleyDB back-end
3
 
 *
4
 
 * Copyright (C) 2000 Sun Microsystems Inc
5
 
 * Contributed to the GConf project.
6
 
 *
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Library General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2 of the License, or (at your option) any later version.
11
 
 *
12
 
 * This library is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Library General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Library General Public
18
 
 * License along with this library; if not, write to the
19
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * Boston, MA 02111-1307, USA.
21
 
 */
22
 
 
23
 
/*
24
 
 * Overview
25
 
 *
26
 
 * A GConf back-end is a storage implementation for the GConf API. Different
27
 
 * back-ends or "drivers" are integrated into GConf using a struct
28
 
 * GConfBackendVTable containing function pointers, simulating a C++
29
 
 * virtual function pointer table (vtable).
30
 
 *
31
 
 * This back-end uses the BerkeleyDB database toolkit from Sleepycat
32
 
 * software (www.sleepycat.com). BerkeleyDB is not a relational database,
33
 
 * but is highly suited to GConf as it simply stores key-value pairs and
34
 
 * is relatively efficient.
35
 
 *
36
 
 * The storage model if implemented in a relational database would
37
 
 * use two tables:
38
 
 *
39
 
 *   Directory structure table: { directory_path, id, parent_directory_id }
40
 
 *   Keyname/Value table:       { key_name, directory_id, value }
41
 
 *
42
 
 * A keyname is the last element in the hierarchical key; a directory path
43
 
 * is required to form the complete key - this composition of directory path
44
 
 * and keyname is called a keypath.
45
 
 *
46
 
 * Because a BerkeleyDB database can only store a single key+value pair,
47
 
 * this program splits these tables into four databases:
48
 
 *
49
 
 * Table:        Key | Value:                          Data?
50
 
 * -----         -----------                           ----
51
 
 * BDB_DIR       directory_path | directory_id         Yes
52
 
 * BDB_HIERARCHY directory_id | child_directory_name   No
53
 
 * BDB_KEY       directory_id | keyname                No
54
 
 * BDB_VALUE     keypath | value                       Yes
55
 
 * BDB_SCHEMA    keypath | schema-key                  Yes
56
 
 * BDB_SCHKEY    directory_id | schema-key-name        No
57
 
 *
58
 
 * A Data table is one that may not have records with identical keys. Other
59
 
 * tables may not contain identical key-value pairs (i.e. two records
60
 
 * could have the same key but must have different values).
61
 
 *
62
 
 
63
 
 * Note that an important goal is that all tables could be
64
 
 * reconstructed from the BDB_VALUE table and the BDB_SCHEMA table.  This
65
 
 * is possible because the BDB_VALUE table contains the full key-name (the
66
 
 * keypath) and the value, similar to the BDB_SCHEMA table; the other
67
 
 * tables permit the database to be traversed hierarchically instead of
68
 
 * linearly.
69
 
 *
70
 
 * Locales
71
 
 * 
72
 
 * Locale data is stored in a subdirectory of the regular key directory for each
73
 
 * locale; e.g. the Spanish locale data for a key /gnome/desktop/logo is
74
 
 * /gnome/desktop/%locale%es/logo. This allows locale data to be found
75
 
 * efficiently, e.g. the all_entries() backend method accepts a list of
76
 
 * locales to be searched. If the list contains, { "es", "en", "C" }
77
 
 * then the directories searched are /gnome/desktop/, /gnome/desktop/%locale%es,
78
 
 * /gnome/desktop/%locale%en, and /gnome/desktop/%locale%C.
79
 
 *
80
 
 * Schemas
81
 
 *
82
 
 * Schemas are stored with regular keys in the BDB_VALUE database, but it
83
 
 * is necessary to search for them specifically. This requires two databases,
84
 
 * BDB_SCHEMA to store the "applyto" key (see the GConf docs) and the schema
85
 
 * key under which the schema can be found. The BDB_SCHKEY is similar to the
86
 
 * BDB_KEY database as it records the keys in each directory for which a 
87
 
 * schema value may be found.
88
 
 *
89
 
 * Locking
90
 
 *
91
 
 * GConf doesn't specify any locking functionality at the API level.
92
 
 * Currently locking is a requirement, because workgroups and ultimately
93
 
 * enterprises will require large central GConf databases to store
94
 
 * common settings and defaults for users, although these users will
95
 
 * also require separate writable stores for their personal preferences.
96
 
 * For now, no locking functionality is implemented, but later locking may
97
 
 * be required for individual key-value pairs and for hierarchies. The
98
 
 * BDB_DIR database is locked when updating the highest integer id value
99
 
 * assigned to a directory.
100
 
 *
101
 
 * Caching
102
 
 *
103
 
 * Ideally caching should be independent of any back-end, which can only
104
 
 * be achieved by layering the cache on top of the back-ends rather than
105
 
 * within each one, though this is not always practical/efficient. This
106
 
 * implementation includes minimal caching for database structure, not
107
 
 * for values. Even this caching should be above the back-ends, as it
108
 
 * is time-consuming to find a key and to decide where it should be
109
 
 * stored; if each store in GConf has a base path, then no queries are
110
 
 * needed at run-time to locate keys for read or write.
111
 
 *
112
 
 * Atomic Saving
113
 
 *
114
 
 * BerkeleyDB transactions are used to do grouped writes.
115
 
 */
116
 
 
117
 
#ifndef BDB_H
118
 
 
119
 
#ifdef HAVE_DB3_DB_H
120
 
#include <db3/db.h>
121
 
#else
122
 
#include <db.h>
123
 
#endif
124
 
#include <glib.h>
125
 
#include <gconf/gconf.h>
126
 
 
127
 
#define DBD_DIR "dir.db"
128
 
#define DBD_HIERARCHY   "hierarchy.db"
129
 
#define DBD_KEY "key.db"
130
 
#define DBD_VALUE       "value.db"
131
 
#define DBD_SCHEMA      "schema.db"
132
 
#define DBD_SCHKEY      "schkey.db"
133
 
 
134
 
struct _BDB_Store;
135
 
 
136
 
typedef struct _BDB_Store
137
 
{
138
 
  DB *dbdirp;
139
 
  DB *dbhierp;
140
 
  DB *dbkeyp;
141
 
  DB *dbvalp;
142
 
  DB *dbschp;
143
 
  DB *dbschkeyp;
144
 
 
145
 
  DBC *keycp;
146
 
  DBC *schkeycp;
147
 
}
148
 
BDB_Store;
149
 
 
150
 
int bdb_create (BDB_Store * bdb, const char *dbname);
151
 
 
152
 
BDB_Store *bdb_new (const char *dir, int flags);
153
 
 
154
 
#define CLEAR_STRUCT(x) (memset(&x, 0, sizeof(x)))
155
 
 
156
 
extern DBT *temp_string_key (const char *key);
157
 
extern DBT *temp_int_key (int akey);
158
 
extern guint32 get_dir_id (BDB_Store * bdb, const char *dir);
159
 
extern void add_key (BDB_Store * bdb, const char *dir, const char *keypath);
160
 
extern void bdb_set_sysname (const char *name);
161
 
extern guint32 get_or_create_dir (BDB_Store * bdb, const char *dir);
162
 
 
163
 
int bdb_create (BDB_Store * bdb, const char *dir);
164
 
int bdb_open (BDB_Store * bdb, const char *dir, int flags);
165
 
void bdb_close (BDB_Store * bdb);
166
 
 
167
 
extern GConfValue *bdb_query_value (BDB_Store * bdb, const char *key,
168
 
                                    char **schema_name, GError ** err);
169
 
 
170
 
extern GSList *bdb_all_dirs (BDB_Store * bdb, const char *dirname,
171
 
                             GError ** err);
172
 
extern GSList *bdb_all_entries (BDB_Store * bdb, const char *dirpath,
173
 
                                GSList * inlist, GError ** err);
174
 
extern void bdb_put_value (BDB_Store * bdb, const char *key, GConfValue * val,
175
 
                           GError ** err);
176
 
extern GSList *bdb_all_subdirs (BDB_Store * bdb, const char *dirname,
177
 
                                GError ** err);
178
 
extern void bdb_unset_value (BDB_Store * bdb, const char *keypath,
179
 
                             const char *locale, GError ** err);
180
 
extern void bdb_remove_dir (BDB_Store * bdb, const char *dirname,
181
 
                            GError ** err);
182
 
extern void bdb_set_schema (BDB_Store * bdb, const char *key,
183
 
                            const char *schema_key, GError ** err);
184
 
 
185
 
extern gboolean bdb_is_localised (const gchar * key);
186
 
 
187
 
#define struct_dup(x) g_memdup(&x, sizeof(x))
188
 
 
189
 
#endif /* BDB_H */