(file) Return to WQLSelectStatement.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WQL

  1 mike  1.1.2.1 //%/////////////////////////////////////////////////////////////////////////////
  2               //
  3               // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM, 
  4               // The Open Group, Tivoli Systems
  5               //
  6               // Permission is hereby granted, free of charge, to any person obtaining a copy
  7               // of this software and associated documentation files (the "Software"), to 
  8               // deal in the Software without restriction, including without limitation the 
  9               // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 10               // sell copies of the Software, and to permit persons to whom the Software is
 11               // furnished to do so, subject to the following conditions:
 12               // 
 13               // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 14               // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15               // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16               // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 17               // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 18               // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 19               // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20               // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21               //
 22 mike  1.1.2.1 //==============================================================================
 23               //
 24               // Author: Mike Brasher (mbrasher@bmc.com)
 25               //
 26               // Modified By:
 27               //
 28               //%/////////////////////////////////////////////////////////////////////////////
 29               
 30               #ifndef Pegasus_WQLSelectStatement_h
 31               #define Pegasus_WQLSelectStatement_h
 32               
 33               #include <Pegasus/Common/Config.h>
 34               #include <Pegasus/Common/Array.h>
 35               #include <Pegasus/Common/String.h>
 36               #include <Pegasus/WQL/WQLOperation.h>
 37               #include <Pegasus/WQL/WQLOperand.h>
 38 mike  1.1.2.2 #include <Pegasus/WQL/WQLPropertySource.h>
 39 mike  1.1.2.1 
 40               PEGASUS_NAMESPACE_BEGIN
 41               
 42 mike  1.1.2.4 /** This class represents a compiled WQL1 select statement. 
 43 mike  1.1.2.1 
 44                   An instance of WQLSelectStatement is passed to WQLParser::parse() which
 45 mike  1.1.2.4     parses the WQL1 SELECT statement and initializes the WQLSelectStatement
 46                   instance. A WQL1 SELECT statement has the following form:
 47 mike  1.1.2.1 
 48                   <pre>
 49 mike  1.1.2.4 	SELECT &lt;property&gt;...
 50               	FROM &lt;class name&gt;
 51               	WHERE &lt;where clause&gt;
 52 mike  1.1.2.1     </pre>
 53               
 54 mike  1.1.2.5     There are methods for obtaining the various elements of the select
 55                   statement.
 56                   
 57 mike  1.1.2.1     The components of the where clause are stored in two arrays: one for
 58                   operands and one for operators (these are placed in proper order by the
 59                   YACC parser). Evaluation is performed using a Boolean stack. See the
 60                   implementation of evaluateWhereClause() for details.
 61               */
 62               class PEGASUS_WQL_LINKAGE WQLSelectStatement
 63               {
 64               public:
 65               
 66                   /** Default constructor. 
 67                   */
 68                   WQLSelectStatement();
 69               
 70                   /** Destructor.
 71                   */
 72                   ~WQLSelectStatement();
 73               
 74                   /** Clears all data members of this object.
 75                   */
 76                   void clear();
 77               
 78 mike  1.1.2.1     /** Accessor.
 79                   */
 80                   const String& getClassName() const
 81                   {
 82               	return _className;
 83                   }
 84               
 85                   /** Modifier. This method should not be called by the user (only by the
 86               	parser).
 87                   */
 88                   void setClassName(const String& className)
 89                   {
 90               	_className = className;
 91                   }
 92               
 93                   /** Returns the number of property names which were indicated in the
 94               	selection list.
 95                   */
 96 mike  1.1.2.5     Uint32 getSelectPropertyNameCount() const
 97 mike  1.1.2.1     {
 98 mike  1.1.2.5 	return _selectPropertyNames.size();
 99 mike  1.1.2.1     }
100               
101 mike  1.1.2.5     /** Gets the i-th selected property name in the list.
102 mike  1.1.2.1     */
103 mike  1.1.2.5     const String& getSelectPropertyName(Uint32 i)
104 mike  1.1.2.1     {
105 mike  1.1.2.5 	return _selectPropertyNames[i];
106 mike  1.1.2.1     }
107               
108                   /** Appends a property name to the property name list. This user should
109               	not call this method; it should only be called by the parser.
110                   */
111 mike  1.1.2.5     void appendSelectPropertyName(const String& x)
112                   {
113               	_selectPropertyNames.append(x);
114                   }
115               
116                   /** Returns the number of unique property names from the where clause.
117                   */
118                   Uint32 getWherePropertyNameCount() const
119                   {
120               	return _wherePropertyNames.size();
121                   }
122               
123                   /** Gets the i-th unique property appearing in the where clause.
124                   */
125                   const String& getWherePropertyName(Uint32 i)
126 mike  1.1.2.1     {
127 mike  1.1.2.5 	return _wherePropertyNames[i];
128 mike  1.1.2.1     }
129               
130 mike  1.1.2.5     /** Appends a property name to the where property name list. This user 
131               	should not call this method; it should only be called by the parser.
132               
133               	@param x name of the property.
134               	@return false if a property with that name already exists.
135                   */
136                   Boolean appendWherePropertyName(const String& x);
137               
138 mike  1.1.2.1     /** Appends an operation to the operation array. This method should only
139               	be called by the parser itself.
140                   */
141                   void appendOperation(WQLOperation x)
142                   {
143               	_operations.append(x);
144                   }
145               
146                   /** Appends an operand to the operation array. This method should only
147               	be called by the parser itself.
148                   */
149                   void appendOperand(const WQLOperand& x)
150                   {
151               	_operands.append(x);
152                   }
153               
154                   /** Returns true if this class has a where clause.
155                   */
156                   Boolean hasWhereClause() const
157                   {
158               	return _operations.size() != 0;
159 mike  1.1.2.1     }
160               
161 mike  1.1.2.2     /** Evalautes the where clause using the symbol table to resolve symbols.
162 mike  1.1.2.1     */
163 mike  1.1.2.3     Boolean evaluateWhereClause(const WQLPropertySource* source) const;
164 mike  1.1.2.1 
165                   /** Prints out the members of this class.
166                   */
167                   void print() const;
168               
169               private:
170               
171                   //
172                   // The name of the target class. For example:
173                   //
174                   //     SELECT * 
175                   //     FROM TargetClass
176                   //     WHERE ...
177                   //
178               
179                   String _className;
180               
181                   //
182                   // The list of property names being selected. For example, see "firstName",
183                   // and "lastName" below.
184                   //
185 mike  1.1.2.1     //     SELECT firstName, lastName 
186                   //     FROM TargetClass
187                   //     WHERE ...
188                   //
189               
190 mike  1.1.2.5     Array<String> _selectPropertyNames;
191               
192                   //
193                   // The unique list of property names appearing in the WHERE clause.
194                   // Although a property may occur many times in the WHERE clause, it will
195                   // only appear once in this list.
196                   //
197               
198                   Array<String> _wherePropertyNames;
199 mike  1.1.2.1 
200                   //
201                   // The list of operations encountered while parsing the WHERE clause.
202                   // Consider this query:
203                   //
204                   //     SELECT *
205                   //     FROM TargetClass
206                   //     WHERE count > 10 OR peak < 20 AND state = "OKAY"
207                   //
208                   // This would generate the following stream of WQLOperations:
209                   //
210                   //     WQL_GT
211                   //     WQL_LT
212                   //     WQL_EQ
213                   //     WQL_AND
214                   //     WQL_OR
215                   //
216               
217                   Array<WQLOperation> _operations;
218               
219                   // 
220 mike  1.1.2.1     // The list of operands encountered while parsing the WHERE clause. They
221                   // query just above would generate the following stream of operands:
222                   //
223                   //     count, 10, peak, 20, state, "OKAY"
224                   //
225               
226                   Array<WQLOperand> _operands;
227 mike  1.1.2.5 
228                   void f() const { }
229 mike  1.1.2.1 };
230               
231               PEGASUS_NAMESPACE_END
232               
233               #endif /* Pegasus_WQLSelectStatement_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2