📄 cimrepository.cpp
字号:
// // Create entry in index file: // if (!InstanceIndexFile::createEntry( indexFilePath, instanceName, index, size)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE", "Failed to create instance: $0", instanceName.toString())); } transaction.complete(); Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass, true); PEG_METHOD_EXIT(); return instanceName;}void CIMRepository::modifyClass( const CIMNamespaceName& nameSpace, const CIMClass& modifiedClass, const ContentLanguageList& contentLangs){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyClass"); WriteLock lock(_lock); AutoFileLock fileLock(_lockFile); _modifyClass(nameSpace, modifiedClass); PEG_METHOD_EXIT();}void CIMRepository::_modifyClass( const CIMNamespaceName& nameSpace, const CIMClass& modifiedClass){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_modifyClass"); // // Resolve the class: // CIMClass cimClass(modifiedClass); Resolver::resolveClass (cimClass, _context, nameSpace); // // Check to see if it is okay to modify this class: // String classFilePath; _nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(), cimClass.getSuperClassName(), classFilePath); // // ATTN: KS // Disallow modification of classes which have instances (that are // in the repository). And we have no idea whether the class has // instances in other repositories or in providers. We should do // an enumerate instance names at a higher level (above the repository). //#ifdef PEGASUS_USE_CLASS_CACHE _classCache.evict(classFilePath);#endif /* PEGASUS_USE_CLASS_CACHE */ // // Delete the old file containing the class: // if (!FileSystem::removeFileNoCase(classFilePath)) { PEG_METHOD_EXIT(); String str = "CIMRepository::modifyClass()"; throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Repository.CIMRepository.FAILED_TO_REMOVE_FILE", "failed to remove file in $0", str)); } // // Create new class file: // Buffer classXml; streamer->encode(classXml, cimClass); //XmlWriter::appendClassElement(classXml, cimClass); _SaveObject(classFilePath, classXml,streamer); if (cimClass.isAssociation()) { // Remove from Association Array<String> assocFileName = _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceDelete); if (FileSystem::exists(assocFileName[0])) { AssocClassTable::deleteAssociation( assocFileName[0], cimClass.getClassName()); // Create the association again. _createAssocClassEntries(nameSpace, cimClass); } else { PEG_METHOD_EXIT(); throw CannotOpenFile(assocFileName[0]); } } // // Cache this class: //#ifdef PEGASUS_USE_CLASS_CACHE _classCache.put(classFilePath, cimClass);#endif /* PEGASUS_USE_CLASS_CACHE */ PEG_METHOD_EXIT();}void CIMRepository::modifyInstance( const CIMNamespaceName& nameSpace, const CIMInstance& modifiedInstance, Boolean includeQualifiers, const CIMPropertyList& propertyList, const ContentLanguageList& contentLangs){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyInstance"); WriteLock lock(_lock); AutoFileLock fileLock(_lockFile); // // Do this: // String errMessage; CIMInstance cimInstance; // The instance that replaces the original if (propertyList.isNull()) { // // Replace all the properties in the instance // if (includeQualifiers) { // // Replace the entire instance with the given instance // (this is the default behavior) // cimInstance = modifiedInstance; } else { // // Replace all the properties in the instance, but keep the // original qualifiers on the instance and on the properties // _resolveInstance = false; cimInstance = _getInstance( nameSpace, modifiedInstance.getPath (), false, true, true, CIMPropertyList()); _resolveInstance = true; CIMInstance newInstance( modifiedInstance.getPath ().getClassName()); CIMInstance givenInstance = modifiedInstance; // // Copy over the original instance qualifiers // for (Uint32 i = 0; i < cimInstance.getQualifierCount(); i++) { newInstance.addQualifier(cimInstance.getQualifier(i)); } // // Loop through the properties replacing each property in the // original with a new value, but keeping the original qualifiers // for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++) { // Copy the given property value (not qualifiers) CIMProperty givenProperty = givenInstance.getProperty(i); CIMProperty newProperty( givenProperty.getName(), givenProperty.getValue(), givenProperty.getArraySize(), givenProperty.getReferenceClassName(), givenProperty.getClassOrigin(), givenProperty.getPropagated()); // Copy the original property qualifiers Uint32 origPos = cimInstance.findProperty(newProperty.getName()); if (origPos != PEG_NOT_FOUND) { CIMProperty origProperty = cimInstance.getProperty(origPos); for (Uint32 j=0; j<origProperty.getQualifierCount(); j++) { newProperty.addQualifier(origProperty.getQualifier(j)); } } // Add the newly constructed property to the new instance newInstance.addProperty(newProperty); } // Use the newly merged instance to replace the original instance cimInstance = newInstance; } } else { // // Replace only the properties specified in the given instance // _resolveInstance = false; cimInstance = _getInstance(nameSpace, modifiedInstance.getPath (), false, true, true, CIMPropertyList()); _resolveInstance = true; CIMInstance givenInstance = modifiedInstance; // NOTE: Instance qualifiers are not changed when a property list // is specified. Property qualifiers are replaced with the // corresponding property values. // // Loop through the propertyList replacing each property in the original // for (Uint32 i=0; i<propertyList.size(); i++) { Uint32 origPropPos = cimInstance.findProperty(propertyList[i]); if (origPropPos != PEG_NOT_FOUND) { // Case: Property set in original CIMProperty origProperty = cimInstance.getProperty(origPropPos); // Get the given property value Uint32 givenPropPos = givenInstance.findProperty(propertyList[i]); if (givenPropPos != PEG_NOT_FOUND) { // Case: Property set in original and given CIMProperty givenProperty = givenInstance.getProperty(givenPropPos); // Copy over the property from the given to the original if (includeQualifiers) { // Case: Total property replacement cimInstance.removeProperty(origPropPos); cimInstance.addProperty(givenProperty); } else { // Case: Replace only the property value (not quals) origProperty.setValue(givenProperty.getValue()); cimInstance.removeProperty(origPropPos); cimInstance.addProperty(origProperty); } } else { // Case: Property set in original and not in given // Just remove the property (set to null) cimInstance.removeProperty(origPropPos); } } else { // Case: Property not set in original // Get the given property value Uint32 givenPropPos = givenInstance.findProperty(propertyList[i]); if (givenPropPos != PEG_NOT_FOUND) { // Case: Property set in given and not in original CIMProperty givenProperty = givenInstance.getProperty(givenPropPos); // Copy over the property from the given to the original if (includeQualifiers) { // Case: Total property copy cimInstance.addProperty(givenProperty); } else { // Case: Copy only the property value (not qualifiers) CIMProperty newProperty( givenProperty.getName(), givenProperty.getValue(), givenProperty.getArraySize(), givenProperty.getReferenceClassName(), givenProperty.getClassOrigin(), givenProperty.getPropagated()); cimInstance.addProperty(newProperty); } } else { // Case: Property not set in original or in given // Nothing to do; just make sure the property name is valid // ATTN: This is not the most efficient solution CIMClass cimClass = getClass( nameSpace, cimInstance.getClassName(), false); if (cimClass.findProperty(propertyList[i]) == PEG_NOT_FOUND) { // ATTN: This exception may be returned by setProperty PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION( CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()"); } } } } } // // Resolve the instance (do not propagate qualifiers from class since // this will bloat the instance). // CIMConstClass cimClass; Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass, false); CIMObjectPath instanceName = cimInstance.buildPath(cimClass); // // Disallow operation if the instance name was changed: // // For bugzilla 1508. Hostname and namespace are not included // in the comparison here. CIMObjectPath modifiedInstancePath = modifiedInstance.getPath(); modifiedInstancePath.setNameSpace(CIMNamespaceName()); modifiedInstancePath.setHost(String::EMPTY); if (instanceName != modifiedInstancePath) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Repository.CIMRepository.ATTEMPT_TO_MODIFY_KEY_PROPERTY", "Attempted to modify a key property")); } // // Get paths of index and data files: // String indexFilePath = _getInstanceIndexFilePath( nameSpace, modifiedInstance.getClassName()); String dataFilePath = _getInstanceDataFilePath( nameSpace, modifiedInstance.getClassName()); // // Look up the specified instance // Uint32 oldSize; Uint32 oldIndex; Uint32 newSize; Uint32 newIndex; if (!InstanceIndexFile::lookupEntry( indexFilePath, instanceName, oldIndex, oldSize)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString()); } // // Perform the operation in a transaction scope to enable rollback on // failure. // InstanceTransactionHandler transaction(indexFilePath, dataFilePath); // // Modify the data file: // { Buffer out; streamer->encode(out, cimInstance); //XmlWriter::appendInstanceElement(out, cimInstance); newSize = out.size(); if (!InstanceDataFile::appendInstance(dataFilePath, out, newIndex)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -