📄 cqlvaluerep.cpp
字号:
CQLIdentifier id = _CQLChainId[0]; id.setName(inCid[inCid.size()-1].getName()); id.applyScope(inCid[inCid.size()-1].getScope()); CQLChainedIdentifier chainId(id); for(Sint32 i = inCid.size()-2; i >= 0; --i) { chainId.prepend(inCid[i]); } _CQLChainId = chainId; CIMInstance temp; resolve(temp,_ctx); } else { _CQLChainId.applyContext(const_cast<QueryContext&>(_ctx)); } // Add the chained identifier to the WHERE identifier list. // Note: CQLValue's are only used in WHERE processing. if (_CQLChainId.size() > 0) { const_cast<QueryContext&>(_ctx).addWhereIdentifier(_CQLChainId); }}void CQLValueRep::_resolveSymbolicConstant(const QueryContext& inQueryCtx){ PEG_METHOD_ENTER(TRC_CQL,"CQLValueRep::_resolveSymbolicConstant()"); Array<String> valueMapArray; // Value Map Qualifier for property Array<String> valuesArray; // Values Qualifier for property CIMName className; CQLIdentifier lid = _CQLChainId.getLastIdentifier(); CIMClass QueryClass; CIMValue valueMap; // CIMValue for Value Map Qualifiers CIMValue values; // CIMValue for Values Qualifiers Boolean matchFound = false; // Indicator for match Qualifier Uint32 matchIndex = 0; // Placeholder for matched Qualifier if(lid.isScoped()) { className = lid.getScope(); } else { className = _CQLChainId[0].getName(); } QueryClass = inQueryCtx.getClass(className); Uint32 propertyIndex = QueryClass.findProperty(lid.getName()); if(propertyIndex == PEG_NOT_FOUND) { MessageLoaderParms mload(String("CQL.CQLValueRep.PROP_NOT_FOUND"), String("Property $0 not found on class $1."), lid.getName().getString(), className.getString()); throw CQLRuntimeException(mload); } CIMProperty queryPropObj = QueryClass.getProperty(propertyIndex); // We have a symbolic constant (ex. propName#OK) // We need to retrieve the ValueMap and Values Qualifiers for // the property if the exist. Uint32 qualIndex = queryPropObj.findQualifier(CIMName("Values")); if(qualIndex == PEG_NOT_FOUND) { // This property can not be processed with a symbolic constant. MessageLoaderParms mload(String("CQL.CQLValueRep.QUALIFIER_NOT_FOUND"), String("Qualifier $0 not found on Property $1 in class $2."), String("Values"), lid.getName().getString(), className.getString()); throw CQLRuntimeException(mload); } values = queryPropObj.getQualifier(qualIndex).getValue(); qualIndex = queryPropObj.findQualifier(CIMName("ValueMap")); if(qualIndex == PEG_NOT_FOUND) { // This property does not have a ValueMap Qualifier, // therefore the values must be the list of symbolic constants. values.get(valuesArray); // We will loop through the list of Symbolic constants to // determine if we have a match with the Symbolic constant // defined in the CQLIdentifier. for(Uint32 i = 0; i < valuesArray.size(); ++i) { if(String::equalNoCase(valuesArray[i],lid.getSymbolicConstantName())) { matchFound = true; matchIndex = i; break; } } if(matchFound == false) { // The symbolic constant provided is not valid // for this property. MessageLoaderParms mload(String("CQL.CQLValueRep.INVALID_SYMBOLIC_CONSTANT"), String("Provided symbolic constant $0 is not valid for property $1 in class $2."), lid.getSymbolicConstantName(), lid.getName().getString(), className.getString()); throw CQLRuntimeException(mload); } // The symbolic constant defined in the CQLIdentifier is // valid for this property. Now we need to set the value. // Set primitive _setValue(Uint64(matchIndex)); PEG_METHOD_EXIT(); return; } else { // The qualifier Values is defined for the property. // valueMap must be a list of #'s. valueMap = queryPropObj.getQualifier(qualIndex).getValue(); valueMap.get(valueMapArray); values.get(valuesArray); // We will loop through the list of Symbolic constants to // determine if we have a match with the Symbolic constant // defined in the CQLIdentifier. for(Uint32 i = 0; i < valuesArray.size(); ++i) { if(String::equalNoCase(valuesArray[i],lid.getSymbolicConstantName())) { matchFound = true; matchIndex = i; break; } } if(matchFound == false) { // The symbolic constant provided is not valid // for this property. MessageLoaderParms mload(String("CQL.CQLValueRep.INVALID_SYMBOLIC_CONSTANT"), String("Provided symbolic constant $0 is not valid for property $1 in class $2."), lid.getSymbolicConstantName(), lid.getName().getString(), className.getString()); throw CQLRuntimeException(mload); } // Set Primitive if(valueMapArray[matchIndex].find(String("..")) != PEG_NOT_FOUND) { // The symbolic constant provided is not valid // for this property. MessageLoaderParms mload(String("CQL.CQLValueRep.INVALID_SYMBOLIC_CONSTANT"), String("Provided symbolic constant $0 is not valid for property $1 in class $2."), lid.getSymbolicConstantName(), lid.getName().getString(), className.getString()); throw CQLRuntimeException(mload); } _setValue(CIMValue(Sint64(CQLUtilities::stringToSint64(valueMapArray[matchIndex])))); PEG_METHOD_EXIT(); return; } }Boolean CQLValueRep::_compareObjects(CIMObject& _in1, CIMObject& _in2){ if(_in1.isClass() != _in2.isClass()) { return false; } else if(_in1.isClass()) { // objects are classes return ((_in1.getClassName() == _in2.getClassName()) && _in1.identical(_in2)); } else { // objects are instances if(!(_in1.getClassName() == _in2.getClassName())) { return false; } if(_in1.getPropertyCount() != _in2.getPropertyCount()) { return false; } Array<CIMProperty> prop1; Array<CIMProperty> prop2; Boolean result; for(Uint32 i = 0; i < _in1.getPropertyCount(); ++i) { prop1.append(_in1.getProperty(i)); prop2.append(_in2.getProperty(i)); } for(Uint32 i = 0; i < _in1.getPropertyCount(); ++i) { result = false; for(Uint32 j = 0; j < _in2.getPropertyCount(); ++j) { if(prop1[i].getName() == prop2[j].getName()) { if(prop1[i].isArray() != prop2[j].isArray()) { break; } if(prop1[i].isArray()) { CQLValueRep left; CQLValueRep right; left._setValue(prop1[i].getValue()); right._setValue(prop2[j].getValue()); result = left._compareArray(right); } else { if(CQLValue(prop1[i].getValue()) == CQLValue(prop2[j].getValue())) { result = true; break; } else { result = false; break; } } } } if(result == false) { return false; } } } return true;}Boolean CQLValueRep::_compareArray(const CQLValueRep& _in){ PEG_METHOD_ENTER(TRC_CQL,"CQLValueRep::_compareArray()"); Boolean result; Array<Boolean> _bool1; Array<Boolean> _bool2; Array<Uint64> _uint1; Array<Uint64> _uint2; Array<Sint64> _sint1; Array<Sint64> _sint2; Array<Real64> _real1; Array<Real64> _real2; Array<String> _str1; Array<String> _str2; Array<CIMDateTime> _date1; Array<CIMDateTime> _date2; Array<CIMObjectPath> _path1; Array<CIMObjectPath> _path2; Array<CIMObject> _obj1; Array<CIMObject> _obj2; Array<CQLValue> _cqlVal1; Array<CQLValue> _cqlVal2; CIMValue _in1 = _theValue; CIMValue _in2 = _in._theValue; String _arrayType1 = _ArrayType; String _arrayType2 = _in._ArrayType; switch(_in1.getType()) { case CIMTYPE_BOOLEAN: { _in1.get(_bool1); for(Uint32 i = 0; i < _bool1.size(); ++i) { _cqlVal1.append(CQLValue(_bool1[i])); } break; } case CIMTYPE_UINT64: { _in1.get(_uint1); for(Uint32 i = 0; i < _uint1.size(); ++i) { _cqlVal1.append(CQLValue(_uint1[i])); } break; } case CIMTYPE_SINT64: { _in1.get(_sint1); for(Uint32 i = 0; i < _sint1.size(); ++i) { _cqlVal1.append(CQLValue(_sint1[i])); } break; } case CIMTYPE_REAL64: { _in1.get(_real1); for(Uint32 i = 0; i < _real1.size(); ++i) { _cqlVal1.append(CQLValue(_real1[i])); } break; } case CIMTYPE_STRING: { _in1.get(_str1); for(Uint32 i = 0; i < _str1.size(); ++i) { _cqlVal1.append(CQLValue(_str1[i])); } break; } case CIMTYPE_DATETIME: { _in1.get(_date1); for(Uint32 i = 0; i < _date1.size(); ++i) { _cqlVal1.append(CQLValue(_date1[i])); } break; } case CIMTYPE_REFERENCE: { _in1.get(_path1); for(Uint32 i = 0; i < _path1.size(); ++i) { _cqlVal1.append(CQLValue(_path1[i])); } break; } case CIMTYPE_OBJECT: { _in1.get(_obj1); for(Uint32 i = 0; i < _obj1.size(); ++i) { _cqlVal1.append(CQLValue(_obj1[i])); } break; }#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT case CIMTYPE_INSTANCE: { Array<CIMInstance> tmpInst; _in1.get(tmpInst); for(Uint32 i = 0; i < tmpInst.size(); ++i) { _cqlVal1.append(CQLValue((CIMObject)tmpInst[i])); } break; } #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT default: MessageLoaderParms mload(String("CQL.CQLValueRep.INVALID_ARRAY_COMPARISON"), String("Invalid array comparison type: $0."), _in1.getType()); throw CQLRuntimeException(mload); } // switch statement switch(_in2.getType()) { case CIMTYPE_BOOLEAN: { _in2.get(_bool2); for(Uint32 i = 0; i < _bool2.size(); ++i) { _cqlVal2.append(CQLValue(_bool2[i])); } break; } case CIMTYPE_UINT64: { _in2.get(_uint2); for(Uint32 i = 0; i < _uint2.size(); ++i) { _cqlVal2.append(CQLValue(_uint2[i])); } break; } case CIMTYPE_SINT64: { _in2.get(_sint2); for(Uint32 i = 0; i < _sint2.size(); ++i) { _cqlVal2.append(CQLValue(_sint2[i])); } break; } case CIMTYPE_REAL64: { _in2.get(_real2); for(Uint32 i = 0; i < _real2.size(); ++i) { _cqlVal2.append(CQLValue(_real2[i])); } break; } case CIMTYPE_STRING: { _in2.get(_str2); for(Uint32 i = 0; i < _str2.size(); ++i) { _cqlVal2.append(CQLValue(_str2[i])); } break; } case CIMTYPE_DATETIME: { _in2.get(_date2); for(Uint32 i = 0; i < _date2.size(); ++i) { _cqlVal2.append(CQLValue(_date2[i])); } break; } case CIMTYPE_REFERENCE: { _in2.get(_path2); for(Uint32 i = 0; i < _path2.size(); ++i) { _cqlVal2.append(CQLValue(_path2[i])); } break; } case CIMTYPE_OBJECT: { _in2.get(_obj2); for(Uint32 i = 0; i < _obj2.size(); ++i) { _cqlVal2.append(CQLValue(_obj2[i])); }#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT case CIMTYPE_INSTANCE: { Array<CIMObject> tmpInst; _in2.get(tmpInst); for(Uint32 i = 0; i < tmpInst.size(); ++i) { _cqlVal2.append(CQLValue((CIMObject)tmpInst[i])); } }#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT break; } default: MessageLoaderParms mload(String("CQL.CQLValueRep.INVALID_ARRAY_COMPARISON"), String("Invalid array comparison type: $0."), _in2.getType()); throw CQLRuntimeException(mload); } // switch statement if((_arrayType1 == String("Indexed") || _arrayType1 == String("Ordered")) && (_arrayType2 == String("Indexed") || _arrayType2 == String("Ordered"))) { // Handle the indexed or ordered case. for(Uint32 i = 0; i < _cqlVal1.size(); ++i) { if(_cqlVal1[i] != _cqlVal2[i]) { PEG_METHOD_EXIT(); return false; } } } else // We are doing a bag comparison { for(Uint32 i = 0; i < _cqlVal1.size(); ++i) { result = false; for(Uint32 j = 0; j < _cqlVal2.size(); ++j) { if(_cqlVal1[i] == _cqlVal2[j]) { result = true; break; } } if(result == false) { PEG_METHOD_EXIT(); return false; } } for(Uint32 i = 0; i < _cqlVal2.size(); ++i) { result = false; for(Uint32 j = 0; j < _cqlVal1.size(); ++j) { if(_cqlVal2[i] == _cqlVal1[j]) { result = true; break; } } if(result == false) { PEG_METHOD_EXIT(); return false; } } } PEG_METHOD_EXIT(); return true;}String CQLValueRep::valueTypeToString(const CQLValue::CQLValueType parmType) { String returnStr; switch (parmType) { case CQLValue::Null_type: returnStr.append("NULL"); break; case CQLValue::Sint64_type: returnStr.append("Sint64"); break; case CQLValue::Uint64_type: returnStr.append("Uint64"); break; case CQLValue::Real_type: returnStr.append("Real"); break; case CQLValue::String_type: returnStr.append("String"); break; case CQLValue::CIMDateTime_type: returnStr.append("DateTime"); break; case CQLValue::CIMReference_type: returnStr.append("CIM Ref"); break; case CQLValue::CQLIdentifier_type: returnStr.append("Identifier"); break; case CQLValue::CIMObject_type: returnStr.append("CIM Object"); break; case CQLValue::Boolean_type: returnStr.append("Boolean"); break; default: returnStr.append("Unknown"); } return returnStr;}PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -