📄 cqlselectstatementrep.cpp
字号:
// cases where the FROM class is the first, and maybe only, // element of the chain). PEGASUS_ASSERT((pos < startingPos + 2) || ids[pos].isWildcard()); curContext = ids[0].getName(); } PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"current context: " + curContext.getString()); // Get the class definition of the current class context // Note: keep this code here so that class existence is always // checked. Eg. SELECT * FROM fromClass CIMClass classDef; try { classDef = _ctx->getClass(curContext); } catch (const CIMException& ce) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"repository error"); PEG_METHOD_EXIT(); if (ce.getCode() == CIM_ERR_NOT_FOUND || ce.getCode() == CIM_ERR_INVALID_CLASS) { MessageLoaderParms parms("CQL.CQLSelectStatementRep.VAL_CLASS_NOT_EXIST", "The class $0 does not exist.", curContext.getString()); throw QueryValidationException(parms); } else { throw; } } // Now do the checks for properties existing on the current class context // and the class relationship rules in section 5.4.1. // Only do these checks if the chain id has a property. if (pos > startingPos) { if (ids[pos].isWildcard()) { // The wildcard is at the end (verified by applyContext), so // no checking is required at this position. continue; } // Determine if the property name at the current position // exists on the current class context. Uint32 propertyIndex = classDef.findProperty(ids[pos].getName()); if (propertyIndex == PEG_NOT_FOUND) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"prop not on context " + ids[pos].getName().getString()); PEG_METHOD_EXIT(); MessageLoaderParms parms("CQL.CQLSelectStatementRep.VAL_PROP_NOT_ON_CLASS", "The property $0 does not exist on class $1.", ids[pos].getName().getString(), classDef.getClassName().getString()); throw QueryMissingPropertyException(parms); } // Checking class relationship rules in section 5.4.1. // For validateProperties, this only applies to the first // property in the chain. This is because once we get into // embedded properties we don't know what the class will be // until we have an instance. if ((pos == (startingPos+1)) && !curContext.equal(ids[0].getName())) { // Its the first property, and the class context is not the FROM class. // Check the class relationship between the scoping class and the FROM class. if (_ctx->getClassRelation(ids[0].getName(), curContext) == QueryContext::NOTRELATED) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"scope violation for:"+ ids[0].getName().getString()); PEG_METHOD_EXIT(); MessageLoaderParms parms("CQL.CQLSelectStatementRep.VAL_SCOPE_VIOLATION", "The class $0 is not a superclass, subclass, or the same class as $1.", curContext.getString(), ids[0].getName().getString()); throw QueryValidationException(parms); } } // If the current position implies an embedded object, then // verify that the property is an embedded object if ((pos > startingPos) && (pos < (ids.size() - 1))) { CIMProperty embObj = classDef.getProperty(propertyIndex); CIMName qual("EmbeddedObject"); if (embObj.findQualifier(qual) == PEG_NOT_FOUND) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"prop not emb " + embObj.getName().getString()); PEG_METHOD_EXIT(); MessageLoaderParms parms("CQL.CQLSelectStatementRep.PROP_NOT_EMB", "The property $0 must be an embedded object.", embObj.getName().getString()); throw QueryValidationException(parms); } } } } PEG_METHOD_EXIT();}CIMName CQLSelectStatementRep::lookupFromClass(const String& lookup){ PEG_METHOD_ENTER (TRC_CQL, "CQLSelectStatementRep::lookupFromClass"); QueryIdentifier id = _ctx->findClass(lookup); PEG_METHOD_EXIT(); return id.getName();}Array<CIMObjectPath> CQLSelectStatementRep::getClassPathList(){ PEG_METHOD_ENTER (TRC_CQL, "CQLSelectStatementRep::getClassPathList"); if(_ctx == NULL){ PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"null QC"); PEG_METHOD_EXIT(); MessageLoaderParms parms("CQL.CQLSelectStatementRep.QUERY_CONTEXT_IS_NULL", "Trying to process a query with a NULL Query Context."); throw CQLRuntimeException(parms); } Array<QueryIdentifier> ids = _ctx->getFromList(); PEGASUS_ASSERT(ids.size() == 1); // no joins yet // No wbem-uri support yet. CIMObjectPath path(String::EMPTY, _ctx->getNamespace(), ids[0].getName()); Array<CIMObjectPath> paths; paths.append(path); PEG_METHOD_EXIT(); return paths;}CIMPropertyList CQLSelectStatementRep::getPropertyList(const CIMObjectPath& inClassName){ PEG_METHOD_ENTER (TRC_CQL, "CQLSelectStatementRep::getPropertyList"); try { return getPropertyListInternal(inClassName, true, true); } catch (const CIMException& ce) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"cim exception"); PEG_METHOD_EXIT(); if (ce.getCode() == CIM_ERR_NOT_FOUND || ce.getCode() == CIM_ERR_INVALID_CLASS) { MessageLoaderParms parms("CQL.CQLSelectStatementRep.GPL_CLASS_NOT_EXIST", "A class required to determine the property list was not found."); throw CQLRuntimeException(parms); } else { throw; } }}CIMPropertyList CQLSelectStatementRep::getSelectPropertyList(const CIMObjectPath& inClassName){ PEG_METHOD_ENTER (TRC_CQL, "CQLSelectStatementRep::getSelectPropertyList"); try { return getPropertyListInternal(inClassName, true, false); } catch (const CIMException& ce) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"cim exception"); PEG_METHOD_EXIT(); if (ce.getCode() == CIM_ERR_NOT_FOUND || ce.getCode() == CIM_ERR_INVALID_CLASS) { MessageLoaderParms parms("CQL.CQLSelectStatementRep.GPL_CLASS_NOT_EXIST", "A class required to determine the property list was not found."); throw CQLRuntimeException(parms); } else { throw; } }}CIMPropertyList CQLSelectStatementRep::getWherePropertyList(const CIMObjectPath& inClassName){ PEG_METHOD_ENTER (TRC_CQL, "CQLSelectStatementRep::getWherePropertyList"); try { return getPropertyListInternal(inClassName, false, true); } catch (const CIMException& ce) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"cim exception"); PEG_METHOD_EXIT(); if (ce.getCode() == CIM_ERR_NOT_FOUND || ce.getCode() == CIM_ERR_INVALID_CLASS) { MessageLoaderParms parms("CQL.CQLSelectStatementRep.GPL_CLASS_NOT_EXIST", "A class required to determine the property list was not found."); throw CQLRuntimeException(parms); } else { throw; } }}CIMPropertyList CQLSelectStatementRep::getPropertyListInternal(const CIMObjectPath& inClassName, Boolean includeSelect, Boolean includeWhere){ PEG_METHOD_ENTER (TRC_CQL, "CQLSelectStatementRep::getPropertyListInternal"); if(_ctx == NULL) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"null QC"); PEG_METHOD_EXIT(); MessageLoaderParms parms("CQL.CQLSelectStatementRep.QUERY_CONTEXT_IS_NULL", "Trying to process a query with a NULL Query Context."); throw CQLRuntimeException(parms); } if (!_contextApplied) applyContext(); // Get the FROM class. CIMName fromClass = _ctx->getFromList()[0].getName(); // Get the classname passed in. Note: since wbem-uri is not supported yet, // only use the classname part of the path. CIMName className = inClassName.getClassName(); if (className.isNull()) { // If the caller passed in an empty className, then the // FROM class is to be used. className = fromClass; } else { // The caller passed in some class name. Verify that it is the FROM // class or a subclass of the FROM class. if(!(className == fromClass)) { // Check if subclass of the FROM class if(!_ctx->isSubClass(fromClass, className)) { MessageLoaderParms parms("CQL.CQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS", "Class $0 does not match the FROM class or any of its subclasses.", className.getString()); throw CQLRuntimeException(parms); } } } Boolean isWildcard; Array<CIMName> reqProps; Array<CIMName> matchedScopes; Array<CIMName> unmatchedScopes; // Add required properties from the select list. if (includeSelect) { for (Uint32 i = 0; i < _selectIdentifiers.size(); i++) { isWildcard = addRequiredProperty(reqProps, className, _selectIdentifiers[i], matchedScopes, unmatchedScopes); if (isWildcard) { // This indicates that a wildcard was found, // and the class passed in was the FROM class. // Return null property list to indicate all properties required. return CIMPropertyList(); } } } // Add required properties from the WHERE clause. if (includeWhere) { Array<QueryChainedIdentifier> _whereIdentifiers = _ctx->getWhereList(); for (Uint32 i = 0; i < _whereIdentifiers.size(); i++) { isWildcard = addRequiredProperty(reqProps, className, _whereIdentifiers[i], matchedScopes, unmatchedScopes); // Wildcards are not allowed in the WHERE clause PEGASUS_ASSERT(!isWildcard); } } // Check if every property on the class is required. CIMClass theClass = _ctx->getClass(className); Uint32 propCnt = theClass.getPropertyCount(); Boolean allProps = true; for (Uint32 i = 0; i < propCnt; i++) { if (!containsProperty(theClass.getProperty(i).getName(), reqProps)) { allProps = false; break; } } if (allProps) { // Return null property list to indicate all properties are required. PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"all props req"); PEG_METHOD_EXIT(); return CIMPropertyList(); } else { // Return the required property list. Note that it is possible to return // an empty list in the case of no required properties for the classname // passed in. This can happen when the scoping operator is used. PEG_METHOD_EXIT(); return CIMPropertyList(reqProps); }}Boolean CQLSelectStatementRep::addRequiredProperty(Array<CIMName>& reqProps, CIMName& className, QueryChainedIdentifier& chainId, Array<CIMName>& matchedScopes, Array<CIMName>& unmatchedScopes){ PEG_METHOD_ENTER (TRC_CQL, "CQLSelectStatementRep::addRequiredProperty"); // // Implementation notes: // This function does not look for required properties on embedded objects. // This function assumes that applyContext has been called. // Array<QueryIdentifier> ids = chainId.getSubIdentifiers(); // After applyContext has been called, a single element // chained identifier refers to either an instance of the // FROM class, or is the classname on the right side of ISA. if (ids.size() == 1) { // This identifier is not a property name PEG_METHOD_EXIT(); return false; } PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"id[1] = " + ids[1].toString()); if (ids[1].isSymbolicConstant()) { // Non-embedded symbolic constants are not properties // Note that an embedded symbolic constant like this: // fromclass.embobj.scope::someprop#'ok' // implies that embobj is a required property, because // embobj could be null, and that affects how the // identifier is evaluated. PEG_METHOD_EXIT(); return false; } // Since applyContext has been called, the first chain element // will be the FROM class, so go to the 2nd chain element. if (ids[1].isScoped()) { // The 2nd chain element is a scoped property. // Eg. fromclass.someclass::someprop // Determine the class that the property is being scoped to. // This could be the FROM class, or some other class not in the FROM list CIMName scopingClass = CIMName(ids[1].getScope()); // Check if the scoping class is the same as the class passed in. if (scopingClass == className) { // The scoping class is the same as the class passed, // add the property if not already added if (!containsProperty(ids[1].getName(), reqProps)) { reqProps.append(ids[1].getName()); } } else { // The scoping class is not the same as the class passed in. // Check if we already know that the scoping class is a subclass // of the class passed in if (containsProperty(scopingClass, unmatchedScopes)) { // Scoping class is a subclass. PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"scoping class is a subclass"); PEG_METHOD_EXIT(); return false; } // Check if we already know that the scoping class is a superclass // of the class passed in Boolean isSuper = false; if (containsProperty(scopingClass, matchedScopes)) { // Scoping class is a superclass. isSuper = true; } // Check if the scoping class is a superclass of the class passed in if (isSuper || _ctx->isSubClass(scopingClass, className)) { PEG_TRACE_STRING (TRC_CQL, Tracer::LEVEL4,"scoping class is a superclass"); // Scoping class is a superclass of the class passed in. if (!isSuper) { // Save this information matchedScopes.append(scopingClass); } // Add to the required property list if not already there.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -