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

  1 karl  1.2 //%2006////////////////////////////////////////////////////////////////////////
  2 r.kieninger 1.1 //
  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 karl        1.2 // 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 r.kieninger 1.1 //
 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 karl        1.2 // 
 21 r.kieninger 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22                 // 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                 // Author: Robert Kieninger (kieningr@de.ibm.com)
 33                 //
 34                 // Modified By:
 35                 //
 36                 //%/////////////////////////////////////////////////////////////////////////////
 37                 
 38                 #include <Pegasus/Common/Config.h>
 39                 #include "AssocClassCache.h"
 40                 
 41                 PEGASUS_USING_STD;
 42 r.kieninger 1.1 
 43                 PEGASUS_NAMESPACE_BEGIN
 44                 
 45                 #define ASSOC_CLASS_NAME_INDEX 0
 46                 #define FROM_CLASS_NAME_INDEX 1
 47                 #define FROM_PROPERTY_NAME_INDEX 2
 48                 #define TO_CLASS_NAME_INDEX 3
 49                 #define TO_PROPERTY_NAME_INDEX 4
 50                 #define NUM_FIELDS 5
 51                 
 52                 Array<AssocClassCache*> AssocClassCache::_assocClassCacheList;
 53                 
 54                 
 55                 /** Retrieves a singleton instance of the class cache for the
 56                   * given namespace.
 57                 */
 58                 AssocClassCache* AssocClassCache::getAssocClassCache(const String& nameSpace)
 59                 {
 60                    for (Uint16 idx=0; idx<_assocClassCacheList.size(); idx++)
 61                    {
 62                       if (nameSpace == _assocClassCacheList[idx]->_nameSpace)
 63 r.kieninger 1.1       {
 64                          return _assocClassCacheList[idx];
 65                       }
 66                    }
 67                 
 68                    // If we got here, no cache exists for the the given namespace so far,
 69                    // so we will create a new one.
 70                    AssocClassCache * newCache = new AssocClassCache(nameSpace);
 71                    _assocClassCacheList.append(newCache);
 72                 
 73                    return newCache;
 74                 }
 75                 
 76                 void AssocClassCache::cleanupAssocClassCaches()
 77                 {
 78                     for (Uint16 idx=_assocClassCacheList.size(); idx>0; idx--)
 79                     {
 80                         delete(_assocClassCacheList[idx-1]);
 81                         _assocClassCacheList.remove(idx-1);
 82                     }
 83                 
 84 r.kieninger 1.1 }
 85                 
 86                 /** Retrieve the list of entries for a from class through direct
 87                  * access via the from class name.
 88                 */
 89 karl        1.3 Boolean AssocClassCache::getAssocClassEntry(const String& fromClassName,
 90 r.kieninger 1.1                                             Array< Array<String> >& entryList)
 91                 {
 92 karl        1.3    return _assocClassCache->lookup(fromClassName,entryList);
 93 r.kieninger 1.1 }
 94                 
 95                 /** Add a new record to the association cache.
 96                  * If an entry for the given from class name already exists,
 97                  * the new entry is appended to the old entry. Otherwise a new entry
 98                  * is added to the cache.
 99                 */
100 karl        1.3 Boolean AssocClassCache::addRecord(const String& fromClassName,
101 r.kieninger 1.1                                    Array<String> assocClassRecord)
102                 {
103                    Array< Array<String> > oldAssocClassEntryList;
104                 
105 karl        1.3    if (_assocClassCache->lookup(fromClassName, oldAssocClassEntryList))
106 r.kieninger 1.1    {
107 karl        1.3       _assocClassCache->remove(fromClassName);
108 r.kieninger 1.1    }
109                 
110                    oldAssocClassEntryList.append(assocClassRecord);
111                 
112 karl        1.3    return _assocClassCache->insert(fromClassName,oldAssocClassEntryList);
113 r.kieninger 1.1 }
114                 
115                 /** Remove an entry from the association cache specified by the given
116                  *  from class name.
117                 */
118 karl        1.3 Boolean AssocClassCache::removeEntry(const String& fromClassName)
119 r.kieninger 1.1 {
120 karl        1.3    return _assocClassCache->remove(fromClassName);
121 r.kieninger 1.1 }
122                 
123                 /** Remove an association record from the association cache specified by the given
124                  *  from class name and association name.
125                 */
126 karl        1.3 Boolean AssocClassCache::removeRecord(const String& fromClassName,
127                                                       const String& assocClassName)
128 r.kieninger 1.1 {
129                    Array< Array<String> > oldAssocClassEntryList;
130 karl        1.3 
131                    if (_assocClassCache->lookup(fromClassName, oldAssocClassEntryList))
132 r.kieninger 1.1    {
133                       for (Uint16 idx=0; idx < oldAssocClassEntryList.size(); idx++ )
134                       {
135                          // The first entry in each record is the association class
136                          // name. Find the record for the association class and remove
137                          // it from the cache entry.
138 karl        1.3          if (String::equalNoCase(oldAssocClassEntryList[idx][ASSOC_CLASS_NAME_INDEX],
139                                                  assocClassName))
140 r.kieninger 1.1          {
141 karl        1.3             _assocClassCache->remove(fromClassName);
142 r.kieninger 1.1             if (oldAssocClassEntryList.size() > 1)
143                             {
144                                oldAssocClassEntryList.remove(idx);
145 karl        1.3                _assocClassCache->insert(fromClassName,oldAssocClassEntryList);
146 r.kieninger 1.1             }
147                             return true;
148                          }
149                       }
150                    }
151                 
152                    return false;
153                 }
154                 
155                 /** Check if the cache is loaded with objects already.
156                 */
157                 Boolean AssocClassCache::isActive()
158                 {
159                    return _isInitialized;
160                 }
161                 
162                 void AssocClassCache::setActive(Boolean flag)
163                 {
164                     _isInitialized = flag;
165                 }
166                 
167 r.kieninger 1.1 
168                 AssocClassCache::~AssocClassCache()
169                 {
170                     delete(_assocClassCache);
171                 }
172                 
173                 AssocClassCache::AssocClassCache(const String& nameSpace)
174                 {
175                     _isInitialized = false;
176                    _nameSpace = nameSpace;
177                    _assocClassCache = new AssocClassCacheHashTableType(1000);
178                 }
179                 
180                 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2