(file) Return to WQLParser.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WQL

  1 karl  1.9 //%2005////////////////////////////////////////////////////////////////////////
  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 karl  1.6 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 mike  1.2 //
 12           // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.4 // of this software and associated documentation files (the "Software"), to
 14           // deal in the Software without restriction, including without limitation the
 15           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.2 // sell copies of the Software, and to permit persons to whom the Software is
 17           // furnished to do so, subject to the following conditions:
 18           // 
 19 kumpf 1.4 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.4 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27           //
 28           //==============================================================================
 29           //
 30           // Author: Mike Brasher (mbrasher@bmc.com)
 31           //
 32 david.dillard 1.8 // Modified By: David Dillard, VERITAS Software Corp.
 33                   //                  (david.dillard@veritas.com)
 34 mike          1.2 //
 35                   //%/////////////////////////////////////////////////////////////////////////////
 36                   
 37                   #ifndef Pegasus_WQLParser_h
 38                   #define Pegasus_WQLParser_h
 39                   
 40                   #include <Pegasus/Common/Config.h>
 41 kumpf         1.5 #include <Pegasus/Common/ArrayInternal.h>
 42 mike          1.2 #include <Pegasus/WQL/Linkage.h>
 43                   #include <Pegasus/WQL/WQLSelectStatement.h>
 44                   
 45                   PEGASUS_NAMESPACE_BEGIN
 46                   
 47                   /** This class is the main interface to the WQL parser used for parsing WQL1
 48                       compliant SQL statements.
 49                   
 50                       Here's an example which parses a SELECT statement:
 51                   
 52                       <pre>
 53                   	const char TEXT[] = "SELECT X,Y FROM MyClass WHERE X > 10 AND Y < 3";
 54                   
 55                   	// Note that this array must be null-terminated (sizeof(TEXT) includes
 56                   	// the null-terminator in the count).
 57                   
 58 david.dillard 1.8 	Array<char> text(TEXT, sizeof(TEXT));
 59 mike          1.2 
 60                   	WQLSelectStatement selectStatement;
 61                   
 62                   	WQLParser parser;
 63                   
 64                   	try
 65                   	{
 66                   	    parser.parse(text, selectStatement);
 67                   	}
 68                   	catch (ParseError&)
 69                   	{
 70                   	    ...
 71                   	}
 72                   	catch (MissingNullTerminator&)
 73                   	{
 74                   	    ...
 75                   	}
 76                       </pre>
 77                   
 78                       Note that the text must be NULL terminated or else the MissingNullTerminator
 79                       exception is thrown.
 80 mike          1.2 
 81                       The text is read and the result is left in the selectStatement output
 82                       argument.
 83                   
 84                       At this point you might wish to peek at the contents of the selectStatement.
 85                       This may be done by calling WQLSelectStatement::print() like this:
 86                   
 87                       <pre>
 88                   	WQLSelectStatement selectStatement;
 89                   	...
 90                   	selectStatement.print();
 91                       </pre>
 92                   
 93                       For the above query text, the following is printed:
 94                   
 95                       <pre>
 96                   	WQLSelectStatement
 97                   	{
 98                   	    _className: "MyClass"
 99                   
100                   	    _propertyNames[0]: "X"
101 mike          1.2 	    _propertyNames[1]: "Y"
102                   
103                   	    _operations[0]: "WQL_GT"
104                   	    _operations[1]: "WQL_LT"
105                   	    _operations[2]: "WQL_AND"
106                   
107                   	    _operands[0]: "PROPERTY_NAME: X"
108                   	    _operands[1]: "INTEGER_VALUE: 10"
109                   	    _operands[2]: "PROPERTY_NAME: Y"
110                   	    _operands[3]: "INTEGER_VALUE: 3"
111                   	}
112                       </pre>
113                   
114                       The WQLSelectStatement::evaluateWhereClause() method may be called to
115                       determine whether a particular instance (whose properties are made 
116                       available to he evaluateWhereClause() by a user implementation of the
117                       WQLPropertySource class). This method returns true, if the where clause
118                       matches this instance. Here is an example:
119                   
120                       <pre>
121                   	WQLSelectStatement selectStatement;
122 mike          1.2 	...
123                   	WQLPropertySource* propertySource = new MyPropertySource(...);
124                   
125                   	if (selectStatement.evaluateWhereClause(propertySource))
126                   	{
127                   	    // It's a match!
128                   	}
129                       </pre>
130                   
131                       The evaluateWhereClause() method calls propertySource->getValue() to
132                       obtain values for each of the properties referred to in where clause (X 
133                       and Y in the above query example).
134                   
135                       The implementer of the WQLPropertySource interface must provide the
136                       implementation of getValue() to produce values for the target data
137                       types. The WQL library makes no assumptions about the nature of the 
138                       target data representation. This was done so that this libary could be
139                       adapted to multiple data representations.
140                   
141                       For use with Pegasus CIMInstance objects, a CIMInstancePropertySource
142                       class could be developed whose getValue() method fetches values from 
143 mike          1.2     a CIMInstance. Here is an example of how it might be used.
144                   
145                       <pre>
146                   	CIMInstancePropertySource* propertySource 
147                   	    = new CIMInstancePropertySource(...);
148                   
149                   	CIMInstance instance;
150                   
151                   	while (instance = GetNextInstance(...))
152                   	{
153                   	    propertySource->setInstance(currentInstance);
154                   
155                   	    if (selectStatement.evaluateWhereClause(propertySource))
156                   	    {
157                   		// It's a match!
158                   	    }
159                   	}
160                       </pre>
161                   
162                       Of course the numeration of instances is left to the user of WQL.
163                   */
164 mike          1.2 class PEGASUS_WQL_LINKAGE WQLParser
165                   {
166                   public:
167                   
168                       /** Parse the SELECT statement given by the text parameter and initialize
169                   	the statement parameter accordingly.
170                   
171                   	Please note that this method is not thread safe. It must be guarded 
172                   	with mutexes by the caller.
173                   
174 mike          1.3 	@param text null-terminated C-string which points to SQL statement.
175 mike          1.2 	@param statement object which holds the compiled version of the SELECT
176                   	    statement upon return.
177                   	@exception ParseError if text is not a valid SELECT statement.
178                   	@exception MissingNullTerminator if text argument is not 
179                   	    terminated with a null. 
180                       */
181                       static void parse(
182 mike          1.3 	const char* text,
183                   	WQLSelectStatement& statement);
184                   
185                       /** Version of parse() taking an array of characters.
186                       */
187                       static void parse(
188 david.dillard 1.8 	const Array<char>& text,
189 mike          1.3 	WQLSelectStatement& statement);
190                   
191                       /** Version of parse() taking a string.
192                       */
193                       static void parse(
194                   	const String& text,
195 mike          1.2 	WQLSelectStatement& statement);
196                   
197                   private:
198                   
199                       /** This method cleans up all the strings which were created by LEX and
200                   	passed to YACC. These strings cannot be cleaned up by YACC actions
201                   	since the actions that clean up certain strings are not always reached
202                   	when errors occur.
203                       */
204                       static void cleanup();
205                   
206                       /** Private constructor to avoid user from creating instance of this class.
207                       */
208                       WQLParser() { }
209                   };
210                   
211                   PEGASUS_NAMESPACE_END
212                   
213                   #endif /* Pegasus_WQLParser_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2