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 schuur 1.9 #include <Pegasus/Common/CIMInstance.h>
41 #include <Pegasus/Common/CIMObject.h>
|
42 mike 1.2 #include <Pegasus/WQL/WQLOperation.h>
43 #include <Pegasus/WQL/WQLOperand.h>
44 #include <Pegasus/WQL/WQLPropertySource.h>
45
46 PEGASUS_NAMESPACE_BEGIN
47
48 /** This class represents a compiled WQL1 select statement.
49
50 An instance of WQLSelectStatement is passed to WQLParser::parse() which
51 parses the WQL1 SELECT statement and initializes the WQLSelectStatement
52 instance. A WQL1 SELECT statement has the following form:
53
54 <pre>
55 SELECT <property>...
56 FROM <class name>
57 WHERE <where clause>
58 </pre>
59
60 There are methods for obtaining the various elements of the select
61 statement.
62
63 mike 1.2 The components of the where clause are stored in two arrays: one for
64 operands and one for operators (these are placed in proper order by the
65 YACC parser). Evaluation is performed using a Boolean stack. See the
66 implementation of evaluateWhereClause() for details.
67 */
68 class PEGASUS_WQL_LINKAGE WQLSelectStatement
69 {
70 public:
71
72 /** Default constructor.
73 */
74 WQLSelectStatement();
75
76 /** Destructor.
77 */
78 ~WQLSelectStatement();
79
80 /** Clears all data members of this object.
81 */
82 void clear();
83
84 mike 1.2 /** Accessor.
85 */
|
86 kumpf 1.6 const CIMName& getClassName() const
|
87 mike 1.2 {
88 return _className;
89 }
90
91 /** Modifier. This method should not be called by the user (only by the
92 parser).
93 */
|
94 kumpf 1.6 void setClassName(const CIMName& className)
|
95 mike 1.2 {
96 _className = className;
97 }
98
|
99 kumpf 1.6 /**
100 Returns true if the query selects all properties ("*")
101 */
102 Boolean getAllProperties() const;
103
104 /**
105 Used by the parser to indicate the query selects all properties ("*")
106 This method should not be called by the user (only by the parser).
107 */
108 void setAllProperties(const Boolean allProperties);
109
|
110 mike 1.2 /** Returns the number of property names which were indicated in the
111 selection list.
|
112 kumpf 1.6 This function should only be used if getAllProperties() returns false.
|
113 mike 1.2 */
114 Uint32 getSelectPropertyNameCount() const
115 {
116 return _selectPropertyNames.size();
117 }
118
119 /** Gets the i-th selected property name in the list.
|
120 kumpf 1.6 This function should only be used if getAllProperties() returns false.
|
121 mike 1.2 */
|
122 kumpf 1.6 const CIMName& getSelectPropertyName(Uint32 i) const
|
123 mike 1.2 {
124 return _selectPropertyNames[i];
125 }
126
|
127 kumpf 1.6 /**
128 Returns a CIMPropertyList containing the selected properties.
129 The list is NULL if the query selects all properties (SELECT * FROM...).
130 */
131 const CIMPropertyList getSelectPropertyList() const;
132
133 /** Appends a property name to the property name list. The user should
|
134 mike 1.2 not call this method; it should only be called by the parser.
135 */
|
136 kumpf 1.6 void appendSelectPropertyName(const CIMName& x)
|
137 mike 1.2 {
138 _selectPropertyNames.append(x);
139 }
140
141 /** Returns the number of unique property names from the where clause.
142 */
143 Uint32 getWherePropertyNameCount() const
144 {
145 return _wherePropertyNames.size();
146 }
147
148 /** Gets the i-th unique property appearing in the where clause.
149 */
|
150 kumpf 1.6 const CIMName& getWherePropertyName(Uint32 i) const
|
151 mike 1.2 {
152 return _wherePropertyNames[i];
153 }
154
|
155 kumpf 1.6 /**
156 Returns a CIMPropertyList containing the unique properties used in the
157 WHERE clause
158 */
159 const CIMPropertyList getWherePropertyList() const;
160
161 /** Appends a property name to the where property name list. The user
|
162 mike 1.2 should not call this method; it should only be called by the parser.
163
164 @param x name of the property.
165 @return false if a property with that name already exists.
166 */
|
167 kumpf 1.6 Boolean appendWherePropertyName(const CIMName& x);
|
168 mike 1.2
169 /** Appends an operation to the operation array. This method should only
170 be called by the parser itself.
171 */
172 void appendOperation(WQLOperation x)
173 {
174 _operations.append(x);
175 }
176
177 /** Appends an operand to the operation array. This method should only
178 be called by the parser itself.
179 */
180 void appendOperand(const WQLOperand& x)
181 {
182 _operands.append(x);
183 }
184
185 /** Returns true if this class has a where clause.
186 */
187 Boolean hasWhereClause() const
188 {
189 mike 1.2 return _operations.size() != 0;
190 }
191
192 /** Evalautes the where clause using the symbol table to resolve symbols.
193 */
194 Boolean evaluateWhereClause(const WQLPropertySource* source) const;
195
|
196 schuur 1.9 /** Inspect an instance and remove properties not listed in Select projection.
197 */
198 void applyProjection(CIMInstance& inst);
199 void applyProjection(CIMObject& inst);
200
|
201 mike 1.2 /** Prints out the members of this class.
202 */
203 void print() const;
204
|
205 schuur 1.9 static const WQLSelectStatement EMPTY;
|
206 mike 1.2 private:
207
208 //
209 // The name of the target class. For example:
210 //
211 // SELECT *
212 // FROM TargetClass
213 // WHERE ...
214 //
215
|
216 kumpf 1.6 CIMName _className;
217
218 //
219 // Indicates that all properties are selected (i.e. SELECT * FROM ...)
220 //
221 Boolean _allProperties;
|
222 mike 1.2
223 //
224 // The list of property names being selected. For example, see "firstName",
225 // and "lastName" below.
226 //
227 // SELECT firstName, lastName
228 // FROM TargetClass
229 // WHERE ...
230 //
|
231 kumpf 1.6 // NOTE: if the query selects all properties, this list is empty, and
232 // _allProperties is true
233 //
234 // NOTE: duplicate property names are not removed from the select list
235 // (e.g. SELECT firstName, firstName FROM...) results in a list of
236 // two properties
237 //
|
238 mike 1.2
|
239 kumpf 1.6 Array<CIMName> _selectPropertyNames;
|
240 mike 1.2
241 //
242 // The unique list of property names appearing in the WHERE clause.
243 // Although a property may occur many times in the WHERE clause, it will
244 // only appear once in this list.
245 //
246
|
247 kumpf 1.6 Array<CIMName> _wherePropertyNames;
|
248 mike 1.2
249 //
250 // The list of operations encountered while parsing the WHERE clause.
251 // Consider this query:
252 //
253 // SELECT *
254 // FROM TargetClass
255 // WHERE count > 10 OR peak < 20 AND state = "OKAY"
256 //
257 // This would generate the following stream of WQLOperations:
258 //
259 // WQL_GT
260 // WQL_LT
261 // WQL_EQ
262 // WQL_AND
263 // WQL_OR
264 //
265
266 Array<WQLOperation> _operations;
267
268 //
|
269 kumpf 1.6 // The list of operands encountered while parsing the WHERE clause. The
|
270 mike 1.2 // query just above would generate the following stream of operands:
271 //
272 // count, 10, peak, 20, state, "OKAY"
273 //
274
275 Array<WQLOperand> _operands;
276
277 void f() const { }
|
278 schuur 1.8
279 friend class CMPI_Wql2Dnf;
|
280 mike 1.2 };
281
282 PEGASUS_NAMESPACE_END
283
284 #endif /* Pegasus_WQLSelectStatement_h */
|