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