1 mike 1.1.2.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 mike 1.1.2.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 #include <Pegasus/Common/Config.h>
35 #include <cctype>
36 #include <cstdio>
37 #include <fstream>
38 #include <Pegasus/Common/Pair.h>
39 #include <Pegasus/Common/FileSystem.h>
40 #include <Pegasus/Common/InternalException.h>
41 #include <Pegasus/Common/DeclContext.h>
42 #include <Pegasus/Common/Resolver.h>
43 mike 1.1.2.1 #include <Pegasus/Common/System.h>
44 #include <Pegasus/Common/Tracer.h>
45 #include <Pegasus/Common/PegasusVersion.h>
46 #include <Pegasus/Common/MessageLoader.h>
47 #include <Pegasus/Common/CommonUTF.h>
48 #include <Pegasus/Common/ReadWriteSem.h>
49 #include <Pegasus/Common/Dir.h>
50 #include <Pegasus/Common/XmlStreamer.h>
51 #include <Pegasus/Common/BinaryStreamer.h>
52 #include <Pegasus/Common/AutoStreamer.h>
53 #include "DefaultRepository.h"
54 #include "RepositoryDeclContext.h"
55 #include "InstanceIndexFile.h"
56 #include "InstanceDataFile.h"
57 #include "AssocInstTable.h"
58 #include "AssocClassTable.h"
59 #include "ObjectCache.h"
60 #include "Filtering.h"
61
62 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
63 // #define win32
64 mike 1.1.2.1 # include <zlib.h>
65 # include <sstream>
66 #endif
67
68 #if 0
69 #undef PEG_METHOD_ENTER
70 #undef PEG_METHOD_EXIT
71 #define PEG_METHOD_ENTER(x,y) cout<<"--- Enter: "<<y<<endl;
72 #define PEG_METHOD_EXIT()
73 #endif
74
75 PEGASUS_USING_STD;
76
77 PEGASUS_NAMESPACE_BEGIN
78
79 static const Uint32 _MAX_FREE_COUNT = 16;
80
81 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
82 static int compressMode = 0; // PEP214
83 #endif
84
85 mike 1.1.2.1 // #define TEST_OUTPUT
86
87 //==============================================================================
88 //
89 // This is the class cache, which caches up PEGASUS_CLASS_CACHE_SIZE classes
90 // into memory. To override the default, define PEGASUS_CLASS_CACHE_SIZE in
91 // your environment. To supress the cache (and not compile it in at all)
92 // define PEGASUS_CLASS_CACHE_SIZE to 0.
93 //
94 //==============================================================================
95
96 #define PEGASUS_QUALIFIER_CACHE_SIZE 80
97
98 #if !defined(PEGASUS_CLASS_CACHE_SIZE)
99 # define PEGASUS_CLASS_CACHE_SIZE 8
100 #endif
101
102 #if (PEGASUS_CLASS_CACHE_SIZE != 0)
103 # define PEGASUS_USE_CLASS_CACHE
104 #endif
105
106 mike 1.1.2.1 #ifdef PEGASUS_USE_CLASS_CACHE
107 static ObjectCache<CIMClass> _classCache(PEGASUS_CLASS_CACHE_SIZE);
108 #endif /* PEGASUS_USE_CLASS_CACHE */
109
110 static ObjectCache<CIMQualifierDecl>
111 _qualifierCache(PEGASUS_QUALIFIER_CACHE_SIZE);
112
113 ////////////////////////////////////////////////////////////////////////////////
114 //
115 // _LoadFileToMemory() PEP214
116 //
117 // The gzxxxx functions read both compresed and non-compresed files.
118 //
119 // There is no conditional flag on reading of files since gzread()
120 // (from zlib) is capable of reading compressed and non-compressed
121 // files (so it contains the logic that examines the header
122 // and magic number). Everything will work properly if the repository
123 // has some compressed and some non-compressed files.
124 //
125 //
126 ////////////////////////////////////////////////////////////////////////////////
127 mike 1.1.2.1
128 void _LoadFileToMemory(Buffer& data, const String& path)
129 {
130
131 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
132
133 Uint32 fileSize;
134
135 if (!FileSystem::getFileSize(path, fileSize))
136 throw CannotOpenFile(path);
137
138 gzFile fp = gzopen(path.getCString(), "rb");
139
140 if (fp == NULL)
141 throw CannotOpenFile(path);
142
143 data.reserveCapacity(fileSize);
144 char buffer[4096];
145 int n;
146
147 while ((n = gzread(fp, buffer, sizeof(buffer))) > 0)
148 mike 1.1.2.1 data.append(buffer, n);
149
150 gzclose(fp);
151
152 #else
153
154 FileSystem::loadFileToMemory(data, path);
155
156 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
157 }
158
159 ////////////////////////////////////////////////////////////////////////////////
160 //
161 // _LoadObject()
162 //
163 // Loads objects (classes and qualifiers) from disk to
164 // memory objects.
165 //
166 ////////////////////////////////////////////////////////////////////////////////
167
168 template<class Object>
169 mike 1.1.2.1 void _LoadObject(
170 const String& path,
171 Object& object,
172 ObjectStreamer* streamer)
173 {
174 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_LoadObject");
175
176 // Get the real path of the file:
177
178 String realPath;
179
180 if (!FileSystem::existsNoCase(path, realPath))
181 {
182 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
183 path + " does not exist.");
184 PEG_METHOD_EXIT();
185 throw CannotOpenFile(path);
186 }
187
188 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "realpath = " + realPath);
189
190 mike 1.1.2.1 // Load file into memory:
191
192 Buffer data;
193 _LoadFileToMemory(data, realPath);
194 streamer->decode(data, 0, object);
195
196 PEG_METHOD_EXIT();
197 }
198
199 ////////////////////////////////////////////////////////////////////////////////
200 //
201 // _SaveObject()
202 //
203 // Saves objects (classes and qualifiers) from memory to
204 // disk files.
205 //
206 ////////////////////////////////////////////////////////////////////////////////
207
208 void _SaveObject(
209 const String& path,
210 Buffer& objectXml,
211 mike 1.1.2.1 ObjectStreamer* streamer)
212 {
213 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_SaveObject");
214
215 // cout << "SAVE[" << path << "]" << endl;
216
217 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
218 if (compressMode) // PEP214
219 {
220 PEGASUS_STD(ostringstream) os;
221 streamer->write(os, objectXml);
222 string str = os.str();
223
224 gzFile fp = gzopen(path.getCString(), "wb");
225
226 if (fp == NULL)
227 throw CannotOpenFile(path);
228
229 const char* ptr = str.data();
230 size_t rem = str.size();
231 int n;
232 mike 1.1.2.1
233 while (rem > 0 && (n = gzwrite(fp, (char*)ptr, rem)) > 0)
234 {
235 ptr += n;
236 rem -= n;
237 }
238
239 gzclose(fp);
240 }
241 else
242 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
243 {
244 PEGASUS_STD(ofstream) os(path.getCString() PEGASUS_IOS_BINARY);
245
246 if (!os)
247 {
248 PEG_METHOD_EXIT();
249 throw CannotOpenFile(path);
250 }
251
252 streamer->write(os, objectXml);
253 mike 1.1.2.1 }
254 PEG_METHOD_EXIT();
255 }
256
257 ////////////////////////////////////////////////////////////////////////////////
258 //
259 // _beginInstanceTransaction()
260 //
261 // Creates rollback files to allow an incomplete transaction to be voided.
262 //
263 ////////////////////////////////////////////////////////////////////////////////
264
265 void _beginInstanceTransaction(
266 const String& indexFilePath,
267 const String& dataFilePath)
268 {
269 PEG_METHOD_ENTER(TRC_REPOSITORY, "_beginInstanceTransaction");
270
271 //
272 // Begin the transaction (an incomplete transaction will cause
273 // a rollback the next time an instance-oriented routine is invoked).
274 mike 1.1.2.1 //
275
276 if (!InstanceIndexFile::beginTransaction(indexFilePath))
277 {
278 PEG_METHOD_EXIT();
279 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
280 MessageLoaderParms("Repository.DefaultRepository.BEGIN_FAILED",
281 "begin failed"));
282 }
283
284 if (!InstanceDataFile::beginTransaction(dataFilePath))
285 {
286 PEG_METHOD_EXIT();
287 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
288 MessageLoaderParms("Repository.DefaultRepository.BEGIN_FAILED",
289 "begin failed"));
290 }
291
292 PEG_METHOD_EXIT();
293 }
294
295 mike 1.1.2.1 ////////////////////////////////////////////////////////////////////////////////
296 //
297 // _commitInstanceTransaction()
298 //
299 // Removes the rollback files to complete the transaction.
300 //
301 ////////////////////////////////////////////////////////////////////////////////
302
303 void _commitInstanceTransaction(
304 const String& indexFilePath,
305 const String& dataFilePath)
306 {
307 PEG_METHOD_ENTER(TRC_REPOSITORY, "_commitInstanceTransaction");
308
309 //
310 // Commit the transaction by removing the rollback files.
311 //
312
313 if (!InstanceIndexFile::commitTransaction(indexFilePath))
314 {
315 PEG_METHOD_EXIT();
316 mike 1.1.2.1 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
317 MessageLoaderParms("Repository.DefaultRepository.COMMIT_FAILED",
318 "commit failed"));
319 }
320
321 if (!InstanceDataFile::commitTransaction(dataFilePath))
322 {
323 PEG_METHOD_EXIT();
324 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
325 MessageLoaderParms("Repository.DefaultRepository.COMMIT_FAILED",
326 "commit failed"));
327 }
328
329 PEG_METHOD_EXIT();
330 }
331
332 ////////////////////////////////////////////////////////////////////////////////
333 //
334 // _rollbackInstanceTransaction()
335 //
336 // Restores instance index and data files to void an incomplete operation.
337 mike 1.1.2.1 // If there are no rollback files, this method has no effect.
338 //
339 ////////////////////////////////////////////////////////////////////////////////
340
341 static String _dirName(const String& path)
342 {
343 Uint32 n = path.size();
344
345 for (Uint32 i = n; i != 0; )
346 {
347 if (path[--i] == '/')
348 return path.subString(0, i);
349 }
350
351 return String(".");
352 }
353
354 void _rollbackInstanceTransaction(
355 const String& indexFilePath,
356 const String& dataFilePath)
357 {
358 mike 1.1.2.1 PEG_METHOD_ENTER(TRC_REPOSITORY, "_rollbackInstanceTransaction");
359
360 // Avoid rollback logic if directory has no .rollback files.
361
362 String path = _dirName(indexFilePath);
363 Array<String> rollbackFiles;
364
365 if (FileSystem::glob(path, "*.rollback", rollbackFiles))
366 {
367 if (rollbackFiles.size() == 0)
368 return;
369 }
370
371 // Proceed to rollback logic.
372
373 if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
374 {
375 PEG_METHOD_EXIT();
376 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
377 MessageLoaderParms("Repository.DefaultRepository.ROLLBACK_FAILED",
378 "rollback failed"));
379 mike 1.1.2.1 }
380
381 if (!InstanceDataFile::rollbackTransaction(dataFilePath))
382 {
383 PEG_METHOD_EXIT();
384 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
385 MessageLoaderParms(
386 "Repository.DefaultRepository.ROLLBACK_FAILED",
387 "rollback failed"));
388 }
389
390 PEG_METHOD_EXIT();
391 }
392
393 ////////////////////////////////////////////////////////////////////////////////
394 //
395 // InstanceTransactionHandler
396 //
397 // This class is used to manage a repository instance transaction. The
398 // transaction is started when the class is instantiated, committed when
399 // the complete() method is called, and rolled back if the destructor is
400 mike 1.1.2.1 // called without a prior call to complete().
401 //
402 // The appropriate repository write locks must be owned while an
403 // InstanceTransactionHandler instance exists.
404 //
405 ////////////////////////////////////////////////////////////////////////////////
406
407 class InstanceTransactionHandler
408 {
409 public:
410 InstanceTransactionHandler(
411 const String& indexFilePath,
412 const String& dataFilePath)
413 : _indexFilePath(indexFilePath),
414 _dataFilePath(dataFilePath),
415 _isComplete(false)
416 {
417 _rollbackInstanceTransaction(_indexFilePath, _dataFilePath);
418 _beginInstanceTransaction(_indexFilePath, _dataFilePath);
419 }
420
421 mike 1.1.2.1 ~InstanceTransactionHandler()
422 {
423 if (!_isComplete)
424 {
425 _rollbackInstanceTransaction(_indexFilePath, _dataFilePath);
426 }
427 }
428
429 void complete()
430 {
431 _commitInstanceTransaction(_indexFilePath, _dataFilePath);
432 _isComplete = true;
433 }
434
435 private:
436 String _indexFilePath;
437 String _dataFilePath;
438 Boolean _isComplete;
439 };
440
441 ////////////////////////////////////////////////////////////////////////////////
442 mike 1.1.2.1 //
443 // DefaultRepository::_rollbackIncompleteTransactions()
444 //
445 // Searches for incomplete instance transactions for all classes in all
446 // namespaces. Restores instance index and data files to void an
447 // incomplete operation. If no incomplete instance transactions are
448 // outstanding, this method has no effect.
449 //
450 ////////////////////////////////////////////////////////////////////////////////
451
452 static Boolean _containsNoCase(const Array<String>& array, const String& str)
453 {
454 for (Uint32 i = 0; i < array.size(); i++)
455 {
456 if (String::equalNoCase(array[i], str))
457 return true;
458 }
459
460 return false;
461 }
462
463 mike 1.1.2.1 void DefaultRepository::_rollbackIncompleteTransactions()
464 {
465 PEG_METHOD_ENTER(TRC_REPOSITORY,
466 "DefaultRepository::_rollbackIncompleteTransactions");
467
468 WriteLock wlock(_lock);
469 AutoFileLock fileLock(_lockFile);
470
471 Array<CIMNamespaceName> namespaceNames;
472 _nameSpaceManager.getNameSpaceNames(namespaceNames);
473
474 for (Uint32 i = 0; i < namespaceNames.size(); i++)
475 {
476 // Form a list of .rollback files.
477
478 Array<String> rollbackFiles;
479 FileSystem::glob(
480 _nameSpaceManager.getInstanceDirRoot(namespaceNames[i]),
481 "*.rollback", rollbackFiles);
482
483 // Don't bother doing rollback if there are no rollback files.
484 mike 1.1.2.1 // The algorithm below is expensive.
485
486 if (rollbackFiles.size() == 0)
487 continue;
488
489 Array<CIMName> classNames;
490 _nameSpaceManager.getSubClassNames(
491 namespaceNames[i], CIMName(), true, classNames);
492
493 for (Uint32 j = 0; j < classNames.size(); j++)
494 {
495 //
496 // Get paths of index and data files:
497 //
498
499 String indexFilePath = _getInstanceIndexFilePath(
500 namespaceNames[i], classNames[j]);
501
502 String dataFilePath = _getInstanceDataFilePath(
503 namespaceNames[i], classNames[j]);
504
505 mike 1.1.2.1 // Only perform rollback processing if there is a rollback file
506 // for either the data or index file.
507
508 if (_containsNoCase(rollbackFiles, dataFilePath + ".rollback") ||
509 _containsNoCase(rollbackFiles, indexFilePath + ".rollback"))
510 {
511 //
512 // Attempt rollback (if there are no rollback files, this will
513 // have no effect). This code is here to rollback uncommitted
514 // changes left over from last time an instance-oriented
515 // function
516 // was called.
517 //
518
519 _rollbackInstanceTransaction(indexFilePath, dataFilePath);
520 }
521 }
522 }
523
524 PEG_METHOD_EXIT();
525 }
526 mike 1.1.2.1
527 ////////////////////////////////////////////////////////////////////////////////
528 //
529 // DefaultRepository
530 //
531 // The following are not implemented:
532 //
533 // DefaultRepository::execQuery()
534 // DefaultRepository::invokeMethod()
535 //
536 // Note that invokeMethod() will not never implemented since it is not
537 // meaningful for a repository.
538 //
539 ////////////////////////////////////////////////////////////////////////////////
540
541 DefaultRepository::DefaultRepository(
542 const String& repositoryRoot,
543 Uint32 mode)
544 :
545 Repository(repositoryRoot, mode),
546 _nameSpaceManager(repositoryRoot),
547 mike 1.1.2.1 _lock(),
548 _resolveInstance(true)
549 {
550 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::DefaultRepository");
551
552 Boolean binaryMode = mode & DefaultRepository::MODE_BIN;
553
554 if (mode == DefaultRepository::MODE_DEFAULT)
555 {
556 binaryMode = ConfigManager::parseBooleanValue(
557 ConfigManager::getInstance()->getCurrentValue(
558 "enableBinaryRepository"));
559 }
560
561 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY // PEP214
562 // FUTURE?? - compressMode = mode & DefaultRepository::MODE_COMPRESSED;
563 compressMode=1;
564
565 char* s = getenv("PEGASUS_ENABLE_COMPRESSED_REPOSITORY");
566 if (s && (strcmp(s, "build_non_compressed") == 0))
567 {
568 mike 1.1.2.1 compressMode =0;
569 #ifdef TEST_OUTPUT
570 cout << "In Compress mode: build_non_compresed found" << endl;
571 #endif /* TEST_OUTPUT */
572 }
573 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
574
575 #ifdef TEST_OUTPUT
576 cout << "repositoryRoot = " << repositoryRoot << endl;
577 cout << "DefaultRepository: binaryMode=" << binaryMode <<
578 ", mode=" << mode << endl;
579 cout << "DefaultRepository: compressMode= " << compressMode << endl;
580 #endif /* TEST_OUTPUT */
581
582 if (binaryMode>0)
583 {
584 // BUILD BINARY
585 streamer = new AutoStreamer(new BinaryStreamer(), BINREP_MARKER);
586 ((AutoStreamer*)streamer)->addReader(new XmlStreamer(), 0);
587 }
588 else
589 mike 1.1.2.1 {
590 // BUILD XML
591 streamer = new AutoStreamer(new XmlStreamer(),0xff);
592 ((AutoStreamer*)streamer)->addReader(
593 new BinaryStreamer(), BINREP_MARKER);
594 ((AutoStreamer*)streamer)->addReader(new XmlStreamer(), 0);
595 }
596
597 _context = new RepositoryDeclContext(this);
598
599 _isDefaultInstanceProvider = ConfigManager::parseBooleanValue(
600 ConfigManager::getInstance()->getCurrentValue(
601 "repositoryIsDefaultInstanceProvider"));
602
603 _lockFile = ConfigManager::getInstance()->getHomedPath(
604 PEGASUS_REPOSITORY_LOCK_FILE).getCString();
605
606 _rollbackIncompleteTransactions();
607
608 PEG_METHOD_EXIT();
609 }
610 mike 1.1.2.1
611 DefaultRepository::~DefaultRepository()
612 {
613 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::~DefaultRepository");
614
615 delete streamer;
616 delete _context;
617
618 AssocClassTable::removeCaches();
619
620 PEG_METHOD_EXIT();
621 }
622
623 String _toString(Boolean x)
624 {
625 return(x ? "true" : "false");
626 }
627
628 CIMClass DefaultRepository::getClass(
629 bool lock,
630 const CIMNamespaceName& nameSpace,
631 mike 1.1.2.1 const CIMName& className,
632 Boolean localOnly,
633 Boolean includeQualifiers,
634 Boolean includeClassOrigin,
635 const CIMPropertyList& propertyList)
636 {
637 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getClass");
638
639 ConditionalReadLock rlock(_lock, lock);
640
641 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "nameSpace= " +
642 nameSpace.getString() + ", className= " +
643 className.getString() +
644 ", localOnly= " + _toString(localOnly) +
645 ", includeQualifiers= " + _toString(includeQualifiers) +
646 ", includeClassOrigin= " + _toString(includeClassOrigin));
647 String classFilePath;
648 classFilePath = _nameSpaceManager.getClassFilePath(
649 nameSpace, className, NameSpaceRead);
650
651 CIMClass cimClass;
652 mike 1.1.2.1
653 try
654 {
655 #ifdef PEGASUS_USE_CLASS_CACHE
656
657 // Check the cache first:
658
659 if (!_classCache.get(classFilePath, cimClass))
660 {
661 // Not in cache so load from disk:
662
663 _LoadObject(classFilePath, cimClass, streamer);
664
665 // Put in cache:
666
667 _classCache.put(classFilePath, cimClass);
668 }
669
670 #else /* PEGASUS_USE_CLASS_CACHE */
671
672 _LoadObject(classFilePath, cimClass, streamer);
673 mike 1.1.2.1
674 #endif /* PEGASUS_USE_CLASS_CACHE */
675 }
676 catch (Exception&)
677 {
678 PEG_METHOD_EXIT();
679 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className.getString());
680 }
681
682 // Remove properties based on propertylist and localOnly flag (Bug 565)
683 Boolean propertyListNull = propertyList.isNull();
684
685 Filtering::filterClass(
686 cimClass,
687 localOnly,
688 includeQualifiers,
689 includeClassOrigin,
690 propertyList);
691
692 PEG_METHOD_EXIT();
693 return cimClass;
694 mike 1.1.2.1 }
695
696 Boolean DefaultRepository::_checkInstanceAlreadyExists(
697 const CIMNamespaceName& nameSpace,
698 const CIMObjectPath& instanceName) const
699 {
700 PEG_METHOD_ENTER(TRC_REPOSITORY,
701 "DefaultRepository::_checkInstanceAlreadyExists");
702
703 //
704 // Get the names of all superclasses and subclasses of this class
705 //
706
707 Array<CIMName> classNames;
708 CIMName className = instanceName.getClassName();
709 classNames.append(className);
710 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
711 _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
712
713 //
714 // Search for an instance with the specified key values
715 mike 1.1.2.1 //
716
717 for (Uint32 i = 0; i < classNames.size(); i++)
718 {
719 CIMObjectPath tmpInstanceName = instanceName;
720 tmpInstanceName.setClassName(classNames[i]);
721
722 String path = _getInstanceIndexFilePath(nameSpace, classNames[i]);
723
724 Uint32 index;
725 Uint32 size;
726 if (InstanceIndexFile::lookupEntry(path, tmpInstanceName, index, size))
727 {
728 PEG_METHOD_EXIT();
729 return true;
730 }
731 }
732
733 PEG_METHOD_EXIT();
734 return false;
735 }
736 mike 1.1.2.1
737 CIMInstance DefaultRepository::getInstance(
738 bool lock,
739 const CIMNamespaceName& nameSpace,
740 const CIMObjectPath& instanceName,
741 Boolean localOnly,
742 Boolean includeQualifiers,
743 Boolean includeClassOrigin,
744 const CIMPropertyList& propertyList)
745 {
746 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getInstance");
747
748 ConditionalReadLock rlock(_lock, lock);
749
750 //
751 // Validate namespace
752 //
753 if ((!instanceName.getNameSpace().isNull()) &&
754 (!instanceName.getNameSpace().equal(nameSpace)))
755 {
756 PEG_METHOD_EXIT();
757 mike 1.1.2.1 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND,
758 instanceName.toString());
759 }
760
761 if (!_nameSpaceManager.classExists(nameSpace, instanceName.getClassName()))
762 {
763 throw PEGASUS_CIM_EXCEPTION(
764 CIM_ERR_INVALID_CLASS, instanceName.getClassName().getString());
765 }
766
767 //
768 // Get paths of index and data files:
769 //
770
771 String indexFilePath = _getInstanceIndexFilePath(
772 nameSpace, instanceName.getClassName());
773
774 String dataFilePath = _getInstanceDataFilePath(
775 nameSpace, instanceName.getClassName());
776
777 //
778 mike 1.1.2.1 // Get the index for this instance:
779 //
780
781 Uint32 index;
782 Uint32 size;
783
784 if (!InstanceIndexFile::lookupEntry(
785 indexFilePath, instanceName, index, size))
786 {
787 PEG_METHOD_EXIT();
788 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
789 }
790
791 //
792 // Load the instance from file:
793 //
794
795 CIMInstance cimInstance;
796
797 if (!_loadInstance(dataFilePath, cimInstance, index, size))
798 {
799 mike 1.1.2.1 PEG_METHOD_EXIT();
800 throw CannotOpenFile(dataFilePath);
801 }
802
803 //
804 // Resolve the instance (if requested):
805 //
806
807 if (_resolveInstance)
808 {
809 CIMConstClass cimClass;
810 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
811 true);
812 }
813
814 Filtering::filterInstance(
815 cimInstance,
816 localOnly,
817 includeQualifiers,
818 includeClassOrigin,
819 propertyList);
820 mike 1.1.2.1
821
822 PEG_METHOD_EXIT();
823 return cimInstance;
824 }
825
826 void DefaultRepository::deleteClass(
827 bool lock,
828 const CIMNamespaceName& nameSpace,
829 const CIMName& className)
830 {
831 PEG_METHOD_ENTER(TRC_REPOSITORY,"DefaultRepository::deleteClass");
832
833 ConditionalWriteLock wlock(_lock, lock);
834 AutoFileLock fileLock(_lockFile);
835
836 //
837 // Get the class and check to see if it is an association class:
838 //
839
840 CIMClass cimClass = getClass(
841 mike 1.1.2.1 false, nameSpace, className, false, true, false, CIMPropertyList());
842 Boolean isAssociation = cimClass.isAssociation();
843
844 //
845 // Delete the class. The NameSpaceManager::deleteClass() method throws
846 // an exception if the class has subclasses.
847 //
848 #ifdef PEGASUS_USE_CLASS_CACHE
849
850 _classCache.evict(_nameSpaceManager.getClassFilePath(
851 nameSpace, className, NameSpaceRead));
852
853 #endif /* PEGASUS_USE_CLASS_CACHE */
854
855 _nameSpaceManager.deleteClass(nameSpace, className);
856
857 //
858 // Remove associations:
859 //
860
861 if (isAssociation)
862 mike 1.1.2.1 {
863 Array<String> assocFileName =
864 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceDelete);
865
866 if (FileSystem::exists(assocFileName[0]))
867 AssocClassTable::deleteAssociation(assocFileName[0], className);
868 }
869
870 PEG_METHOD_EXIT();
871 }
872
873 void _CompactInstanceRepository(
874 const String& indexFilePath,
875 const String& dataFilePath)
876 {
877 PEG_METHOD_ENTER(TRC_REPOSITORY,
878 "DefaultRepository::_CompactInstanceRepository");
879
880 //
881 // Compact the data file first:
882 //
883 mike 1.1.2.1
884 Array<Uint32> freeFlags;
885 Array<Uint32> indices;
886 Array<Uint32> sizes;
887 Array<CIMObjectPath> instanceNames;
888
889 if (!InstanceIndexFile::enumerateEntries(
890 indexFilePath, freeFlags, indices, sizes, instanceNames, true))
891 {
892 PEG_METHOD_EXIT();
893 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
894 MessageLoaderParms(
895 "Repository.DefaultRepository.INDEX_ENUM_ENTRIES_FAILED",
896 "Failed to obtain the entries from the Repository Instance"
897 " Index file."));
898 }
899
900 if (!InstanceDataFile::compact(dataFilePath, freeFlags, indices, sizes))
901 {
902 PEG_METHOD_EXIT();
903 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
904 mike 1.1.2.1 MessageLoaderParms(
905 "Repository.DefaultRepository.COMPACT_FAILED",
906 "Failed to compact the Repository Instance Data file."));
907 }
908
909 //
910 // Now compact the index file:
911 //
912
913 if (!InstanceIndexFile::compact(indexFilePath))
914 {
915 PEG_METHOD_EXIT();
916 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
917 MessageLoaderParms(
918 "Repository.DefaultRepository.INDEX_COMPACT_FAILED",
919 "Failed to compact the Repository Instance Index file."));
920 }
921
922 PEG_METHOD_EXIT();
923 }
924
925 mike 1.1.2.1 void DefaultRepository::deleteInstance(
926 bool lock,
927 const CIMNamespaceName& nameSpace,
928 const CIMObjectPath& instanceName)
929 {
930 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteInstance");
931
932 //
933 // Validate namespace
934 //
935 if ((!instanceName.getNameSpace().isNull()) &&
936 (!instanceName.getNameSpace().equal(nameSpace)))
937 {
938 PEG_METHOD_EXIT();
939 throw PEGASUS_CIM_EXCEPTION(
940 CIM_ERR_NOT_FOUND, instanceName.toString());
941 }
942
943 ConditionalWriteLock wlock(_lock, lock);
944 AutoFileLock fileLock(_lockFile);
945
946 mike 1.1.2.1 String errMessage;
947
948 //
949 // Get paths of index and data files:
950 //
951
952 String indexFilePath = _getInstanceIndexFilePath(
953 nameSpace, instanceName.getClassName());
954
955 String dataFilePath = _getInstanceDataFilePath(
956 nameSpace, instanceName.getClassName());
957
958 //
959 // Perform the operation in a transaction scope to enable rollback on
960 // failure.
961 //
962
963 InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
964
965 //
966 // Lookup instance from the index file (raise error if not found).
967 mike 1.1.2.1 //
968
969 Uint32 index;
970 Uint32 size;
971
972 if (!InstanceIndexFile::lookupEntry(
973 indexFilePath, instanceName, index, size))
974 {
975 PEG_METHOD_EXIT();
976 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
977 }
978
979 //
980 // Remove entry from index file.
981 //
982
983 Uint32 freeCount;
984
985 if (!InstanceIndexFile::deleteEntry(indexFilePath, instanceName, freeCount))
986 {
987 PEG_METHOD_EXIT();
988 mike 1.1.2.1 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
989 MessageLoaderParms(
990 "Repository.DefaultRepository.FAILED_TO_DELETE_INSTANCE",
991 "Failed to delete instance: $0",
992 instanceName.toString()));
993 }
994
995 transaction.complete();
996
997 //
998 // Compact the index and data files if the free count max was
999 // reached.
1000 //
1001
1002 if (freeCount == _MAX_FREE_COUNT)
1003 _CompactInstanceRepository(indexFilePath, dataFilePath);
1004
1005 //
1006 // Delete from assocation table (if an assocation).
1007 //
1008
1009 mike 1.1.2.1 String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);
1010
1011 if (FileSystem::exists(assocFileName))
1012 AssocInstTable::deleteAssociation(assocFileName, instanceName);
1013
1014 PEG_METHOD_EXIT();
1015 }
1016
1017 void DefaultRepository::_createAssocClassEntries(
1018 const CIMNamespaceName& nameSpace,
1019 const CIMConstClass& assocClass)
1020 {
1021 PEG_METHOD_ENTER(
1022 TRC_REPOSITORY, "DefaultRepository::_createAssocClassEntries");
1023
1024 // Open input file:
1025
1026
1027 Array<String> assocFileName =
1028 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceWrite);
1029 ofstream os;
1030 mike 1.1.2.1
1031 if (!OpenAppend(os, assocFileName[0]))
1032 {
1033 PEG_METHOD_EXIT();
1034 throw CannotOpenFile(assocFileName[0]);
1035 }
1036
1037 // Get the association's class name:
1038
1039 CIMName assocClassName = assocClass.getClassName();
1040
1041 // For each property:
1042
1043 Uint32 n = assocClass.getPropertyCount();
1044
1045 for (Uint32 i = 0; i < n; i++)
1046 {
1047 CIMConstProperty fromProp = assocClass.getProperty(i);
1048
1049 if (fromProp.getType() == CIMTYPE_REFERENCE)
1050 {
1051 mike 1.1.2.1 for (Uint32 j = 0; j < n; j++)
1052 {
1053 CIMConstProperty toProp = assocClass.getProperty(j);
1054
1055 if (toProp.getType() == CIMTYPE_REFERENCE &&
1056 (!fromProp.getName().equal (toProp.getName())))
1057 {
1058 CIMName fromClassName = fromProp.getReferenceClassName();
1059 CIMName fromPropertyName = fromProp.getName();
1060 CIMName toClassName = toProp.getReferenceClassName();
1061 CIMName toPropertyName = toProp.getName();
1062
1063 AssocClassTable::append(
1064 os,
1065 assocFileName[0],
1066 assocClassName,
1067 fromClassName,
1068 fromPropertyName,
1069 toClassName,
1070 toPropertyName);
1071 }
1072 mike 1.1.2.1 }
1073 }
1074 }
1075
1076 PEG_METHOD_EXIT();
1077 }
1078
1079 void DefaultRepository::createClass(
1080 bool lock,
1081 const CIMNamespaceName& nameSpace,
1082 const CIMClass& newClass,
1083 const ContentLanguageList& contentLangs)
1084 {
1085 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::createClass");
1086
1087 ConditionalWriteLock wlock(_lock, lock);
1088 AutoFileLock fileLock(_lockFile);
1089
1090 // -- Resolve the class:
1091 CIMClass cimClass(newClass);
1092
1093 mike 1.1.2.1 Resolver::resolveClass (cimClass, _context, nameSpace);
1094
1095 // -- If an association, populate associations file:
1096
1097 if (cimClass.isAssociation())
1098 _createAssocClassEntries(nameSpace, cimClass);
1099
1100 // -- Create namespace manager entry:
1101
1102 String classFilePath;
1103
1104 _nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),
1105 cimClass.getSuperClassName(), classFilePath);
1106
1107 // -- Create the class file:
1108
1109 Buffer classXml;
1110 streamer->encode(classXml, cimClass);
1111 //XmlWriter::appendClassElement(classXml, cimClass);
1112 _SaveObject(classFilePath, classXml,streamer);
1113
1114 mike 1.1.2.1
1115 PEG_METHOD_EXIT();
1116 }
1117
1118 /*------------------------------------------------------------------------------
1119
1120 This routine does the following:
1121
1122 1. Creates two entries in the association file for each relationship
1123 formed by this new assocation instance. A binary association
1124 (one with two references) ties two instances together. Suppose
1125 there are two instances: I1 and I2. Then two entries are created:
1126
1127 I2 -> I1
1128 I1 -> I2
1129
1130 For a ternary relationship, six entries will be created. Suppose
1131 there are three instances: I1, I2, and I3:
1132
1133 I1 -> I2
1134 I1 -> I3
1135 mike 1.1.2.1 I2 -> I1
1136 I2 -> I3
1137 I3 -> I1
1138 I3 -> I2
1139
1140 So for an N-ary relationship, there will be 2*N entries created.
1141
1142 2. Verifies that the association instance refers to real objects.
1143 (note that an association reference may refer to either an instance
1144 or a class). Throws an exception if one of the references does not
1145 refer to a valid object.
1146
1147 ------------------------------------------------------------------------------*/
1148
1149
1150 void DefaultRepository::_createAssocInstEntries(
1151 const CIMNamespaceName& nameSpace,
1152 const CIMConstClass& cimClass,
1153 const CIMInstance& cimInstance,
1154 const CIMObjectPath& instanceName)
1155 {
1156 mike 1.1.2.1 PEG_METHOD_ENTER(
1157 TRC_REPOSITORY, "DefaultRepository::_createAssocInstEntries");
1158
1159 // Open input file:
1160
1161 String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);
1162 ofstream os;
1163
1164 if (!OpenAppend(os, assocFileName))
1165 {
1166 PEG_METHOD_EXIT();
1167 throw CannotOpenFile(assocFileName);
1168 }
1169
1170 // Get the association's instance name and class name:
1171
1172 String assocInstanceName = instanceName.toString();
1173 CIMName assocClassName = instanceName.getClassName();
1174
1175 // For each property:
1176
1177 mike 1.1.2.1 for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
1178 {
1179 CIMConstProperty fromProp = cimInstance.getProperty(i);
1180
1181 // If a reference property:
1182
1183 if (fromProp.getType() == CIMTYPE_REFERENCE)
1184 {
1185 // For each property:
1186
1187 for (Uint32 j = 0, n = cimInstance.getPropertyCount(); j < n; j++)
1188 {
1189 CIMConstProperty toProp = cimInstance.getProperty(j);
1190
1191 // If a reference property and not the same property:
1192
1193 if (toProp.getType() == CIMTYPE_REFERENCE &&
1194 (!fromProp.getName().equal (toProp.getName())))
1195 {
1196 CIMObjectPath fromRef;
1197 fromProp.getValue().get(fromRef);
1198 mike 1.1.2.1
1199 CIMObjectPath toRef;
1200 toProp.getValue().get(toRef);
1201
1202
1203 // Fix for bugzilla 667:
1204 // Strip off the hostname if it is the same as the
1205 // local host
1206 if ((fromRef.getHost() != String::EMPTY) &&
1207 (System::isLocalHost(fromRef.getHost())))
1208 {
1209 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1210 "_createAssocInstEntries() - Stripping off local "
1211 "hostName from fromRef");
1212 fromRef.setHost(String::EMPTY);
1213 }
1214
1215 // Strip off the namespace when it is the same as the
1216 // one this instance is created in.
1217 if ((fromRef.getHost() == String::EMPTY) &&
1218 (fromRef.getNameSpace() == nameSpace))
1219 mike 1.1.2.1 {
1220 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1221 "_createAssocInstEntries() - Stripping off "
1222 "local nameSpace from fromRef");
1223 fromRef.setNameSpace(CIMNamespaceName());
1224 }
1225
1226 // Strip off the hostname if it is the same as the
1227 // local host
1228 if ((toRef.getHost() != String::EMPTY) &&
1229 (System::isLocalHost(toRef.getHost())))
1230 {
1231 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1232 "_createAssocInstEntries() - Stripping off "
1233 "local hostName from toRef");
1234 toRef.setHost(String::EMPTY);
1235 }
1236
1237 // Strip off the namespace when it is the same as the
1238 // one this instance is created in.
1239 if ((toRef.getHost() == String::EMPTY) &&
1240 mike 1.1.2.1 (toRef.getNameSpace() == nameSpace))
1241 {
1242 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1243 "_createAssocInstEntries() - Stripping off "
1244 "local nameSpace from toRef");
1245 toRef.setNameSpace(CIMNamespaceName());
1246 }
1247
1248
1249 String fromObjectName = fromRef.toString();
1250 CIMName fromClassName = fromRef.getClassName();
1251 CIMName fromPropertyName = fromProp.getName();
1252 String toObjectName = toRef.toString();
1253 CIMName toClassName = toRef.getClassName();
1254 CIMName toPropertyName = toProp.getName();
1255
1256 AssocInstTable::append(
1257 os,
1258 assocInstanceName,
1259 assocClassName,
1260 fromObjectName,
1261 mike 1.1.2.1 fromClassName,
1262 fromPropertyName,
1263 toObjectName,
1264 toClassName,
1265 toPropertyName);
1266 }
1267 }
1268 }
1269 }
1270
1271 PEG_METHOD_EXIT();
1272 }
1273
1274 CIMObjectPath DefaultRepository::createInstance(
1275 bool lock,
1276 const CIMNamespaceName& nameSpace,
1277 const CIMInstance& newInstance,
1278 const ContentLanguageList& contentLangs)
1279 {
1280 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::createInstance");
1281
1282 mike 1.1.2.1 ConditionalWriteLock wlock(_lock, lock);
1283 AutoFileLock fileLock(_lockFile);
1284
1285 String errMessage;
1286
1287 //
1288 // Resolve the instance. Looks up class and fills out properties but
1289 // not the qualifiers.
1290 //
1291
1292 CIMInstance cimInstance(newInstance);
1293 CIMConstClass cimClass;
1294 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1295 false);
1296 CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
1297
1298 //
1299 // Make sure the class has keys (otherwise it will be impossible to
1300 // create the instance).
1301 //
1302
1303 mike 1.1.2.1 if (!cimClass.hasKeys())
1304 {
1305 PEG_METHOD_EXIT();
1306 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1307 MessageLoaderParms("Repository.DefaultRepository.CLASS_HAS_NO_KEYS",
1308 "class has no keys: $0",
1309 cimClass.getClassName().getString()));
1310 }
1311
1312 //
1313 // Be sure instance does not already exist:
1314 //
1315
1316 if (_checkInstanceAlreadyExists(nameSpace, instanceName))
1317 {
1318 PEG_METHOD_EXIT();
1319 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,
1320 instanceName.toString());
1321 }
1322
1323 //
1324 mike 1.1.2.1 // Create association entries if an association instance.
1325 //
1326
1327 if (cimClass.isAssociation())
1328 _createAssocInstEntries(nameSpace, cimClass, cimInstance, instanceName);
1329
1330 //
1331 // Get paths to data and index files:
1332 //
1333
1334 String indexFilePath = _getInstanceIndexFilePath(
1335 nameSpace, newInstance.getClassName());
1336
1337 String dataFilePath = _getInstanceDataFilePath(
1338 nameSpace, newInstance.getClassName());
1339
1340 //
1341 // Perform the operation in a transaction scope to enable rollback on
1342 // failure.
1343 //
1344
1345 mike 1.1.2.1 InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
1346
1347 //
1348 // Save instance to file:
1349 //
1350
1351 Uint32 index;
1352 Uint32 size;
1353
1354 {
1355 Buffer data;
1356 streamer->encode(data, cimInstance);
1357 size = data.size();
1358
1359 if (!InstanceDataFile::appendInstance(dataFilePath, data, index))
1360 {
1361 PEG_METHOD_EXIT();
1362 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1363 MessageLoaderParms(
1364 "Repository.DefaultRepository.FAILED_TO_CREATE_INSTANCE",
1365 "Failed to create instance: $0",
1366 mike 1.1.2.1 instanceName.toString()));
1367 }
1368 }
1369
1370 //
1371 // Create entry in index file:
1372 //
1373
1374 if (!InstanceIndexFile::createEntry(
1375 indexFilePath, instanceName, index, size))
1376 {
1377 PEG_METHOD_EXIT();
1378 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1379 MessageLoaderParms(
1380 "Repository.DefaultRepository.FAILED_TO_CREATE_INSTANCE",
1381 "Failed to create instance: $0",
1382 instanceName.toString()));
1383 }
1384
1385 transaction.complete();
1386
1387 mike 1.1.2.1 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1388 true);
1389
1390
1391 PEG_METHOD_EXIT();
1392 return instanceName;
1393 }
1394
1395 void DefaultRepository::modifyClass(
1396 bool lock,
1397 const CIMNamespaceName& nameSpace,
1398 const CIMClass& modifiedClass,
1399 const ContentLanguageList& contentLangs)
1400 {
1401 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::modifyClass");
1402
1403 ConditionalWriteLock wlock(_lock, lock);
1404 AutoFileLock fileLock(_lockFile);
1405
1406 //
1407 // Resolve the class:
1408 mike 1.1.2.1 //
1409
1410 CIMClass cimClass(modifiedClass);
1411 Resolver::resolveClass (cimClass, _context, nameSpace);
1412
1413 //
1414 // Check to see if it is okay to modify this class:
1415 //
1416
1417 String classFilePath;
1418
1419 _nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(),
1420 cimClass.getSuperClassName(), classFilePath);
1421
1422 //
1423 // ATTN: KS
1424 // Disallow modification of classes which have instances (that are
1425 // in the repository). And we have no idea whether the class has
1426 // instances in other repositories or in providers. We should do
1427 // an enumerate instance names at a higher level (above the repository).
1428 //
1429 mike 1.1.2.1
1430 #ifdef PEGASUS_USE_CLASS_CACHE
1431
1432 _classCache.evict(classFilePath);
1433
1434 #endif /* PEGASUS_USE_CLASS_CACHE */
1435
1436 //
1437 // Delete the old file containing the class:
1438 //
1439
1440 if (!FileSystem::removeFileNoCase(classFilePath))
1441 {
1442 PEG_METHOD_EXIT();
1443 String str = "DefaultRepository::modifyClass()";
1444 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1445 MessageLoaderParms(
1446 "Repository.DefaultRepository.FAILED_TO_REMOVE_FILE",
1447 "failed to remove file in $0", str));
1448 }
1449
1450 mike 1.1.2.1 //
1451 // Create new class file:
1452 //
1453
1454 Buffer classXml;
1455 streamer->encode(classXml, cimClass);
1456 //XmlWriter::appendClassElement(classXml, cimClass);
1457 _SaveObject(classFilePath, classXml,streamer);
1458
1459 if (cimClass.isAssociation())
1460 {
1461 // Remove from Association
1462 Array<String> assocFileName =
1463 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceDelete);
1464 if (FileSystem::exists(assocFileName[0]))
1465 {
1466 AssocClassTable::deleteAssociation(
1467 assocFileName[0], cimClass.getClassName());
1468 // Create the association again.
1469 _createAssocClassEntries(nameSpace, cimClass);
1470 }
1471 mike 1.1.2.1 else
1472 {
1473 PEG_METHOD_EXIT();
1474 throw CannotOpenFile(assocFileName[0]);
1475 }
1476 }
1477
1478
1479 //
1480 // Cache this class:
1481 //
1482
1483 #ifdef PEGASUS_USE_CLASS_CACHE
1484
1485 _classCache.put(classFilePath, cimClass);
1486
1487 #endif /* PEGASUS_USE_CLASS_CACHE */
1488
1489 PEG_METHOD_EXIT();
1490 }
1491
1492 mike 1.1.2.1 void DefaultRepository::modifyInstance(
1493 bool lock,
1494 const CIMNamespaceName& nameSpace,
1495 const CIMInstance& modifiedInstance,
1496 Boolean includeQualifiers,
1497 const CIMPropertyList& propertyList,
1498 const ContentLanguageList& contentLangs)
1499 {
1500 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::modifyInstance");
1501
1502 ConditionalWriteLock wlock(_lock, lock);
1503 AutoFileLock fileLock(_lockFile);
1504
1505 //
1506 // Do this:
1507 //
1508
1509 String errMessage;
1510 CIMInstance cimInstance; // The instance that replaces the original
1511
1512 if (propertyList.isNull())
1513 mike 1.1.2.1 {
1514 //
1515 // Replace all the properties in the instance
1516 //
1517 if (includeQualifiers)
1518 {
1519 //
1520 // Replace the entire instance with the given instance
1521 // (this is the default behavior)
1522 //
1523 cimInstance = modifiedInstance;
1524 }
1525 else
1526 {
1527 //
1528 // Replace all the properties in the instance, but keep the
1529 // original qualifiers on the instance and on the properties
1530 //
1531
1532 _resolveInstance = false;
1533
1534 mike 1.1.2.1 cimInstance = getInstance(
1535 false,
1536 nameSpace,
1537 modifiedInstance.getPath (),
1538 false,
1539 true,
1540 true,
1541 CIMPropertyList());
1542
1543 _resolveInstance = true;
1544
1545 CIMInstance newInstance(
1546 modifiedInstance.getPath ().getClassName());
1547
1548 CIMInstance givenInstance = modifiedInstance;
1549
1550 //
1551 // Copy over the original instance qualifiers
1552 //
1553
1554 for (Uint32 i = 0; i < cimInstance.getQualifierCount(); i++)
1555 mike 1.1.2.1 {
1556 newInstance.addQualifier(cimInstance.getQualifier(i));
1557 }
1558
1559 //
1560 // Loop through the properties replacing each property in the
1561 // original with a new value, but keeping the original qualifiers
1562 //
1563 for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
1564 {
1565 // Copy the given property value (not qualifiers)
1566 CIMProperty givenProperty = givenInstance.getProperty(i);
1567 CIMProperty newProperty(
1568 givenProperty.getName(),
1569 givenProperty.getValue(),
1570 givenProperty.getArraySize(),
1571 givenProperty.getReferenceClassName(),
1572 givenProperty.getClassOrigin(),
1573 givenProperty.getPropagated());
1574
1575 // Copy the original property qualifiers
1576 mike 1.1.2.1 Uint32 origPos =
1577 cimInstance.findProperty(newProperty.getName());
1578 if (origPos != PEG_NOT_FOUND)
1579 {
1580 CIMProperty origProperty = cimInstance.getProperty(origPos);
1581 for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
1582 {
1583 newProperty.addQualifier(origProperty.getQualifier(j));
1584 }
1585 }
1586
1587 // Add the newly constructed property to the new instance
1588 newInstance.addProperty(newProperty);
1589 }
1590
1591 // Use the newly merged instance to replace the original instance
1592 cimInstance = newInstance;
1593 }
1594 }
1595 else
1596 {
1597 mike 1.1.2.1 //
1598 // Replace only the properties specified in the given instance
1599 //
1600
1601 _resolveInstance = false;
1602
1603 cimInstance = getInstance(false, nameSpace,
1604 modifiedInstance.getPath (), false, true, true, CIMPropertyList());
1605
1606 _resolveInstance = true;
1607
1608 CIMInstance givenInstance = modifiedInstance;
1609
1610 // NOTE: Instance qualifiers are not changed when a property list
1611 // is specified. Property qualifiers are replaced with the
1612 // corresponding property values.
1613
1614 //
1615 // Loop through the propertyList replacing each property in the original
1616 //
1617
1618 mike 1.1.2.1 for (Uint32 i=0; i<propertyList.size(); i++)
1619 {
1620 Uint32 origPropPos = cimInstance.findProperty(propertyList[i]);
1621 if (origPropPos != PEG_NOT_FOUND)
1622 {
1623 // Case: Property set in original
1624 CIMProperty origProperty =
1625 cimInstance.getProperty(origPropPos);
1626
1627 // Get the given property value
1628 Uint32 givenPropPos =
1629 givenInstance.findProperty(propertyList[i]);
1630 if (givenPropPos != PEG_NOT_FOUND)
1631 {
1632 // Case: Property set in original and given
1633 CIMProperty givenProperty =
1634 givenInstance.getProperty(givenPropPos);
1635
1636 // Copy over the property from the given to the original
1637 if (includeQualifiers)
1638 {
1639 mike 1.1.2.1 // Case: Total property replacement
1640 cimInstance.removeProperty(origPropPos);
1641 cimInstance.addProperty(givenProperty);
1642 }
1643 else
1644 {
1645 // Case: Replace only the property value (not quals)
1646 origProperty.setValue(givenProperty.getValue());
1647 cimInstance.removeProperty(origPropPos);
1648 cimInstance.addProperty(origProperty);
1649 }
1650 }
1651 else
1652 {
1653 // Case: Property set in original and not in given
1654 // Just remove the property (set to null)
1655 cimInstance.removeProperty(origPropPos);
1656 }
1657 }
1658 else
1659 {
1660 mike 1.1.2.1 // Case: Property not set in original
1661
1662 // Get the given property value
1663 Uint32 givenPropPos =
1664 givenInstance.findProperty(propertyList[i]);
1665 if (givenPropPos != PEG_NOT_FOUND)
1666 {
1667 // Case: Property set in given and not in original
1668 CIMProperty givenProperty =
1669 givenInstance.getProperty(givenPropPos);
1670
1671 // Copy over the property from the given to the original
1672 if (includeQualifiers)
1673 {
1674 // Case: Total property copy
1675 cimInstance.addProperty(givenProperty);
1676 }
1677 else
1678 {
1679 // Case: Copy only the property value (not qualifiers)
1680 CIMProperty newProperty(
1681 mike 1.1.2.1 givenProperty.getName(),
1682 givenProperty.getValue(),
1683 givenProperty.getArraySize(),
1684 givenProperty.getReferenceClassName(),
1685 givenProperty.getClassOrigin(),
1686 givenProperty.getPropagated());
1687 cimInstance.addProperty(newProperty);
1688 }
1689 }
1690 else
1691 {
1692 // Case: Property not set in original or in given
1693
1694 // Nothing to do; just make sure the property name is valid
1695 // ATTN: This is not the most efficient solution
1696
1697 CIMClass cimClass = getClass(
1698 false,
1699 nameSpace,
1700 cimInstance.getClassName(),
1701 false,
1702 mike 1.1.2.1 true,
1703 false,
1704 CIMPropertyList());
1705
1706 if (cimClass.findProperty(propertyList[i]) == PEG_NOT_FOUND)
1707 {
1708 // ATTN: This exception may be returned by setProperty
1709 PEG_METHOD_EXIT();
1710 throw PEGASUS_CIM_EXCEPTION(
1711 CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
1712 }
1713 }
1714 }
1715 }
1716 }
1717
1718 //
1719 // Resolve the instance (do not propagate qualifiers from class since
1720 // this will bloat the instance).
1721 //
1722
1723 mike 1.1.2.1 CIMConstClass cimClass;
1724 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1725 false);
1726
1727 CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
1728
1729 //
1730 // Disallow operation if the instance name was changed:
1731 //
1732
1733 // For bugzilla 1508. Hostname and namespace are not included
1734 // in the comparison here.
1735 CIMObjectPath modifiedInstancePath = modifiedInstance.getPath();
1736 modifiedInstancePath.setNameSpace(CIMNamespaceName());
1737 modifiedInstancePath.setHost(String::EMPTY);
1738 if (instanceName != modifiedInstancePath)
1739 {
1740 PEG_METHOD_EXIT();
1741 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1742 MessageLoaderParms(
1743 "Repository.DefaultRepository.ATTEMPT_TO_MODIFY_KEY_PROPERTY",
1744 mike 1.1.2.1 "Attempted to modify a key property"));
1745 }
1746
1747 //
1748 // Get paths of index and data files:
1749 //
1750
1751 String indexFilePath = _getInstanceIndexFilePath(
1752 nameSpace, modifiedInstance.getClassName());
1753
1754 String dataFilePath = _getInstanceDataFilePath(
1755 nameSpace, modifiedInstance.getClassName());
1756
1757 //
1758 // Look up the specified instance
1759 //
1760
1761 Uint32 oldSize;
1762 Uint32 oldIndex;
1763 Uint32 newSize;
1764 Uint32 newIndex;
1765 mike 1.1.2.1
1766 if (!InstanceIndexFile::lookupEntry(
1767 indexFilePath, instanceName, oldIndex, oldSize))
1768 {
1769 PEG_METHOD_EXIT();
1770 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
1771 }
1772
1773 //
1774 // Perform the operation in a transaction scope to enable rollback on
1775 // failure.
1776 //
1777
1778 InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
1779
1780 //
1781 // Modify the data file:
1782 //
1783
1784 {
1785 Buffer out;
1786 mike 1.1.2.1 streamer->encode(out, cimInstance);
1787 //XmlWriter::appendInstanceElement(out, cimInstance);
1788
1789 newSize = out.size();
1790
1791 if (!InstanceDataFile::appendInstance(dataFilePath, out, newIndex))
1792 {
1793 PEG_METHOD_EXIT();
1794 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1795 MessageLoaderParms(
1796 "Repository.DefaultRepository.FAILED_TO_MODIFY_INSTANCE",
1797 "Failed to modify instance $0",
1798 instanceName.toString()));
1799 }
1800 }
1801
1802 //
1803 // Modify the index file:
1804 //
1805
1806 Uint32 freeCount;
1807 mike 1.1.2.1
1808 if (!InstanceIndexFile::modifyEntry(indexFilePath, instanceName, newIndex,
1809 newSize, freeCount))
1810 {
1811 PEG_METHOD_EXIT();
1812 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1813 MessageLoaderParms(
1814 "Repository.DefaultRepository.FAILED_TO_MODIFY_INSTANCE",
1815 "Failed to modify instance $0",
1816 instanceName.toString()));
1817 }
1818
1819 transaction.complete();
1820
1821 //
1822 // Compact the index and data files if the free count max was
1823 // reached.
1824 //
1825
1826 if (freeCount == _MAX_FREE_COUNT)
1827 _CompactInstanceRepository(indexFilePath, dataFilePath);
1828 mike 1.1.2.1
1829 //
1830 // Resolve the instance:
1831 //
1832
1833 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1834 true);
1835
1836 PEG_METHOD_EXIT();
1837 }
1838
1839 Array<CIMClass> DefaultRepository::enumerateClasses(
1840 bool lock,
1841 const CIMNamespaceName& nameSpace,
1842 const CIMName& className,
1843 Boolean deepInheritance,
1844 Boolean localOnly,
1845 Boolean includeQualifiers,
1846 Boolean includeClassOrigin)
1847 {
1848 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateClasses");
1849 mike 1.1.2.1
1850 ConditionalReadLock rlock(_lock, lock);
1851
1852 Array<CIMName> classNames;
1853
1854 _nameSpaceManager.getSubClassNames(
1855 nameSpace, className, deepInheritance, classNames);
1856
1857 Array<CIMClass> result;
1858
1859 for (Uint32 i = 0; i < classNames.size(); i++)
1860 {
1861 result.append(getClass(false, nameSpace, classNames[i], localOnly,
1862 includeQualifiers, includeClassOrigin, CIMPropertyList()));
1863 }
1864
1865 PEG_METHOD_EXIT();
1866 return result;
1867 }
1868
1869 Array<CIMName> DefaultRepository::enumerateClassNames(
1870 mike 1.1.2.1 bool lock,
1871 const CIMNamespaceName& nameSpace,
1872 const CIMName& className,
1873 Boolean deepInheritance)
1874 {
1875 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateClassNames");
1876
1877 ConditionalReadLock rlock(_lock, lock);
1878
1879 Array<CIMName> classNames;
1880
1881 _nameSpaceManager.getSubClassNames(
1882 nameSpace, className, deepInheritance, classNames,true);
1883
1884 PEG_METHOD_EXIT();
1885 return classNames;
1886 }
1887
1888 Boolean DefaultRepository::_loadAllInstances(
1889 const CIMNamespaceName& nameSpace,
1890 const CIMName& className,
1891 mike 1.1.2.1 Array<CIMInstance>& namedInstances)
1892 {
1893 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_loadAllInstances");
1894
1895 Array<CIMObjectPath> instanceNames;
1896 Buffer data;
1897 Array<Uint32> indices;
1898 Array<Uint32> sizes;
1899
1900 //
1901 // Form the names of the instance index and data files
1902 //
1903
1904 String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
1905 String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
1906
1907 //
1908 // Enumerate the index file:
1909 //
1910
1911 Array<Uint32> freeFlags;
1912 mike 1.1.2.1
1913 if (!InstanceIndexFile::enumerateEntries(
1914 indexFilePath, freeFlags, indices, sizes, instanceNames, true))
1915 {
1916 PEG_METHOD_EXIT();
1917 return false;
1918 }
1919
1920 //
1921 // Form the array of instances result:
1922 //
1923
1924 if (instanceNames.size() > 0)
1925 {
1926 //
1927 // Load all instances from the data file:
1928 //
1929
1930 if (!InstanceDataFile::loadAllInstances(dataFilePath, data))
1931 {
1932 PEG_METHOD_EXIT();
1933 mike 1.1.2.1 return false;
1934 }
1935
1936 //
1937 // for each instance loaded, call XML parser to parse the XML
1938 // data and create a CIMInstance object.
1939 //
1940
1941 CIMInstance tmpInstance;
1942
1943 Uint32 bufferSize = data.size();
1944 char* buffer = (char*)data.getData();
1945
1946 for (Uint32 i = 0; i < instanceNames.size(); i++)
1947 {
1948 if (!freeFlags[i])
1949 {
1950 Uint32 pos= (Uint32)((&(buffer[indices[i]]))-buffer);
1951 streamer->decode(data, pos, tmpInstance);
1952
1953 Resolver::resolveInstance (tmpInstance, _context, nameSpace,
1954 mike 1.1.2.1 true);
1955 tmpInstance.setPath (instanceNames[i]);
1956
1957 namedInstances.append (tmpInstance);
1958 }
1959 }
1960 }
1961
1962 PEG_METHOD_EXIT();
1963 return true;
1964 }
1965
1966 Array<CIMInstance> DefaultRepository::enumerateInstancesForSubtree(
1967 bool lock,
1968 const CIMNamespaceName& nameSpace,
1969 const CIMName& className,
1970 Boolean deepInheritance,
1971 Boolean localOnly,
1972 Boolean includeQualifiers,
1973 Boolean includeClassOrigin,
1974 const CIMPropertyList& propertyList)
1975 mike 1.1.2.1 {
1976 PEG_METHOD_ENTER(TRC_REPOSITORY,
1977 "DefaultRepository::enumerateInstancesForSubtree");
1978
1979 // It is not necessary to control access to the ReadWriteSem _lock here.
1980 // This method calls enumerateInstancesForClass, which does its own
1981 // access control.
1982
1983 //
1984 // Get all descendent classes of this class:
1985 //
1986
1987 Array<CIMName> classNames;
1988 classNames.append(className);
1989 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
1990
1991 //
1992 // Get all instances for this class and all its descendent classes
1993 //
1994
1995 Array<CIMInstance> namedInstances;
1996 mike 1.1.2.1
1997 for (Uint32 i = 0; i < classNames.size(); i++)
1998 {
1999 Array<CIMInstance> localNamedInstances =
2000 enumerateInstancesForClass(true, nameSpace, classNames[i],
2001 false, includeQualifiers, includeClassOrigin, propertyList);
2002
2003 // ATTN: Handles everything but deepInheritance.
2004 for (Uint32 i = 0 ; i < localNamedInstances.size(); i++)
2005 {
2006 Filtering::filterInstance(localNamedInstances[i],
2007 localOnly,
2008 includeQualifiers,
2009 includeClassOrigin,
2010 propertyList);
2011 }
2012 namedInstances.appendArray(localNamedInstances);
2013 }
2014
2015 PEG_METHOD_EXIT();
2016 return namedInstances;
2017 mike 1.1.2.1 }
2018
2019 Array<CIMInstance> DefaultRepository::enumerateInstancesForClass(
2020 bool lock,
2021 const CIMNamespaceName& nameSpace,
2022 const CIMName& className,
2023 Boolean localOnly,
2024 Boolean includeQualifiers,
2025 Boolean includeClassOrigin,
2026 const CIMPropertyList& propertyList)
2027 {
2028 PEG_METHOD_ENTER(TRC_REPOSITORY,
2029 "DefaultRepository::enumerateInstancesForClass");
2030
2031 ConditionalReadLock rlock(_lock, lock);
2032
2033 //
2034 // Get all instances for this class
2035 //
2036
2037 Array<CIMInstance> namedInstances;
2038 mike 1.1.2.1
2039 if (!_loadAllInstances(nameSpace, className, namedInstances))
2040 {
2041 PEG_METHOD_EXIT();
2042 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2043 MessageLoaderParms(
2044 "Repository.DefaultRepository.FAILED_TO_LOAD_INSTANCES",
2045 "Failed to load instances in class $0",
2046 className.getString()));
2047 }
2048
2049 // Do any required filtering of properties, qualifiers, classorigin
2050 // on the returned instances.
2051 for (Uint32 i = 0 ; i < namedInstances.size(); i++)
2052 {
2053 Filtering::filterInstance(namedInstances[i],
2054 localOnly,
2055 includeQualifiers,
2056 includeClassOrigin,
2057 propertyList);
2058 }
2059 mike 1.1.2.1
2060 PEG_METHOD_EXIT();
2061 return namedInstances;
2062 }
2063
2064 Array<CIMObjectPath> DefaultRepository::enumerateInstanceNamesForSubtree(
2065 bool lock,
2066 const CIMNamespaceName& nameSpace,
2067 const CIMName& className)
2068 {
2069 PEG_METHOD_ENTER(TRC_REPOSITORY,
2070 "DefaultRepository::enumerateInstanceNamesForSubtree");
2071
2072 // It is not necessary to control access to the ReadWriteSem _lock here.
2073 // This method calls enumerateInstanceNamesForClass, which does its own
2074 // access control.
2075
2076 //
2077 // Get names of descendent classes:
2078 //
2079
2080 mike 1.1.2.1 Array<CIMName> classNames;
2081 classNames.append(className);
2082 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
2083
2084 //
2085 // Enumerate instance names for each of the subclasses
2086 //
2087 Array<CIMObjectPath> instanceNames;
2088
2089 for (Uint32 i = 0; i < classNames.size(); i++)
2090 {
2091 instanceNames.appendArray(
2092 enumerateInstanceNamesForClass(true, nameSpace, classNames[i]));
2093 }
2094
2095 PEG_METHOD_EXIT();
2096 return instanceNames;
2097 }
2098
2099 Array<CIMObjectPath> DefaultRepository::enumerateInstanceNamesForClass(
2100 bool lock,
2101 mike 1.1.2.1 const CIMNamespaceName& nameSpace,
2102 const CIMName& className)
2103 {
2104 PEG_METHOD_ENTER(TRC_REPOSITORY,
2105 "DefaultRepository::enumerateInstanceNamesForClass");
2106
2107 ConditionalReadLock rlock(_lock, lock);
2108
2109 //
2110 // Get instance names from the instance index file for the class:
2111 //
2112 Array<CIMObjectPath> instanceNames;
2113 Array<Uint32> indices;
2114 Array<Uint32> sizes;
2115
2116 //
2117 // Form the names of the instance index and data files
2118 //
2119
2120 String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
2121 String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
2122 mike 1.1.2.1
2123 //
2124 // Get all instances for the class:
2125 //
2126
2127 Array<Uint32> freeFlags;
2128
2129 if (!InstanceIndexFile::enumerateEntries(
2130 indexFilePath, freeFlags, indices, sizes, instanceNames, false))
2131 {
2132 PEG_METHOD_EXIT();
2133 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2134 MessageLoaderParms(
2135 "Repository.DefaultRepository.FAILED_TO_LOAD_INSTANCE_NAMES",
2136 "Failed to load instance names in class $0",
2137 className.getString()));
2138 }
2139
2140 PEG_METHOD_EXIT();
2141 return instanceNames;
2142 }
2143 mike 1.1.2.1
2144
2145 Array<CIMInstance> DefaultRepository::execQuery(
2146 bool lock,
2147 const String& queryLanguage,
2148 const String& query)
2149 {
2150 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::execQuery");
2151
2152 ConditionalReadLock rlock(_lock, lock);
2153
2154 PEG_METHOD_EXIT();
2155 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "execQuery()");
2156
2157 PEGASUS_UNREACHABLE(PEG_METHOD_EXIT();
2158 return Array<CIMInstance>();)
2159 }
2160
2161 Array<CIMObject> DefaultRepository::associators(
2162 bool lock,
2163 const CIMNamespaceName& nameSpace,
2164 mike 1.1.2.1 const CIMObjectPath& objectName,
2165 const CIMName& assocClass,
2166 const CIMName& resultClass,
2167 const String& role,
2168 const String& resultRole,
2169 Boolean includeQualifiers,
2170 Boolean includeClassOrigin,
2171 const CIMPropertyList& propertyList)
2172 {
2173 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::associators");
2174
2175 ConditionalReadLock rlock(_lock, lock);
2176
2177 Array<CIMObjectPath> names = associatorNames(
2178 false,
2179 nameSpace,
2180 objectName,
2181 assocClass,
2182 resultClass,
2183 role,
2184 resultRole);
2185 mike 1.1.2.1
2186 Array<CIMObject> result;
2187
2188 for (Uint32 i = 0, n = names.size(); i < n; i++)
2189 {
2190 CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2191
2192 if (tmpNameSpace.isNull())
2193 tmpNameSpace = nameSpace;
2194
2195 //
2196 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2197 // distinguish instanceNames from classNames in every case
2198 // The instanceName of a singleton instance of a keyless class also
2199 // has no key bindings
2200 //
2201 if (names[i].getKeyBindings ().size () == 0)
2202 {
2203 CIMObjectPath tmpRef = names[i];
2204 tmpRef.setHost(String());
2205 tmpRef.setNameSpace(CIMNamespaceName());
2206 mike 1.1.2.1
2207 CIMClass cimClass = getClass(
2208 false,
2209 tmpNameSpace,
2210 tmpRef.getClassName(),
2211 false,
2212 includeQualifiers,
2213 includeClassOrigin,
2214 propertyList);
2215
2216 CIMObject cimObject(cimClass);
2217 cimObject.setPath (names[i]);
2218 result.append(cimObject);
2219 }
2220 else
2221 {
2222 CIMObjectPath tmpRef = names[i];
2223 tmpRef.setHost(String());
2224 tmpRef.setNameSpace(CIMNamespaceName());
2225
2226 CIMInstance cimInstance = getInstance(
2227 mike 1.1.2.1 false,
2228 tmpNameSpace,
2229 tmpRef,
2230 false,
2231 includeQualifiers,
2232 includeClassOrigin,
2233 propertyList);
2234
2235 CIMObject cimObject(cimInstance);
2236 cimObject.setPath (names[i]);
2237 result.append(cimObject);
2238 }
2239 }
2240
2241 PEG_METHOD_EXIT();
2242 return result;
2243 }
2244
2245 Array<CIMObjectPath> DefaultRepository::associatorNames(
2246 bool lock,
2247 const CIMNamespaceName& nameSpace,
2248 mike 1.1.2.1 const CIMObjectPath& objectName,
2249 const CIMName& assocClass,
2250 const CIMName& resultClass,
2251 const String& role,
2252 const String& resultRole)
2253 {
2254 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::associatorNames");
2255
2256 ConditionalReadLock rlock(_lock, lock);
2257
2258 Array<String> associatorNames;
2259
2260 // The assocClass parameter implies subclasses, so retrieve them
2261 Array<CIMName> assocClassList;
2262 if (!assocClass.isNull())
2263 {
2264 _nameSpaceManager.getSubClassNames(
2265 nameSpace, assocClass, true, assocClassList);
2266 assocClassList.append(assocClass);
2267 }
2268
2269 mike 1.1.2.1 // The resultClass parameter implies subclasses, so retrieve them
2270 Array<CIMName> resultClassList;
2271 if (!resultClass.isNull())
2272 {
2273 _nameSpaceManager.getSubClassNames(
2274 nameSpace, resultClass, true, resultClassList);
2275 resultClassList.append(resultClass);
2276 }
2277
2278 //
2279 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2280 // distinguish instanceNames from classNames in every case
2281 // The instanceName of a singleton instance of a keyless class also
2282 // has no key bindings
2283 //
2284 if (objectName.getKeyBindings ().size () == 0)
2285 {
2286 CIMName className = objectName.getClassName();
2287
2288 Array<CIMName> classList;
2289 _nameSpaceManager.getSuperClassNames(nameSpace, className, classList);
2290 mike 1.1.2.1 classList.append(className);
2291
2292 Array<String> assocFileName =
2293 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceRead);
2294
2295 for (int i=0,m=assocFileName.size(); i<m; i++)
2296 {
2297 AssocClassTable::getAssociatorNames(
2298 assocFileName[i],
2299 classList,
2300 assocClassList,
2301 resultClassList,
2302 role,
2303 resultRole,
2304 associatorNames);
2305 }
2306 }
2307 else
2308 {
2309 String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);
2310
2311 mike 1.1.2.1 AssocInstTable::getAssociatorNames(
2312 assocFileName,
2313 objectName,
2314 assocClassList,
2315 resultClassList,
2316 role,
2317 resultRole,
2318 associatorNames);
2319 }
2320
2321 Array<CIMObjectPath> result;
2322
2323 for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
2324 {
2325 CIMObjectPath r = associatorNames[i];
2326
2327 if (r.getHost().size() == 0)
2328 r.setHost(System::getHostName());
2329
2330 if (r.getNameSpace().isNull())
2331 r.setNameSpace(nameSpace);
2332 mike 1.1.2.1
2333 result.append(r);
2334 }
2335
2336
2337 PEG_METHOD_EXIT();
2338 return result;
2339 }
2340
2341 Array<CIMObject> DefaultRepository::references(
2342 bool lock,
2343 const CIMNamespaceName& nameSpace,
2344 const CIMObjectPath& objectName,
2345 const CIMName& resultClass,
2346 const String& role,
2347 Boolean includeQualifiers,
2348 Boolean includeClassOrigin,
2349 const CIMPropertyList& propertyList)
2350 {
2351 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::references");
2352
2353 mike 1.1.2.1 ConditionalReadLock rlock(_lock, lock);
2354
2355 Array<CIMObjectPath> names = referenceNames(
2356 false,
2357 nameSpace,
2358 objectName,
2359 resultClass,
2360 role);
2361
2362 Array<CIMObject> result;
2363
2364 for (Uint32 i = 0, n = names.size(); i < n; i++)
2365 {
2366 CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2367
2368 if (tmpNameSpace.isNull())
2369 tmpNameSpace = nameSpace;
2370
2371 // ATTN: getInstance() should this be able to handle instance names
2372 // with host names and namespaces?
2373
2374 mike 1.1.2.1 CIMObjectPath tmpRef = names[i];
2375 tmpRef.setHost(String());
2376 tmpRef.setNameSpace(CIMNamespaceName());
2377
2378 //
2379 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2380 // distinguish instanceNames from classNames in every case
2381 // The instanceName of a singleton instance of a keyless class also
2382 // has no key bindings
2383 //
2384 if (objectName.getKeyBindings ().size () == 0)
2385 {
2386 CIMClass cimClass = getClass(
2387 false,
2388 tmpNameSpace,
2389 tmpRef.getClassName(),
2390 false,
2391 includeQualifiers,
2392 includeClassOrigin,
2393 propertyList);
2394
2395 mike 1.1.2.1 CIMObject cimObject = CIMObject (cimClass);
2396 cimObject.setPath (names[i]);
2397 result.append (cimObject);
2398 }
2399 else
2400 {
2401 CIMInstance instance = getInstance(
2402 false,
2403 tmpNameSpace,
2404 tmpRef,
2405 false,
2406 includeQualifiers,
2407 includeClassOrigin,
2408 propertyList);
2409
2410 CIMObject cimObject = CIMObject (instance);
2411 cimObject.setPath (names[i]);
2412 result.append (cimObject);
2413 }
2414 }
2415
2416 mike 1.1.2.1 PEG_METHOD_EXIT();
2417 return result;
2418 }
2419
2420 Array<CIMObjectPath> DefaultRepository::referenceNames(
2421 bool lock,
2422 const CIMNamespaceName& nameSpace,
2423 const CIMObjectPath& objectName,
2424 const CIMName& resultClass,
2425 const String& role)
2426 {
2427 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::referenceNames");
2428
2429 ConditionalReadLock rlock(_lock, lock);
2430
2431 Array<String> tmpReferenceNames;
2432
2433 // The resultClass parameter implies subclasses, so retrieve them
2434 Array<CIMName> resultClassList;
2435
2436 try
2437 mike 1.1.2.1 {
2438 if (!resultClass.isNull())
2439 {
2440 _nameSpaceManager.getSubClassNames(
2441 nameSpace, resultClass, true, resultClassList);
2442 resultClassList.append(resultClass);
2443 }
2444
2445 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2446 // distinguish instanceNames from classNames in every case
2447 // The instanceName of a singleton instance of a keyless class also
2448 // has no key bindings
2449 //
2450 if (objectName.getKeyBindings ().size () == 0)
2451 {
2452 CIMName className = objectName.getClassName();
2453
2454 Array<CIMName> classList;
2455 _nameSpaceManager.getSuperClassNames(
2456 nameSpace, className, classList);
2457 classList.append(className);
2458 mike 1.1.2.1
2459 Array<String> assocFileName =
2460 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceRead);
2461
2462 Boolean refs=false;
2463 for (int i = 0, m=assocFileName.size(); !refs && i < m; i++)
2464 {
2465 if (AssocClassTable::getReferenceNames(
2466 assocFileName[i],
2467 classList,
2468 resultClassList,
2469 role,
2470 tmpReferenceNames))
2471 {
2472 refs |= true;
2473 }
2474 }
2475
2476 if (refs == false)
2477 {
2478 // Ignore error! It's okay not to have references.
2479 mike 1.1.2.1 }
2480 }
2481 else
2482 {
2483 String assocFileName =
2484 _nameSpaceManager.getAssocInstPath(nameSpace);
2485
2486 if (!AssocInstTable::getReferenceNames(
2487 assocFileName,
2488 objectName,
2489 resultClassList,
2490 role,
2491 tmpReferenceNames))
2492 {
2493 // Ignore error! It's okay not to have references.
2494 }
2495 }
2496 }
2497 catch (const CIMException& exception)
2498 {
2499 if (exception.getCode() == CIM_ERR_INVALID_CLASS)
2500 mike 1.1.2.1 {
2501 throw PEGASUS_CIM_EXCEPTION(
2502 CIM_ERR_INVALID_PARAMETER, exception.getMessage());
2503 }
2504 else
2505 {
2506 throw;
2507 }
2508 }
2509
2510 Array<CIMObjectPath> result;
2511
2512 for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
2513 {
2514 CIMObjectPath r = tmpReferenceNames[i];
2515
2516 if (r.getHost().size() == 0)
2517 r.setHost(System::getHostName());
2518
2519 if (r.getNameSpace().isNull())
2520 r.setNameSpace(nameSpace);
2521 mike 1.1.2.1
2522 result.append(r);
2523 }
2524
2525 PEG_METHOD_EXIT();
2526 return result;
2527 }
2528
2529 CIMValue DefaultRepository::getProperty(
2530 bool lock,
2531 const CIMNamespaceName& nameSpace,
2532 const CIMObjectPath& instanceName,
2533 const CIMName& propertyName)
2534 {
2535 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getProperty");
2536
2537 ConditionalReadLock rlock(_lock, lock);
2538
2539 //
2540 // Retrieve the specified instance
2541 //
2542 mike 1.1.2.1
2543 CIMInstance cimInstance = getInstance(
2544 false, nameSpace, instanceName, false, true, true, CIMPropertyList());
2545
2546 //
2547 // Get the requested property from the instance
2548 //
2549
2550 Uint32 pos = cimInstance.findProperty(propertyName);
2551
2552 // ATTN: This breaks if the property is simply null
2553 if (pos == PEG_NOT_FOUND)
2554 {
2555 PEG_METHOD_EXIT();
2556 throw PEGASUS_CIM_EXCEPTION(
2557 CIM_ERR_NO_SUCH_PROPERTY,
2558 propertyName.getString());
2559 }
2560
2561 CIMProperty prop = cimInstance.getProperty(pos);
2562
2563 mike 1.1.2.1 //
2564 // Return the value:
2565 //
2566
2567 PEG_METHOD_EXIT();
2568 return prop.getValue();
2569 }
2570
2571 void DefaultRepository::setProperty(
2572 bool lock,
2573 const CIMNamespaceName& nameSpace,
2574 const CIMObjectPath& instanceName,
2575 const CIMName& propertyName,
2576 const CIMValue& newValue,
2577 const ContentLanguageList& contentLangs)
2578 {
2579 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::setProperty");
2580
2581 // It is not necessary to control access to the ReadWriteSem _lock here.
2582 // This method calls modifyInstance, which does its own access control.
2583
2584 mike 1.1.2.1 //
2585 // Create the instance to pass to modifyInstance()
2586 //
2587
2588 CIMInstance instance(instanceName.getClassName());
2589 instance.addProperty(CIMProperty(propertyName, newValue));
2590 instance.setPath (instanceName);
2591
2592 //
2593 // Create the propertyList to pass to modifyInstance()
2594 //
2595
2596 Array<CIMName> propertyListArray;
2597 propertyListArray.append(propertyName);
2598 CIMPropertyList propertyList(propertyListArray);
2599
2600 //
2601 // Modify the instance to set the value of the given property
2602 //
2603 modifyInstance(
2604 true,
2605 mike 1.1.2.1 nameSpace,
2606 instance,
2607 false,
2608 propertyList,
2609 ContentLanguageList());
2610
2611 PEG_METHOD_EXIT();
2612 }
2613
2614 CIMQualifierDecl DefaultRepository::getQualifier(
2615 bool lock,
2616 const CIMNamespaceName& nameSpace,
2617 const CIMName& qualifierName)
2618 {
2619 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getQualifier");
2620
2621 ConditionalReadLock rlock(_lock, lock);
2622
2623 //
2624 // Get path of qualifier file:
2625 //
2626 mike 1.1.2.1
2627 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2628 nameSpace, qualifierName,NameSpaceRead);
2629
2630 //
2631 // Load qualifier:
2632 //
2633
2634 CIMQualifierDecl qualifierDecl;
2635
2636 try
2637 {
2638 // Check the cache first:
2639
2640 if (!_qualifierCache.get(qualifierFilePath, qualifierDecl))
2641 {
2642 // Not in cache so load from disk:
2643
2644 _LoadObject(qualifierFilePath, qualifierDecl, streamer);
2645
2646 // Put in cache:
2647 mike 1.1.2.1
2648 _qualifierCache.put(qualifierFilePath, qualifierDecl);
2649 }
2650 }
2651 catch (const CannotOpenFile&)
2652 {
2653 PEG_METHOD_EXIT();
2654 throw PEGASUS_CIM_EXCEPTION
2655 (CIM_ERR_NOT_FOUND, qualifierName.getString());
2656 }
2657
2658 PEG_METHOD_EXIT();
2659 return qualifierDecl;
2660 }
2661
2662 void DefaultRepository::setQualifier(
2663 bool lock,
2664 const CIMNamespaceName& nameSpace,
2665 const CIMQualifierDecl& qualifierDecl,
2666 const ContentLanguageList& contentLangs)
2667 {
2668 mike 1.1.2.1 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::setQualifier");
2669
2670 ConditionalWriteLock wlock(_lock, lock);
2671 AutoFileLock fileLock(_lockFile);
2672
2673 // -- Get path of qualifier file:
2674
2675 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2676 nameSpace, qualifierDecl.getName(),NameSpaceWrite);
2677
2678 // -- If qualifier already exists, throw exception:
2679
2680 if (FileSystem::existsNoCase(qualifierFilePath))
2681 {
2682 PEG_METHOD_EXIT();
2683 throw PEGASUS_CIM_EXCEPTION(
2684 CIM_ERR_NOT_SUPPORTED, qualifierDecl.getName().getString());
2685 }
2686
2687 // -- Save qualifier:
2688
2689 mike 1.1.2.1 Buffer qualifierDeclXml;
2690 streamer->encode(qualifierDeclXml, qualifierDecl);
2691 //XmlWriter::appendQualifierDeclElement(qualifierDeclXml, qualifierDecl);
2692 _SaveObject(qualifierFilePath, qualifierDeclXml,streamer);
2693
2694 _qualifierCache.put(qualifierFilePath, (CIMQualifierDecl&)qualifierDecl);
2695
2696 PEG_METHOD_EXIT();
2697 }
2698
2699 void DefaultRepository::deleteQualifier(
2700 bool lock,
2701 const CIMNamespaceName& nameSpace,
2702 const CIMName& qualifierName)
2703 {
2704 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteQualifier");
2705
2706 ConditionalWriteLock wlock(_lock, lock);
2707 AutoFileLock fileLock(_lockFile);
2708
2709 // -- Get path of qualifier file:
2710 mike 1.1.2.1
2711 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2712 nameSpace, qualifierName,NameSpaceDelete);
2713
2714 // -- Delete qualifier:
2715
2716 if (!FileSystem::removeFileNoCase(qualifierFilePath))
2717 {
2718 PEG_METHOD_EXIT();
2719 throw PEGASUS_CIM_EXCEPTION
2720 (CIM_ERR_NOT_FOUND, qualifierName.getString());
2721 }
2722
2723 _qualifierCache.evict(qualifierFilePath);
2724
2725 PEG_METHOD_EXIT();
2726 }
2727
2728 Array<CIMQualifierDecl> DefaultRepository::enumerateQualifiers(
2729 bool lock,
2730 const CIMNamespaceName& nameSpace)
2731 mike 1.1.2.1 {
2732 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateQualifiers");
2733
2734 ConditionalReadLock rlock(_lock, lock);
2735
2736 String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);
2737
2738 Array<String> qualifierNames;
2739
2740 if (!FileSystem::getDirectoryContents(qualifiersRoot, qualifierNames))
2741 {
2742 PEG_METHOD_EXIT();
2743 String str ="enumerateQualifiers()";
2744 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2745 MessageLoaderParms("Repository.DefaultRepository.INTERNAL_ERROR",
2746 "$0: internal error",
2747 str));
2748 }
2749
2750 Array<CIMQualifierDecl> qualifiers;
2751
2752 mike 1.1.2.1 for (Uint32 i = 0; i < qualifierNames.size(); i++)
2753 {
2754 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
2755 // All chars above 0x7F will be escape.
2756 CIMQualifierDecl qualifier = getQualifier(false, nameSpace,
2757 escapeStringDecoder(qualifierNames[i]));
2758 #else
2759 CIMQualifierDecl qualifier = getQualifier( false, nameSpace,
2760 qualifierNames[i]);
2761 #endif
2762 qualifiers.append(qualifier);
2763 }
2764
2765 PEG_METHOD_EXIT();
2766 return qualifiers;
2767 }
2768
2769 void DefaultRepository::createNameSpace(
2770 bool lock,
2771 const CIMNamespaceName& nameSpace,
2772 const NameSpaceAttributes& attributes)
2773 mike 1.1.2.1 {
2774 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::createNameSpace");
2775
2776 ConditionalWriteLock wlock(_lock, lock);
2777 AutoFileLock fileLock(_lockFile);
2778 _nameSpaceManager.createNameSpace(nameSpace, attributes);
2779
2780 PEG_METHOD_EXIT();
2781 }
2782
2783 void DefaultRepository::modifyNameSpace(
2784 bool lock,
2785 const CIMNamespaceName& nameSpace,
2786 const NameSpaceAttributes& attributes)
2787 {
2788 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::modifyNameSpace");
2789
2790 ConditionalWriteLock wlock(_lock, lock);
2791 AutoFileLock fileLock(_lockFile);
2792 _nameSpaceManager.modifyNameSpace(nameSpace, attributes);
2793
2794 mike 1.1.2.1 PEG_METHOD_EXIT();
2795 }
2796
2797 Array<CIMNamespaceName> DefaultRepository::enumerateNameSpaces(
2798 bool lock) const
2799 {
2800 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateNameSpaces");
2801
2802 ConditionalReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
2803
2804 Array<CIMNamespaceName> nameSpaceNames;
2805 _nameSpaceManager.getNameSpaceNames(nameSpaceNames);
2806
2807 PEG_METHOD_EXIT();
2808 return nameSpaceNames;
2809 }
2810
2811 void DefaultRepository::deleteNameSpace(
2812 bool lock,
2813 const CIMNamespaceName& nameSpace)
2814 {
2815 mike 1.1.2.1 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteNameSpace");
2816
2817 ConditionalWriteLock wlock(_lock, lock);
2818 AutoFileLock fileLock(_lockFile);
2819 _nameSpaceManager.deleteNameSpace(nameSpace);
2820
2821 PEG_METHOD_EXIT();
2822 }
2823
2824 Boolean DefaultRepository::getNameSpaceAttributes(
2825 bool lock,
2826 const CIMNamespaceName& nameSpace,
2827 NameSpaceAttributes& attributes)
2828 {
2829 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteNameSpace");
2830
2831 ConditionalReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
2832 attributes.clear();
2833 PEG_METHOD_EXIT();
2834 return _nameSpaceManager.getNameSpaceAttributes(nameSpace, attributes);
2835 }
2836 mike 1.1.2.1
2837 Boolean DefaultRepository::isRemoteNameSpace(
2838 bool lock,
2839 const CIMNamespaceName& nameSpaceName,
2840 String& remoteInfo)
2841 {
2842 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::isRemoteNamespace");
2843 ConditionalReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
2844 PEG_METHOD_EXIT();
2845 return _nameSpaceManager.isRemoteNameSpace(nameSpaceName, remoteInfo);
2846 }
2847
2848 //----------------------------------------------------------------------
2849 //
2850 // _getInstanceIndexFilePath()
2851 //
2852 // returns the file path of the instance index file.
2853 //
2854 //----------------------------------------------------------------------
2855
2856 String DefaultRepository::_getInstanceIndexFilePath(
2857 mike 1.1.2.1 const CIMNamespaceName& nameSpace,
2858 const CIMName& className) const
2859 {
2860 PEG_METHOD_ENTER(TRC_REPOSITORY,
2861 "DefaultRepository::_getInstanceIndexFilePath");
2862
2863 String tmp = _nameSpaceManager.getInstanceDataFileBase(
2864 nameSpace, className);
2865
2866 tmp.append(".idx");
2867
2868 PEG_METHOD_EXIT();
2869 return tmp;
2870 }
2871
2872 //----------------------------------------------------------------------
2873 //
2874 // _getInstanceDataFilePath()
2875 //
2876 // returns the file path of the instance file.
2877 //
2878 mike 1.1.2.1 //----------------------------------------------------------------------
2879
2880 String DefaultRepository::_getInstanceDataFilePath(
2881 const CIMNamespaceName& nameSpace,
2882 const CIMName& className) const
2883 {
2884 PEG_METHOD_ENTER(
2885 TRC_REPOSITORY, "DefaultRepository::_getInstanceDataFilePath");
2886
2887 String tmp = _nameSpaceManager.getInstanceDataFileBase(
2888 nameSpace, className);
2889 tmp.append(".instances");
2890
2891 PEG_METHOD_EXIT();
2892 return tmp;
2893 }
2894
2895 Boolean DefaultRepository::_loadInstance(
2896 const String& path,
2897 CIMInstance& object,
2898 Uint32 index,
2899 mike 1.1.2.1 Uint32 size)
2900 {
2901 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_loadInstance");
2902
2903 //
2904 // Load instance (in XML) from instance file into memory:
2905 //
2906
2907 Buffer data;
2908
2909 if (!InstanceDataFile::loadInstance(path, index, size, data))
2910 {
2911 PEG_METHOD_EXIT();
2912 return false;
2913 }
2914
2915 //
2916 // Convert XML into an actual object:
2917 //
2918
2919 streamer->decode(data, 0, object);
2920 mike 1.1.2.1 //XmlParser parser((char*)data.getData());
2921 //XmlReader::getObject(parser, object);
2922
2923 PEG_METHOD_EXIT();
2924 return true;
2925 }
2926
2927 void DefaultRepository::setDeclContext(
2928 bool lock,
2929 RepositoryDeclContext* context)
2930 {
2931 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::setDeclContext");
2932
2933 ConditionalWriteLock wlock(_lock, lock);
2934 AutoFileLock fileLock(_lockFile);
2935 _context = context;
2936
2937 PEG_METHOD_EXIT();
2938 }
2939
2940 #ifdef PEGASUS_DEBUG
2941 mike 1.1.2.1 void DefaultRepository::DisplayCacheStatistics(
2942 bool lock)
2943 {
2944 #ifdef PEGASUS_USE_CLASS_CACHE
2945 cout << "Repository Class Cache Statistics:" << endl;
2946 _classCache.DisplayCacheStatistics();
2947 #endif
2948 cout << "Repository Qualifier Cache Statistics:" << endl;
2949 _qualifierCache.DisplayCacheStatistics();
2950 }
2951 #endif
2952
2953 void DefaultRepository::getSubClassNames(
2954 bool lock,
2955 const CIMNamespaceName& nameSpaceName,
2956 const CIMName& className,
2957 Boolean deepInheritance,
2958 Array<CIMName>& subClassNames) const
2959 {
2960 ConditionalReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
2961 _nameSpaceManager.getSubClassNames(nameSpaceName,
2962 mike 1.1.2.1 className,
2963 deepInheritance,
2964 subClassNames);
2965 }
2966
2967 /** Get the names of all superclasses (direct and indirect) of this
2968 class.
2969 */
2970 void DefaultRepository::getSuperClassNames(
2971 bool lock,
2972 const CIMNamespaceName& nameSpaceName,
2973 const CIMName& className,
2974 Array<CIMName>& superClassNames) const
2975 {
2976 ConditionalReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
2977 _nameSpaceManager.getSuperClassNames(
2978 nameSpaceName, className, superClassNames);
2979 }
2980
2981 PEGASUS_NAMESPACE_END
|