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

  1 martin 1.8 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.9 //
  3 martin 1.8 // 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.9 //
 10 martin 1.8 // 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.9 //
 17 martin 1.8 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.9 //
 20 martin 1.8 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.9 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.8 // 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.9 //
 28 martin 1.8 //////////////////////////////////////////////////////////////////////////
 29 r.kieninger 1.1 //
 30                 //%/////////////////////////////////////////////////////////////////////////////
 31                 
 32                 #include <Pegasus/Common/Config.h>
 33 kumpf       1.7 #include <Pegasus/Common/ArrayInternal.h>
 34 r.kieninger 1.1 #include "AssocClassCache.h"
 35                 
 36                 PEGASUS_USING_STD;
 37                 
 38                 PEGASUS_NAMESPACE_BEGIN
 39                 
 40 kumpf       1.6 AssocClassCacheManager::AssocClassCacheManager()
 41                 {
 42                 }
 43 r.kieninger 1.1 
 44 kumpf       1.6 AssocClassCacheManager::~AssocClassCacheManager()
 45                 {
 46                     for (Uint32 i = _assocClassCacheList.size(); i > 0; i--)
 47                     {
 48                         delete _assocClassCacheList[i-1];
 49                         _assocClassCacheList.remove(i-1);
 50                     }
 51                 }
 52 r.kieninger 1.1 
 53 kumpf       1.4 /**
 54                     Retrieves a singleton instance of the class cache for the given namespace.
 55 r.kieninger 1.1 */
 56 kumpf       1.6 AssocClassCache* AssocClassCacheManager::getAssocClassCache(
 57                     const String& nameSpace)
 58 r.kieninger 1.1 {
 59 kumpf       1.6     for (Uint32 i = 0; i < _assocClassCacheList.size(); i++)
 60 kumpf       1.4     {
 61 kumpf       1.6         if (nameSpace == _assocClassCacheList[i]->getNameSpace())
 62 kumpf       1.4         {
 63 kumpf       1.6             return _assocClassCacheList[i];
 64 kumpf       1.4         }
 65                     }
 66                 
 67 kumpf       1.6     // If we got here, no cache exists for the given namespace so far,
 68 kumpf       1.4     // so we will create a new one.
 69                     AssocClassCache* newCache = new AssocClassCache(nameSpace);
 70                     _assocClassCacheList.append(newCache);
 71 r.kieninger 1.1 
 72 kumpf       1.4     return newCache;
 73 r.kieninger 1.1 }
 74                 
 75                 
 76                 /** Retrieve the list of entries for a from class through direct
 77 kumpf       1.4     access via the from class name.
 78 r.kieninger 1.1 */
 79 kumpf       1.4 Boolean AssocClassCache::getAssocClassEntry(
 80 kumpf       1.6     const CIMName& fromClassName,
 81                     Array<ClassAssociation>& entryList)
 82 r.kieninger 1.1 {
 83 kumpf       1.6     return _assocTable.lookup(fromClassName.getString(), entryList);
 84 r.kieninger 1.1 }
 85                 
 86 kumpf       1.7 Boolean AssocClassCache::getReferenceNames(
 87                     const Array<CIMName>& classList,
 88                     const Array<CIMName>& resultClassList,
 89                     const String& role,
 90                     Array<String>& referenceNames)
 91                 {
 92                     Array<ClassAssociation> records;
 93                     Boolean found = false;
 94                 
 95                     // For each of the target classes retrieve the list of matching
 96                     // association classes from the cache.
 97                     // The cache uses the from class name as an index and returns all
 98                     // association class records having that from class.
 99                 
100                     for (Uint16 idx = 0; idx < classList.size(); idx++)
101                     {
102                         String fromClassName = classList[idx].getString();
103                         if (getAssocClassEntry(fromClassName, records))
104                         {
105                             for (Uint16 rx = 0; rx < records.size(); rx++)
106                             {
107 kumpf       1.7                 if ((role.size() == 0) ||
108                                     (records[rx].fromPropertyName == role))
109                                 {
110                                     // Skip classes that do not appear in the result class list
111                                     if ((resultClassList.size() != 0) &&
112                                         (!Contains(resultClassList,
113                                              records[rx].assocClassName)))
114                                     {
115                                         continue;
116                                     }
117                 
118                                     // This class qualifies; add it to the list (skipping
119                                     // duplicates)
120                                     if (!Contains(referenceNames,
121                                             records[rx].assocClassName.getString()))
122                                     {
123                                         referenceNames.append(
124                                             records[rx].assocClassName.getString());
125                                     }
126                                     found = true;
127                                 }
128 kumpf       1.7             }
129                         }
130                     }
131                 
132                     return found;
133                 }
134                 
135 r.kieninger 1.1 /** Add a new record to the association cache.
136 kumpf       1.4     If an entry for the given from class name already exists,
137                     the new entry is appended to the old entry. Otherwise a new entry
138                     is added to the cache.
139 r.kieninger 1.1 */
140 kumpf       1.4 Boolean AssocClassCache::addRecord(
141 kumpf       1.6     const CIMName& fromClassName,
142                     const ClassAssociation& assocClassRecord)
143 r.kieninger 1.1 {
144 kumpf       1.6     Array<ClassAssociation> oldAssocClassEntryList;
145 r.kieninger 1.1 
146 kumpf       1.6     if (_assocTable.lookup(fromClassName.getString(), oldAssocClassEntryList))
147 kumpf       1.4     {
148 kumpf       1.6         _assocTable.remove(fromClassName.getString());
149 kumpf       1.4     }
150 r.kieninger 1.1 
151 kumpf       1.4     oldAssocClassEntryList.append(assocClassRecord);
152 r.kieninger 1.1 
153 kumpf       1.6     return _assocTable.insert(
154                         fromClassName.getString(), oldAssocClassEntryList);
155 r.kieninger 1.1 }
156                 
157 kumpf       1.4 /** Remove an association record from the association cache specified by the
158                     given from class name and association name.
159 r.kieninger 1.1 */
160 kumpf       1.4 Boolean AssocClassCache::removeRecord(
161 kumpf       1.6     const CIMName& fromClassName,
162                     const CIMName& assocClassName)
163 r.kieninger 1.1 {
164 kumpf       1.6     Array<ClassAssociation> oldAssocClassEntryList;
165 kumpf       1.4 
166 kumpf       1.6     if (_assocTable.lookup(fromClassName.getString(), oldAssocClassEntryList))
167 kumpf       1.4     {
168 kumpf       1.6         for (Uint32 idx=0; idx < oldAssocClassEntryList.size(); idx++)
169 kumpf       1.4         {
170 kumpf       1.7             // Find the record for the association class and remove
171 kumpf       1.4             // it from the cache entry.
172 kumpf       1.6             if (oldAssocClassEntryList[idx].assocClassName == assocClassName)
173 r.kieninger 1.1             {
174 kumpf       1.6                 _assocTable.remove(fromClassName.getString());
175 kumpf       1.4                 if (oldAssocClassEntryList.size() > 1)
176                                 {
177                                     oldAssocClassEntryList.remove(idx);
178 kumpf       1.6                     _assocTable.insert(
179                                         fromClassName.getString(), oldAssocClassEntryList);
180 kumpf       1.4                 }
181                                 return true;
182 r.kieninger 1.1             }
183 kumpf       1.4         }
184                     }
185 r.kieninger 1.1 
186 kumpf       1.4     return false;
187 r.kieninger 1.1 }
188                 
189 kumpf       1.7 /** Remove association records from the association cache specified by the
190                     association class name.
191                 */
192                 Boolean AssocClassCache::removeAssocClassRecords(const CIMName& assocClassName)
193                 {
194                     Array<CIMName> fromClassNames;
195                 
196                     for (AssocClassCacheHashTableType::Iterator i = _assocTable.start(); i; i++)
197                     {
198                         Array<ClassAssociation> assocClassEntryList = i.value();
199                         for (Uint32 j = 0; j < assocClassEntryList.size(); j++)
200                         {
201                             if (assocClassEntryList[j].assocClassName == assocClassName)
202                             {
203                                 // Note: We cannot remove an entry from the HashTable while
204                                 // iterating over it.
205                                 fromClassNames.append(assocClassEntryList[j].fromClassName);
206                                 break;
207                             }
208                         }
209                     }
210 kumpf       1.7 
211                     for (Uint32 i = 0; i < fromClassNames.size(); i++)
212                     {
213                         removeRecord(fromClassNames[i], assocClassName);
214                     }
215                 
216                     return fromClassNames.size();
217                 }
218                 
219 r.kieninger 1.1 /** Check if the cache is loaded with objects already.
220                 */
221                 Boolean AssocClassCache::isActive()
222                 {
223 kumpf       1.4     return _isInitialized;
224 r.kieninger 1.1 }
225                 
226                 void AssocClassCache::setActive(Boolean flag)
227                 {
228                     _isInitialized = flag;
229                 }
230                 
231                 
232                 AssocClassCache::~AssocClassCache()
233                 {
234                 }
235                 
236                 AssocClassCache::AssocClassCache(const String& nameSpace)
237 kumpf       1.6     : _nameSpace(nameSpace),
238                       _isInitialized(false),
239                       _assocTable(1000)
240 r.kieninger 1.1 {
241                 }
242                 
243                 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2