1 mike 1.1.2.1 //%/////////////////////////////////////////////////////////////////////////////
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.1.2.1 //==============================================================================
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/Common/CIMInstance.h>
37 #include <Pegasus/WQL/WQLOperation.h>
38 #include <Pegasus/WQL/WQLOperand.h>
39
40 PEGASUS_NAMESPACE_BEGIN
41
42 /** This class represents a compiled WBEMSQl1 select statement.
43 mike 1.1.2.1
44 An instance of WQLSelectStatement is passed to WQLParser::parse() which
45 parses and WBEMSQL1 SELECT statement and initializes the WQLSelectStatement
46 instance. The WBEMSWL1 SELECT statement has the following form:
47
48 <pre>
49 SELECT <property>...
50 FROM <class name>
51 WHERE <where clause>
52 </pre>
53
54 The properties may be obtained with the getProperties() method.
55 The class name may be obtained with getClassName(). The where clause
56 may be evaluated by calling evaluateWhereClause() with the appropriate
57 arguments. If hasWhereClause() returns false, then there is no where
58 clause.
59
60 The components of the where clause are stored in two arrays: one for
61 operands and one for operators (these are placed in proper order by the
62 YACC parser). Evaluation is performed using a Boolean stack. See the
63 implementation of evaluateWhereClause() for details.
64 mike 1.1.2.1 */
65 class PEGASUS_WQL_LINKAGE WQLSelectStatement
66 {
67 public:
68
69 /** Default constructor.
70 */
71 WQLSelectStatement();
72
73 /** Destructor.
74 */
75 ~WQLSelectStatement();
76
77 /** Clears all data members of this object.
78 */
79 void clear();
80
81 /** Accessor.
82 */
83 const String& getClassName() const
84 {
85 mike 1.1.2.1 return _className;
86 }
87
88 /** Modifier. This method should not be called by the user (only by the
89 parser).
90 */
91 void setClassName(const String& className)
92 {
93 _className = className;
94 }
95
96 /** Returns the number of property names which were indicated in the
97 selection list.
98 */
99 Uint32 getPropertyNameCount() const
100 {
101 return _propertyNames.size();
102 }
103
104 /** Gets the i-th property name in the list.
105 */
106 mike 1.1.2.1 const String& getPropertyName(Uint32 i)
107 {
108 return _propertyNames[i];
109 }
110
111 /** Appends a property name to the property name list. This user should
112 not call this method; it should only be called by the parser.
113 */
114 void appendPropertyName(const String& x)
115 {
116 _propertyNames.append(x);
117 }
118
119 /** Appends an operation to the operation array. This method should only
120 be called by the parser itself.
121 */
122 void appendOperation(WQLOperation x)
123 {
124 _operations.append(x);
125 }
126
127 mike 1.1.2.1 /** Appends an operand to the operation array. This method should only
128 be called by the parser itself.
129 */
130 void appendOperand(const WQLOperand& x)
131 {
132 _operands.append(x);
133 }
134
135 /** Returns true if this class has a where clause.
136 */
137 Boolean hasWhereClause() const
138 {
139 return _operations.size() != 0;
140 }
141
142 /** Evalautes the where clause using the CIMInstance as input.
143 */
144 Boolean evaluateWhereClause(const CIMInstance& instance) const;
145
146 /** Prints out the members of this class.
147 */
148 mike 1.1.2.1 void print() const;
149
150 private:
151
152 //
153 // The name of the target class. For example:
154 //
155 // SELECT *
156 // FROM TargetClass
157 // WHERE ...
158 //
159
160 String _className;
161
162 //
163 // The list of property names being selected. For example, see "firstName",
164 // and "lastName" below.
165 //
166 // SELECT firstName, lastName
167 // FROM TargetClass
168 // WHERE ...
169 mike 1.1.2.1 //
170
171 Array<String> _propertyNames;
172
173 //
174 // The list of operations encountered while parsing the WHERE clause.
175 // Consider this query:
176 //
177 // SELECT *
178 // FROM TargetClass
179 // WHERE count > 10 OR peak < 20 AND state = "OKAY"
180 //
181 // This would generate the following stream of WQLOperations:
182 //
183 // WQL_GT
184 // WQL_LT
185 // WQL_EQ
186 // WQL_AND
187 // WQL_OR
188 //
189
190 mike 1.1.2.1 Array<WQLOperation> _operations;
191
192 //
193 // The list of operands encountered while parsing the WHERE clause. They
194 // query just above would generate the following stream of operands:
195 //
196 // count, 10, peak, 20, state, "OKAY"
197 //
198
199 Array<WQLOperand> _operands;
200 };
201
202 PEGASUS_NAMESPACE_END
203
204 #endif /* Pegasus_WQLSelectStatement_h */
|