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