📄 queryexpression.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/FileSystem.h>#include <stdio.h>#include <fstream>#include <string.h>#include <Pegasus/Common/String.h>#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/Query/QueryExpression/QueryExpression.h>#include <Pegasus/Query/QueryCommon/SelectStatement.h>#include <Pegasus/CQL/CQLSelectStatement.h>#include <Pegasus/Repository/RepositoryQueryContext.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Repository/CIMRepository.h>#include <Pegasus/Common/CIMInstance.h>#include <Pegasus/Common/CIMObjectPath.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;//FILE *CQL_in;//int CQL_parse();//PEGASUS_NAMESPACE_BEGIN//CQLParserState* globalParserState = 0;//PEGASUS_NAMESPACE_ENDBoolean _applyProjection(QueryExpression& qe, Array<CIMInstance>& _instances, String testOption, String lang){ if(testOption == String::EMPTY || testOption == "2") { cout << endl << lang << " ========Apply Projection Results========" << endl; cout << qe.getQuery() << endl; for(Uint32 j = 0; j < _instances.size(); j++) { cout << "Instance of class " << _instances[j].getClassName().getString() << endl; try { CIMInstance projInst = _instances[j].clone(); Boolean gotPropExc = false; try { qe.applyProjection(projInst, false); } catch (QueryRuntimePropertyException & qrpe) { // Got a missing property exception. cout << "-----" << qrpe.getMessage() << endl; gotPropExc = true; } if (gotPropExc) { // Got a missing property exception. // Try again, allowing missing properties. // Need to use a cloned instance because the original instance // was partially projected. cout << "Instance of class " << _instances[j].getClassName().getString() << ". Allow missing properties." << endl; projInst = _instances[j].clone(); qe.applyProjection(projInst, true); } Uint32 cnt = projInst.getPropertyCount(); if (cnt == 0) { cout << "-----No properties left after projection" << endl; } if (cnt > 10) { // If more than 10 props, just print the count to keep // the output file short cout << "Instance has " << cnt << " properties" << endl; } else { for (Uint32 n = 0; n < cnt; n++) { CIMProperty prop = projInst.getProperty(n); CIMValue val = prop.getValue(); cout << "-----Prop #" << n << " Name = " << prop.getName().getString(); if (val.isNull()) { cout << " Value = NULL" << endl; } else { cout << " Value = " << val.toString() << endl; } } } } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} } } return true;}void _printPropertyList(CIMPropertyList& propList){ if (propList.isNull()) { cout << "-----all properties required" << endl; } else if (propList.size() == 0) { cout << "-----no properties required" << endl; } else { for (Uint32 n = 0; n < propList.size(); n++) { cout << "-----Required property " << propList[n].getString() << endl; } }}Boolean _getPropertyList(QueryExpression& qe, Array<CIMInstance>& _instances, CIMNamespaceName ns, String testOption, String lang){ if(testOption == String::EMPTY || testOption == "3") { for(Uint32 j = 0; j < _instances.size(); j++) { cout << endl << lang << " ========Get Property List Results=======" << endl; cout << qe.getQuery() << endl; try { cout << endl << "Get Class Path List" << endl; Array<CIMObjectPath> fromPaths = qe.getClassPathList(); for (Uint32 k = 0; k < fromPaths.size(); k++) { cout << "-----" << fromPaths[k].toString() << endl; } } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} CIMName className = _instances[j].getClassName(); CIMObjectPath classPath (String::EMPTY, ns, className); CIMPropertyList propList; try { cout << "Property List for the FROM class" << endl; propList = qe.getPropertyList(); _printPropertyList(propList); } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} try { cout << "Property List for " << className.getString() << endl; propList = qe.getPropertyList(classPath); _printPropertyList(propList); } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} try { propList.clear(); cout << "SELECT Property List for the FROM class" << endl; propList = qe.getSelectPropertyList(); _printPropertyList(propList); } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} try { propList.clear(); cout << "SELECT Property List for " << className.getString() << endl; propList = qe.getSelectPropertyList(classPath); _printPropertyList(propList); } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} try { propList.clear(); cout << "WHERE Property List for the FROM class" << endl; propList = qe.getWherePropertyList(); _printPropertyList(propList); } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} try { propList.clear(); cout << "WHERE Property List for " << className.getString() << endl; propList = qe.getWherePropertyList(classPath); _printPropertyList(propList); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -