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

  1 karl  1.7 //%2004////////////////////////////////////////////////////////////////////////
  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 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 david.dillard 1.8 // Modified By: David Dillard, VERITAS Software Corp.
 31                   //                  (david.dillard@veritas.com)
 32 mike          1.2 //
 33                   //%/////////////////////////////////////////////////////////////////////////////
 34                   
 35                   #ifndef Pegasus_WQLParser_h
 36                   #define Pegasus_WQLParser_h
 37                   
 38                   #include <Pegasus/Common/Config.h>
 39 kumpf         1.5 #include <Pegasus/Common/ArrayInternal.h>
 40 mike          1.2 #include <Pegasus/WQL/Linkage.h>
 41                   #include <Pegasus/WQL/WQLSelectStatement.h>
 42                   
 43                   PEGASUS_NAMESPACE_BEGIN
 44                   
 45                   /** This class is the main interface to the WQL parser used for parsing WQL1
 46                       compliant SQL statements.
 47                   
 48                       Here's an example which parses a SELECT statement:
 49                   
 50                       <pre>
 51                   	const char TEXT[] = "SELECT X,Y FROM MyClass WHERE X > 10 AND Y < 3";
 52                   
 53                   	// Note that this array must be null-terminated (sizeof(TEXT) includes
 54                   	// the null-terminator in the count).
 55                   
 56 david.dillard 1.8 	Array<char> text(TEXT, sizeof(TEXT));
 57 mike          1.2 
 58                   	WQLSelectStatement selectStatement;
 59                   
 60                   	WQLParser parser;
 61                   
 62                   	try
 63                   	{
 64                   	    parser.parse(text, selectStatement);
 65                   	}
 66                   	catch (ParseError&)
 67                   	{
 68                   	    ...
 69                   	}
 70                   	catch (MissingNullTerminator&)
 71                   	{
 72                   	    ...
 73                   	}
 74                       </pre>
 75                   
 76                       Note that the text must be NULL terminated or else the MissingNullTerminator
 77                       exception is thrown.
 78 mike          1.2 
 79                       The text is read and the result is left in the selectStatement output
 80                       argument.
 81                   
 82                       At this point you might wish to peek at the contents of the selectStatement.
 83                       This may be done by calling WQLSelectStatement::print() like this:
 84                   
 85                       <pre>
 86                   	WQLSelectStatement selectStatement;
 87                   	...
 88                   	selectStatement.print();
 89                       </pre>
 90                   
 91                       For the above query text, the following is printed:
 92                   
 93                       <pre>
 94                   	WQLSelectStatement
 95                   	{
 96                   	    _className: "MyClass"
 97                   
 98                   	    _propertyNames[0]: "X"
 99 mike          1.2 	    _propertyNames[1]: "Y"
100                   
101                   	    _operations[0]: "WQL_GT"
102                   	    _operations[1]: "WQL_LT"
103                   	    _operations[2]: "WQL_AND"
104                   
105                   	    _operands[0]: "PROPERTY_NAME: X"
106                   	    _operands[1]: "INTEGER_VALUE: 10"
107                   	    _operands[2]: "PROPERTY_NAME: Y"
108                   	    _operands[3]: "INTEGER_VALUE: 3"
109                   	}
110                       </pre>
111                   
112                       The WQLSelectStatement::evaluateWhereClause() method may be called to
113                       determine whether a particular instance (whose properties are made 
114                       available to he evaluateWhereClause() by a user implementation of the
115                       WQLPropertySource class). This method returns true, if the where clause
116                       matches this instance. Here is an example:
117                   
118                       <pre>
119                   	WQLSelectStatement selectStatement;
120 mike          1.2 	...
121                   	WQLPropertySource* propertySource = new MyPropertySource(...);
122                   
123                   	if (selectStatement.evaluateWhereClause(propertySource))
124                   	{
125                   	    // It's a match!
126                   	}
127                       </pre>
128                   
129                       The evaluateWhereClause() method calls propertySource->getValue() to
130                       obtain values for each of the properties referred to in where clause (X 
131                       and Y in the above query example).
132                   
133                       The implementer of the WQLPropertySource interface must provide the
134                       implementation of getValue() to produce values for the target data
135                       types. The WQL library makes no assumptions about the nature of the 
136                       target data representation. This was done so that this libary could be
137                       adapted to multiple data representations.
138                   
139                       For use with Pegasus CIMInstance objects, a CIMInstancePropertySource
140                       class could be developed whose getValue() method fetches values from 
141 mike          1.2     a CIMInstance. Here is an example of how it might be used.
142                   
143                       <pre>
144                   	CIMInstancePropertySource* propertySource 
145                   	    = new CIMInstancePropertySource(...);
146                   
147                   	CIMInstance instance;
148                   
149                   	while (instance = GetNextInstance(...))
150                   	{
151                   	    propertySource->setInstance(currentInstance);
152                   
153                   	    if (selectStatement.evaluateWhereClause(propertySource))
154                   	    {
155                   		// It's a match!
156                   	    }
157                   	}
158                       </pre>
159                   
160                       Of course the numeration of instances is left to the user of WQL.
161                   */
162 mike          1.2 class PEGASUS_WQL_LINKAGE WQLParser
163                   {
164                   public:
165                   
166                       /** Parse the SELECT statement given by the text parameter and initialize
167                   	the statement parameter accordingly.
168                   
169                   	Please note that this method is not thread safe. It must be guarded 
170                   	with mutexes by the caller.
171                   
172 mike          1.3 	@param text null-terminated C-string which points to SQL statement.
173 mike          1.2 	@param statement object which holds the compiled version of the SELECT
174                   	    statement upon return.
175                   	@exception ParseError if text is not a valid SELECT statement.
176                   	@exception MissingNullTerminator if text argument is not 
177                   	    terminated with a null. 
178                       */
179                       static void parse(
180 mike          1.3 	const char* text,
181                   	WQLSelectStatement& statement);
182                   
183                       /** Version of parse() taking an array of characters.
184                       */
185                       static void parse(
186 david.dillard 1.8 	const Array<char>& text,
187 mike          1.3 	WQLSelectStatement& statement);
188                   
189                       /** Version of parse() taking a string.
190                       */
191                       static void parse(
192                   	const String& text,
193 mike          1.2 	WQLSelectStatement& statement);
194                   
195                   private:
196                   
197                       /** This method cleans up all the strings which were created by LEX and
198                   	passed to YACC. These strings cannot be cleaned up by YACC actions
199                   	since the actions that clean up certain strings are not always reached
200                   	when errors occur.
201                       */
202                       static void cleanup();
203                   
204                       /** Private constructor to avoid user from creating instance of this class.
205                       */
206                       WQLParser() { }
207                   };
208                   
209                   PEGASUS_NAMESPACE_END
210                   
211                   #endif /* Pegasus_WQLParser_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2