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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2