1 martin 1.5 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.6 //
|
3 martin 1.5 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.6 //
|
10 martin 1.5 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.6 //
|
17 martin 1.5 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.6 //
|
20 martin 1.5 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.6 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.5 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.6 //
|
28 martin 1.5 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_SQLiteStore_h
33 #define Pegasus_SQLiteStore_h
34
35 #include <Pegasus/Common/Config.h>
36 #include <Pegasus/Common/CommonUTF.h>
|
37 kumpf 1.2 #include <Pegasus/Common/Mutex.h>
|
38 kumpf 1.1 #include <Pegasus/Repository/PersistentStore.h>
|
39 kumpf 1.4 #include <Pegasus/Repository/AssocClassCache.h>
|
40 kumpf 1.1 #include <Pegasus/Repository/Linkage.h>
41
42 #include <sqlite3.h>
43
44 PEGASUS_NAMESPACE_BEGIN
45
|
46 kumpf 1.2 /**
47 The DbConnectionManager caches database handles for reuse.
48 It has a fixed maximum cache size (currently 4) and uses an LRU algorithm
49 to determine which entry to evict when a new handle is returned to the
50 cache. Note that multiple handles may be cached for a single namespace
51 (database file).
52 */
53 class DbConnectionManager
54 {
55 public:
56 DbConnectionManager(const String& repositoryRoot)
57 : _repositoryRoot(repositoryRoot)
58 {
59 }
60
61 ~DbConnectionManager();
62
63 /**
64 Gets a database connection handle for the specified namespace. It may
65 return a handle removed from its cache or a newly opened one. The
66 caller is responsible for cleaning up the dynamic resources for the
67 kumpf 1.2 database connection or returning it to the cache.
68 */
69 sqlite3* getDbConnection(const CIMNamespaceName& nameSpace);
70
71 /**
72 Add a database connection handle to the cache. If the cache is full,
73 the least recently used handle is evicted.
74 */
75 void cacheDbConnection(
76 const CIMNamespaceName& nameSpace,
77 sqlite3* db);
78
79 /**
80 Converts a namespace name to the database file path which contains
81 the namespace data.
82 */
83 String getDbPath(const CIMNamespaceName& nameSpace);
84
85 /**
86 Opens a database handle for the specified file path. This handle is
87 not cached.
88 kumpf 1.2 */
89 static sqlite3* openDb(const char* fileName);
90
91 private:
92
93 class CacheEntry
94 {
95 public:
96 CacheEntry(const CIMNamespaceName& nameSpace_, sqlite3* db_)
97 : nameSpace(nameSpace_),
98 db(db_)
99 {
100 }
101
102 // Note: The default copy constructor and assignment operator are used.
103 // The caller is responsible for ensuring proper pointer management.
104
105 CIMNamespaceName nameSpace;
106 sqlite3* db;
107 };
108
109 kumpf 1.2 Array<CacheEntry> _cache;
110 Mutex _cacheLock;
111 String _repositoryRoot;
112 };
113
114
|
115 kumpf 1.1 class PEGASUS_REPOSITORY_LINKAGE SQLiteStore : public PersistentStore
116 {
117 public:
118
119 static Boolean isExistingRepository(const String& repositoryRoot);
120
121 SQLiteStore(
122 const String& repositoryRoot,
123 ObjectStreamer* streamer);
124
125 ~SQLiteStore();
126
127 Boolean storeCompleteClassDefinitions()
128 {
129 return false;
130 }
131
132 Array<NamespaceDefinition> enumerateNameSpaces();
133 void createNameSpace(
134 const CIMNamespaceName& nameSpace,
135 Boolean shareable,
136 kumpf 1.1 Boolean updatesAllowed,
|
137 venkat.puvvada 1.3 const String& parentNameSpace,
138 const String& remoteInfo);
|
139 kumpf 1.1 void modifyNameSpace(
140 const CIMNamespaceName& nameSpace,
141 Boolean shareable,
142 Boolean updatesAllowed);
143 void deleteNameSpace(const CIMNamespaceName& nameSpace);
144 Boolean isNameSpaceEmpty(const CIMNamespaceName& nameSpace);
145
146 Array<CIMQualifierDecl> enumerateQualifiers(
147 const CIMNamespaceName& nameSpace);
148 /**
149 Gets a qualifier declaration for a specified qualifier name in a
150 specified namespace. Returns an uninitialized object if the qualifier
151 is not found.
152 */
153 CIMQualifierDecl getQualifier(
154 const CIMNamespaceName& nameSpace,
155 const CIMName& qualifierName);
156 void setQualifier(
157 const CIMNamespaceName& nameSpace,
158 const CIMQualifierDecl& qualifierDecl);
159 void deleteQualifier(
160 kumpf 1.1 const CIMNamespaceName& nameSpace,
161 const CIMName& qualifierName);
162
163 Array<Pair<String, String> > enumerateClassNames(
164 const CIMNamespaceName& nameSpace);
165 CIMClass getClass(
166 const CIMNamespaceName& nameSpace,
167 const CIMName& className,
168 const CIMName& superClassName);
169 void createClass(
170 const CIMNamespaceName& nameSpace,
171 const CIMClass& newClass,
172 const Array<ClassAssociation>& classAssocEntries);
173 void modifyClass(
174 const CIMNamespaceName& nameSpace,
175 const CIMClass& modifiedClass,
176 const CIMName& oldSuperClassName,
177 Boolean isAssociation,
178 const Array<ClassAssociation>& classAssocEntries);
179 void deleteClass(
180 const CIMNamespaceName& nameSpace,
181 kumpf 1.1 const CIMName& className,
182 const CIMName& superClassName,
183 Boolean isAssociation,
184 const Array<CIMNamespaceName>& dependentNameSpaceNames);
185 Array<CIMObjectPath> enumerateInstanceNamesForClass(
186 const CIMNamespaceName& nameSpace,
187 const CIMName& className);
188 Array<CIMInstance> enumerateInstancesForClass(
189 const CIMNamespaceName& nameSpace,
190 const CIMName& className);
191 CIMInstance getInstance(
192 const CIMNamespaceName& nameSpace,
193 const CIMObjectPath& instanceName);
194 void createInstance(
195 const CIMNamespaceName& nameSpace,
196 const CIMObjectPath& instanceName,
197 const CIMInstance& cimInstance,
198 const Array<InstanceAssociation>& instAssocEntries);
199 void modifyInstance(
200 const CIMNamespaceName& nameSpace,
201 const CIMObjectPath& instanceName,
202 kumpf 1.1 const CIMInstance& cimInstance);
203 void deleteInstance(
204 const CIMNamespaceName& nameSpace,
205 const CIMObjectPath& instanceName);
206 Boolean instanceExists(
207 const CIMNamespaceName& nameSpace,
208 const CIMObjectPath& instanceName);
209
210 void getClassAssociatorNames(
211 const CIMNamespaceName& nameSpace,
212 const Array<CIMName>& classList,
213 const Array<CIMName>& assocClassList,
214 const Array<CIMName>& resultClassList,
215 const String& role,
216 const String& resultRole,
217 Array<String>& associatorNames);
218 void getClassReferenceNames(
219 const CIMNamespaceName& nameSpace,
220 const Array<CIMName>& classList,
221 const Array<CIMName>& resultClassList,
222 const String& role,
223 kumpf 1.1 Array<String>& referenceNames);
224
225 void getInstanceAssociatorNames(
226 const CIMNamespaceName& nameSpace,
227 const CIMObjectPath& instanceName,
228 const Array<CIMName>& assocClassList,
229 const Array<CIMName>& resultClassList,
230 const String& role,
231 const String& resultRole,
232 Array<String>& associatorNames);
233 void getInstanceReferenceNames(
234 const CIMNamespaceName& nameSpace,
235 const CIMObjectPath& instanceName,
236 const Array<CIMName>& resultClassList,
237 const String& role,
238 Array<String>& referenceNames);
239
240 private:
241
242 void _execDbStatement(
243 sqlite3* db,
244 kumpf 1.1 const char* sqlStatement);
245
246 void _initSchema(sqlite3* db);
247
248 void _beginTransaction(sqlite3* db);
249 void _commitTransaction(sqlite3* db);
250
251 String _getNormalizedName(const CIMName& className)
252 {
253 String cn = className.getString();
254 cn.toLower();
255 return cn;
256 }
257
|
258 kumpf 1.4 void _initAssocClassCache(
259 const CIMNamespaceName& nameSpace,
260 AssocClassCache* cache);
|
261 kumpf 1.1 void _addClassAssociationEntries(
262 sqlite3* db,
263 const CIMNamespaceName& nameSpace,
264 const Array<ClassAssociation>& classAssocEntries);
265 void _removeClassAssociationEntries(
266 sqlite3* db,
267 const CIMNamespaceName& nameSpace,
268 const CIMName& assocClassName);
269
270 void _addInstanceAssociationEntries(
271 sqlite3* db,
272 const CIMNamespaceName& nameSpace,
273 const Array<InstanceAssociation>& instanceAssocEntries);
274 void _removeInstanceAssociationEntries(
275 sqlite3* db,
276 const CIMNamespaceName& nameSpace,
277 const CIMObjectPath& assocInstanceName);
278
279 String _repositoryRoot;
|
280 kumpf 1.2 DbConnectionManager _dbcm;
|
281 kumpf 1.1 ObjectStreamer* _streamer;
|
282 kumpf 1.4 AssocClassCacheManager _assocClassCacheManager;
|
283 kumpf 1.1 };
284
285 PEGASUS_NAMESPACE_END
286
287 #endif /* Pegasus_SQLiteStore_h */
|