1 mike 1.2 //%/////////////////////////////////////////////////////////////////////////////
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.2 //==============================================================================
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 #include <Pegasus/WQL/WQLPropertySource.h>
39
40 PEGASUS_NAMESPACE_BEGIN
41
42 /** This class represents a compiled WQL1 select statement.
43 mike 1.2
44 An instance of WQLSelectStatement is passed to WQLParser::parse() which
45 parses the WQL1 SELECT statement and initializes the WQLSelectStatement
46 instance. A WQL1 SELECT statement has the following form:
47
48 <pre>
49 SELECT <property>...
50 FROM <class name>
51 WHERE <where clause>
52 </pre>
53
54 There are methods for obtaining the various elements of the select
55 statement.
56
57 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 mike 1.2 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 /** Accessor.
79 */
80 const String& getClassName() const
81 {
82 return _className;
83 }
84
85 mike 1.2 /** 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 Uint32 getSelectPropertyNameCount() const
97 {
98 return _selectPropertyNames.size();
99 }
100
101 /** Gets the i-th selected property name in the list.
102 */
103 const String& getSelectPropertyName(Uint32 i)
104 {
105 return _selectPropertyNames[i];
106 mike 1.2 }
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 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 {
127 mike 1.2 return _wherePropertyNames[i];
128 }
129
130 /** 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 /** 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 mike 1.2 */
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 }
160
161 /** Evalautes the where clause using the symbol table to resolve symbols.
162 */
163 Boolean evaluateWhereClause(const WQLPropertySource* source) const;
164
165 /** Prints out the members of this class.
166 */
167 void print() const;
168
169 mike 1.2 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 // SELECT firstName, lastName
186 // FROM TargetClass
187 // WHERE ...
188 //
189
190 mike 1.2 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
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 mike 1.2 // WQL_LT
212 // WQL_EQ
213 // WQL_AND
214 // WQL_OR
215 //
216
217 Array<WQLOperation> _operations;
218
219 //
220 // 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
228 void f() const { }
229 };
230
231 PEGASUS_NAMESPACE_END
232 mike 1.2
233 #endif /* Pegasus_WQLSelectStatement_h */
|