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