(file) Return to SQLiteStore.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Repository

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2