OW_WQLSelectStatement.hpp

Go to the documentation of this file.
00001 //%/////////////////////////////////////////////////////////////////////////////
00002 //
00003 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
00004 // The Open Group, Tivoli Systems
00005 // Portions Copyright (C) 2003-2004 Vintela, Inc. All rights reserved.
00006 //
00007 // Permission is hereby granted, free of charge, to any person obtaining a copy
00008 // of this software and associated documentation files (the "Software"), to
00009 // deal in the Software without restriction, including without limitation the
00010 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00011 // sell copies of the Software, and to permit persons to whom the Software is
00012 // furnished to do so, subject to the following conditions:
00013 // 
00014 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
00015 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
00016 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
00017 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
00018 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00019 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00020 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00021 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 //
00023 //==============================================================================
00024 //
00025 // Author: Mike Brasher (mbrasher@bmc.com)
00026 //
00027 // Modified By: Dan Nuffer
00028 //
00029 //%/////////////////////////////////////////////////////////////////////////////
00030 #ifndef OW_WQL_SELECT_STATEMENT_HPP_INCLUDE_GUARD_H_
00031 #define OW_WQL_SELECT_STATEMENT_HPP_INCLUDE_GUARD_H_
00032 #include "OW_config.h"
00033 #include "OW_Array.hpp"
00034 #include "OW_String.hpp"
00035 #include "OW_WQLOperation.hpp"
00036 #include "OW_WQLOperand.hpp"
00037 #include "OW_WQLPropertySource.hpp"
00038 
00039 namespace OW_NAMESPACE
00040 {
00041 
00053 class WQLCompile;
00054 class OW_WQLCOMMON_API WQLSelectStatement
00055 {
00056 public:
00057    WQLSelectStatement();
00058    ~WQLSelectStatement();
00061    void clear();
00062    const String& getClassName() const
00063    {
00064       return _className;
00065    }
00069    void setClassName(const String& className)
00070    {
00071       _className = className;
00072    }
00076    UInt32 getSelectPropertyNameCount() const
00077    {
00078       return _selectPropertyNames.size();
00079    }
00082    const String& getSelectPropertyName(UInt32 i) const
00083    {
00084       return _selectPropertyNames[i];
00085    }
00088    const StringArray& getSelectPropertyNames() const
00089    {
00090       return _selectPropertyNames;
00091    }
00095    void appendSelectPropertyName(const String& x)
00096    {
00097       _selectPropertyNames.append(x);
00098    }
00101    UInt32 getWherePropertyNameCount() const
00102    {
00103       return _wherePropertyNames.size();
00104    }
00107    const String& getWherePropertyName(UInt32 i) const
00108    {
00109       return _wherePropertyNames[i];
00110    }
00116    bool appendWherePropertyName(const String& x);
00120    void appendOperation(WQLOperation x)
00121    {
00122       _operStack.push_back(x);
00123    }
00127    void appendOperand(const WQLOperand& x)
00128    {
00129       _operStack.push_back(x);
00130    }
00133    bool hasWhereClause() const
00134    {
00135       return !_operStack.empty();
00136    }
00145    bool evaluateWhereClause(const WQLPropertySource* source) const;
00148    void print(std::ostream& ostr) const;
00149    String toString() const;
00150    void compileWhereClause(const WQLPropertySource* source, WQLCompile& wcl);
00151 private:
00152 
00153 #ifdef OW_WIN32
00154 #pragma warning (push)
00155 #pragma warning (disable: 4251)
00156 #endif
00157 
00158    //
00159    // The name of the target class. For example:
00160    //
00161    //  SELECT * 
00162    //  FROM TargetClass
00163    //  WHERE ...
00164    //
00165    String _className;
00166    //
00167    // The list of property names being selected. For example, see "firstName",
00168    // and "lastName" below.
00169    //
00170    //  SELECT firstName, lastName 
00171    //  FROM TargetClass
00172    //  WHERE ...
00173    //
00174    Array<String> _selectPropertyNames;
00175    //
00176    // The unique list of property names appearing in the WHERE clause.
00177    // Although a property may occur many times in the WHERE clause, it will
00178    // only appear once in this list.
00179    //
00180    Array<String> _wherePropertyNames;
00181    //
00182    // The list of operations encountered while parsing the WHERE clause.
00183    // Consider this query:
00184    //
00185    //  SELECT *
00186    //  FROM TargetClass
00187    //  WHERE count > 10 OR peak < 20 AND state = "OKAY"
00188    //
00189    // This would generate the following stream of WQLOperations:
00190    //
00191    //  WQL_GT
00192    //  WQL_LT
00193    //  WQL_EQ
00194    //  WQL_AND
00195    //  WQL_OR
00196    //
00197    //Array<WQLOperation> _operations;
00198    // 
00199    // The list of operands encountered while parsing the WHERE clause. They
00200    // query just above would generate the following stream of operands:
00201    //
00202    //  count, 10, peak, 20, state, "OKAY"
00203    //
00204    //Array<WQLOperand> _operands;
00205    struct OperandOrOperation
00206    {
00207       enum Type
00208       {
00209          OPERATION,
00210          OPERAND
00211       };
00212       OperandOrOperation(WQLOperation o)
00213          : m_type(OPERATION)
00214          , m_operation(o)
00215       {}
00216       OperandOrOperation(const WQLOperand& o)
00217          : m_type(OPERAND)
00218          , m_operand(o)
00219       {}
00220       Type m_type;
00221       WQLOperation m_operation;
00222       WQLOperand m_operand;
00223       String toString() const
00224       {
00225          if (m_type == OPERATION)
00226          {
00227             return WQLOperationToString(m_operation);
00228          }
00229          else
00230          {
00231             return m_operand.toString();
00232          }
00233       }
00234    };
00235    Array<OperandOrOperation> _operStack;
00236    friend class WQLCompile;
00237 
00238 #ifdef OW_WIN32
00239 #pragma warning (pop)
00240 #endif
00241 
00242 };
00243 
00244 } // end namespace OW_NAMESPACE
00245 
00246 #endif

Generated on Thu Feb 9 08:48:18 2006 for openwbem by  doxygen 1.4.6