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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2