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

  1 karl  1.11 //%2006////////////////////////////////////////////////////////////////////////
  2 chuck 1.1  //
  3            // 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            // IBM Corp.; EMC Corporation, The Open Group.
  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.2  // 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 chuck 1.1  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // 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            // 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 karl  1.11 // 
 21 chuck 1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // 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            // 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            // 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            // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
 35 david.dillard 1.3  //                  (carolann_graves@hp.com)
 36                    //              David Dillard, VERITAS Software Corp.
 37                    //                  (david.dillard@veritas.com)
 38 chuck         1.1  //
 39                    //%/////////////////////////////////////////////////////////////////////////////
 40                    
 41                    #include <iostream>
 42                    #include <Pegasus/Common/Stack.h>
 43                    #include "WQLSelectStatementRep.h"
 44                    #include <Pegasus/Query/QueryCommon/QueryContext.h>
 45                    #include <Pegasus/Query/QueryCommon/QueryException.h>
 46                    #include "WQLInstancePropertySource.h"
 47                    PEGASUS_USING_STD;
 48                    
 49                    PEGASUS_NAMESPACE_BEGIN
 50                    
 51                    template<class T>
 52                    inline static Boolean _Compare(const T& x, const T& y, WQLOperation op)
 53                    {
 54                        switch (op)
 55                        {
 56 david.dillard 1.3  	case WQL_EQ:
 57 chuck         1.1  	    return x == y;
 58                    
 59 david.dillard 1.3  	case WQL_NE:
 60 chuck         1.1  	    return x != y;
 61                    
 62 david.dillard 1.3  	case WQL_LT:
 63 chuck         1.1  	    return x < y;
 64 david.dillard 1.3  	case WQL_LE:
 65 chuck         1.1  	    return x <= y;
 66                    
 67 david.dillard 1.3  	case WQL_GT:
 68 chuck         1.1  	    return x > y;
 69                    
 70 david.dillard 1.3  	case WQL_GE:
 71 chuck         1.1  	    return x >= y;
 72                    
 73                    	default:
 74                    	    PEGASUS_ASSERT(0);
 75                        }
 76                    
 77 gs.keenan     1.6      return false;
 78 chuck         1.1  }
 79                    
 80                    static Boolean _Evaluate(
 81 david.dillard 1.3      const WQLOperand& lhs,
 82                        const WQLOperand& rhs,
 83 chuck         1.1      WQLOperation op)
 84                    {
 85                        switch (lhs.getType())
 86                        {
 87                    	case WQLOperand::NULL_VALUE:
 88                    	{
 89 dave.sudlik   1.10 #ifdef PEGASUS_SNIA_EXTENSIONS
 90                                return (rhs.getType() == WQLOperand::NULL_VALUE);
 91                    #else
 92 chuck         1.1  	    // This cannot happen since expressions of the form
 93                    	    // OPERAND OPERATOR NULL are converted to unary form.
 94                    	    // For example: "count IS NULL" is treated as a unary
 95                    	    // operation in which IS_NULL is the unary operation
 96                    	    // and count is the the unary operand.
 97                    
 98                    	    PEGASUS_ASSERT(0);
 99                    	    break;
100 dave.sudlik   1.10 #endif
101 chuck         1.1  	}
102                    
103                    	case WQLOperand::INTEGER_VALUE:
104                    	{
105                    	    return _Compare(
106                    		lhs.getIntegerValue(),
107                    		rhs.getIntegerValue(),
108                    		op);
109                    	}
110                    
111                    	case WQLOperand::DOUBLE_VALUE:
112                    	{
113                    	    return _Compare(
114                    		lhs.getDoubleValue(),
115                    		rhs.getDoubleValue(),
116                    		op);
117                    	}
118                    
119                    	case WQLOperand::BOOLEAN_VALUE:
120                    	{
121                    	    return _Compare(
122 chuck         1.1  		lhs.getBooleanValue(),
123                    		rhs.getBooleanValue(),
124                    		op);
125                    	}
126                    
127                    	case WQLOperand::STRING_VALUE:
128                    	{
129                    	    return _Compare(
130                    		lhs.getStringValue(),
131                    		rhs.getStringValue(),
132                    		op);
133                    	}
134                    
135                    	default:
136                    	    PEGASUS_ASSERT(0);
137                        }
138                    
139                        return false;
140                    }
141                    
142                    WQLSelectStatementRep::WQLSelectStatementRep(String& queryLang, String& query)
143 chuck         1.1  	:SelectStatementRep(queryLang,query)
144                    {
145                        _operations.reserveCapacity(16);
146                        _operands.reserveCapacity(16);
147                    
148                        _allProperties = false;
149                    }
150                    
151                    WQLSelectStatementRep::WQLSelectStatementRep(String& queryLang, String& query, QueryContext& inCtx)
152                            :SelectStatementRep(queryLang,query,inCtx)
153                    {
154                        _operations.reserveCapacity(16);
155                        _operands.reserveCapacity(16);
156                    
157                        _allProperties = false;
158                    }
159                    
160                    WQLSelectStatementRep::WQLSelectStatementRep()
161                    	:SelectStatementRep()
162                    {
163                        //
164 chuck         1.1      // Reserve space for a where clause with up to sixteen terms.
165                        //
166                    
167                        _operations.reserveCapacity(16);
168                        _operands.reserveCapacity(16);
169                    
170                        _allProperties = false;
171                    }
172                    
173                    WQLSelectStatementRep::WQLSelectStatementRep(const WQLSelectStatementRep& rep)
174                      :SelectStatementRep(rep),
175                       _className(rep._className),
176                       _allProperties(rep._allProperties),
177                       _selectPropertyNames(rep._selectPropertyNames),
178                       _wherePropertyNames(rep._wherePropertyNames),
179                       _operations(rep._operations),
180                       _operands(rep._operands)
181                    {
182                    }
183                    
184                    WQLSelectStatementRep::~WQLSelectStatementRep()
185 chuck         1.1  {
186                    
187                    }
188                    
189                    void WQLSelectStatementRep::clear()
190                    {
191                        _className.clear();
192                        _allProperties = false;
193                        _selectPropertyNames.clear();
194                        _operations.clear();
195                        _operands.clear();
196                    }
197                    
198                    Boolean WQLSelectStatementRep::getAllProperties() const
199                    {
200                        return _allProperties;
201                    }
202                    
203                    void WQLSelectStatementRep::setAllProperties(const Boolean allProperties)
204                    {
205                        _allProperties = allProperties;
206 chuck         1.1  }
207                    
208 david.dillard 1.7  const CIMPropertyList WQLSelectStatementRep::getSelectPropertyList
209 carolann.graves 1.4      (const CIMObjectPath& inClassName) const
210 chuck           1.1  {
211                          //
212                          //  Check for "*"
213                          //
214                          if (_allProperties)
215                          {
216                              //
217                              //  Return null CIMPropertyList for all properties
218                              //
219                              return CIMPropertyList ();
220                          }
221 carolann.graves 1.4  
222                          CIMName className = inClassName.getClassName();
223                          if (className.isNull())
224                          {
225                              //
226 david.dillard   1.7          //  If the caller passed in an empty className, then the FROM class is
227 carolann.graves 1.4          //  to be used
228                              //
229                              className = _className;
230                          }
231                      
232                          //
233                          //  Check if inClassName is the FROM class
234                          //
235                          if (!(className == _className))
236 chuck           1.1      {
237                              //
238 carolann.graves 1.4          //  Check for NULL Query Context
239                              //
240                              if (_ctx == NULL)
241                              {
242                                  MessageLoaderParms parms
243                                      ("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
244                                      "Trying to process a query with a NULL Query Context.");
245 david.dillard   1.7              throw QueryRuntimeException(parms);
246 carolann.graves 1.4          }
247                      
248                              //
249                              //  Check if inClassName is a subclass of the FROM class
250 chuck           1.1          //
251 carolann.graves 1.4          if (!_ctx->isSubClass(_className,className))
252                              {
253                                  MessageLoaderParms parms
254                                      ("WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",
255                                      "Class $0 does not match the FROM class or any of its "
256                                      "subclasses.",
257                                      className.getString());
258                                  throw QueryRuntimeException(parms);
259                              }
260 chuck           1.1      }
261 carolann.graves 1.4  
262                          //
263 david.dillard   1.7      //  Return CIMPropertyList for properties referenced in the projection
264 carolann.graves 1.4      //  list (SELECT clause)
265                          //
266                          return CIMPropertyList (_selectPropertyNames);
267 chuck           1.1  }
268                      
269 david.dillard   1.7  const CIMPropertyList WQLSelectStatementRep::getWherePropertyList
270 carolann.graves 1.4      (const CIMObjectPath& inClassName) const
271 chuck           1.1  {
272 carolann.graves 1.4      CIMName className = inClassName.getClassName();
273                          if (className.isNull())
274                          {
275                              //
276 david.dillard   1.7          //  If the caller passed in an empty className, then the FROM class is
277 carolann.graves 1.4          //  to be used
278                              //
279                              className = _className;
280                          }
281                      
282                          //
283                          //  Check if inClassName is the FROM class
284                          //
285                          if (!(className == _className))
286                          {
287                              //
288                              //  Check for NULL Query Context
289                              //
290                              if (_ctx == NULL)
291                              {
292                                  MessageLoaderParms parms
293                                      ("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
294                                      "Trying to process a query with a NULL Query Context.");
295 david.dillard   1.7              throw QueryRuntimeException(parms);
296 carolann.graves 1.4          }
297                      
298                              //
299                              //  Check if inClassName is a subclass of the FROM class
300                              //
301                              if (!_ctx->isSubClass(_className,className))
302                              {
303                                  MessageLoaderParms parms
304                                      ("WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",
305                                      "Class $0 does not match the FROM class or any of its "
306                                      "subclasses.",
307                                      className.getString());
308                                  throw QueryRuntimeException(parms);
309                              }
310                          }
311                      
312 chuck           1.1      //
313 david.dillard   1.3      //  Return CIMPropertyList for properties referenced in the condition
314 chuck           1.1      //  (WHERE clause)
315                          //  The list may be empty, but may not be NULL
316                          //
317                          return CIMPropertyList (_wherePropertyNames);
318                      }
319                      
320                      Boolean WQLSelectStatementRep::appendWherePropertyName(const CIMName& x)
321                      {
322                          //
323                          // Reject duplicate property names by returning false.
324                          //
325                      
326                          for (Uint32 i = 0, n = _wherePropertyNames.size(); i < n; i++)
327                          {
328                      	if (_wherePropertyNames[i] == x)
329                      	    return false;
330                          }
331                      
332                          //
333                          // Append the new property.
334                          //
335 chuck           1.1  
336                          _wherePropertyNames.append(x);
337                          return true;
338                      }
339                      
340                      static inline void _ResolveProperty(
341                          WQLOperand& op,
342                          const WQLPropertySource* source)
343                      {
344                          //
345                          // Resolve the operand: if it's a property name, look up its value:
346                          //
347                      
348                          if (op.getType() == WQLOperand::PROPERTY_NAME)
349                          {
350                      	const CIMName& propertyName = op.getPropertyName();
351                      
352                      	if (!source->getValue(propertyName, op))
353                      	    op = WQLOperand();
354                          }
355                      }
356 chuck           1.1  
357                      Boolean WQLSelectStatementRep::evaluateWhereClause(
358                          const WQLPropertySource* source) const
359                      {
360                          if (!hasWhereClause())
361                      	return true;
362                      
363                          Stack<Boolean> stack;
364                          stack.reserveCapacity(16);
365                      
366 david.dillard   1.3      //
367 chuck           1.1      // Counter for operands:
368                          //
369                      
370                          Uint32 j = 0;
371                      
372                          //
373                          // Process each of the operations:
374                          //
375                      
376                          for (Uint32 i = 0, n = _operations.size(); i < n; i++)
377                          {
378                      	WQLOperation op = _operations[i];
379                      
380                      	switch (op)
381                      	{
382                      	    case WQL_OR:
383                      	    {
384                      		PEGASUS_ASSERT(stack.size() >= 2);
385                      
386                      		Boolean op1 = stack.top();
387                      		stack.pop();
388 chuck           1.1  
389                      		Boolean op2 = stack.top();
390                      
391                      		stack.top() = op1 || op2;
392                      		break;
393                      	    }
394                      
395                      	    case WQL_AND:
396                      	    {
397                      		PEGASUS_ASSERT(stack.size() >= 2);
398                      
399                      		Boolean op1 = stack.top();
400                      		stack.pop();
401                      
402                      		Boolean op2 = stack.top();
403                      
404                      		stack.top() = op1 && op2;
405                      		break;
406                      	    }
407                      
408                      	    case WQL_NOT:
409 chuck           1.1  	    {
410                      		PEGASUS_ASSERT(stack.size() >= 1);
411                      
412                      		Boolean op = stack.top();
413                      		stack.top() = !op;
414                      		break;
415                      	    }
416                      
417                      	    case WQL_EQ:
418                      	    case WQL_NE:
419                      	    case WQL_LT:
420                      	    case WQL_LE:
421                      	    case WQL_GT:
422                      	    case WQL_GE:
423                      	    {
424                      		Array<WQLOperand> whereOperands(_operands);
425                      		PEGASUS_ASSERT(whereOperands.size() >= 2);
426                      
427                      		//
428                      		// Resolve the left-hand-side to a value (if not already
429                      		// a value).
430 chuck           1.1  		//
431                      
432                      		WQLOperand& lhs = whereOperands[j++];
433                      		_ResolveProperty(lhs, source);
434                      
435                      		//
436                      		// Resolve the right-hand-side to a value (if not already
437                      		// a value).
438                      		//
439                      
440                      		WQLOperand& rhs = whereOperands[j++];
441                      		_ResolveProperty(rhs, source);
442                      
443                      		//
444                      		// Check for a type mismatch:
445                      		//
446                      
447                      		// PEGASUS_OUT(lhs.toString());
448                      		// PEGASUS_OUT(rhs.toString());
449                      
450                      		if (rhs.getType() != lhs.getType())
451 chuck           1.1  		    throw TypeMismatchException();
452                      
453                      		//
454                      		// Now that the types are known to be alike, apply the
455                      		// operation:
456                      		//
457                      
458                      		stack.push(_Evaluate(lhs, rhs, op));
459                      		break;
460                      	    }
461                      
462                      	    case WQL_IS_TRUE:
463                      	    case WQL_IS_NOT_FALSE:
464                      	    {
465                      		PEGASUS_ASSERT(stack.size() >= 1);
466                      		break;
467                      	    }
468                      
469                      	    case WQL_IS_FALSE:
470                      	    case WQL_IS_NOT_TRUE:
471                      	    {
472 chuck           1.1  		PEGASUS_ASSERT(stack.size() >= 1);
473                      		stack.top() = !stack.top();
474                      		break;
475                      	    }
476                      
477                      	    case WQL_IS_NULL:
478                      	    {
479                      		Array<WQLOperand> whereOperands(_operands);
480                      		PEGASUS_ASSERT(whereOperands.size() >= 1);
481                      		WQLOperand& op = whereOperands[j++];
482                      		_ResolveProperty(op, source);
483                      		stack.push(op.getType() == WQLOperand::NULL_VALUE);
484                      		break;
485                      	    }
486                      
487                      	    case WQL_IS_NOT_NULL:
488                      	    {
489                      		Array<WQLOperand> whereOperands(_operands);
490                      		PEGASUS_ASSERT(whereOperands.size() >= 1);
491                      		WQLOperand& op = whereOperands[j++];
492                      		_ResolveProperty(op, source);
493 chuck           1.1  		stack.push(op.getType() != WQLOperand::NULL_VALUE);
494                      		break;
495                      	    }
496                      	}
497                          }
498                      
499                          PEGASUS_ASSERT(stack.size() == 1);
500                          return stack.top();
501                      }
502                      
503 kumpf           1.9  template<class T>
504                      inline void wqlSelectStatementApplyProjection(
505                          T& object,
506                          Boolean allowMissing,
507                          const Array<CIMName>& selectPropertyNames)
508                      {
509                          for (int i=object.getPropertyCount(); i!=0; i--)
510                          {
511                              CIMName pn=object.getProperty(i-1).getName();
512                              Boolean foundInSel = false;
513                              for (int ii=0,mm=selectPropertyNames.size(); ii<mm; ii++)
514                              {
515                                  if (selectPropertyNames[ii]==pn)
516                                  {
517                                     foundInSel = true;
518                                     break;
519                                  }
520                              }
521                      
522                              if (!foundInSel)
523                              {
524 kumpf           1.9              object.removeProperty(i-1);
525                              }
526                          }
527                      
528                          //check for properties on select list missing from the instance
529                          if (!allowMissing)
530                          {
531                              Boolean foundInInst;
532                              for (Uint32 i=0; i < selectPropertyNames.size(); i++)
533                              {
534                                  foundInInst = false;
535                                  CIMName sn=selectPropertyNames[i];
536                                  for (Uint32 j = object.getPropertyCount(); j != 0; j--)
537                                  {
538                                      CIMName in = object.getProperty(j-1).getName();
539                                      if (sn == in) foundInInst = true;
540                                  }
541                      
542                                  if(!foundInInst)
543                                  {
544                                      MessageLoaderParms parms
545 kumpf           1.9                      ("WQL.WQLSelectStatementRep.MISSING_PROPERTY_ON_INSTANCE",
546                                          "A property in the Select list is missing from the "
547                                          "instance");
548                                      throw QueryRuntimePropertyException(parms);
549                                  }
550                              }
551                          }
552                      }
553                      
554 carolann.graves 1.4  void WQLSelectStatementRep::applyProjection(CIMInstance& ci,
555 david.dillard   1.7      Boolean allowMissing)
556 chuck           1.1  {
557 kumpf           1.9      if (_allProperties)
558                          {
559                              return;
560                          }
561                      
562                          wqlSelectStatementApplyProjection(ci, allowMissing, _selectPropertyNames);
563 chuck           1.8  }
564                      
565                      void WQLSelectStatementRep::applyProjection(CIMObject& ci,
566                          Boolean allowMissing)
567                      {
568 kumpf           1.9      if (_allProperties)
569                          {
570                              return;
571                          }
572 chuck           1.1  
573 kumpf           1.9      wqlSelectStatementApplyProjection(ci, allowMissing, _selectPropertyNames);
574 chuck           1.1  }
575                      
576                      void WQLSelectStatementRep::print() const
577                      {
578                          //
579                          // Print the header:
580                          //
581 david.dillard   1.3  
582 chuck           1.1      cout << "WQLSelectStatement" << endl;
583                          cout << "{" << endl;
584                      
585                          //
586                          // Print the class name:
587                          //
588                      
589                          cout << "    _className: \"" << _className.getString() << '"' << endl;
590                      
591 david.dillard   1.3      //
592 chuck           1.1      // Print the select properties:
593                          //
594                      
595                          if (_allProperties)
596                          {
597                              cout << endl;
598                              cout << "    _allProperties: TRUE" << endl;
599                          }
600                      
601                          else for (Uint32 i = 0; i < _selectPropertyNames.size(); i++)
602                          {
603                      	if (i == 0)
604                      	    cout << endl;
605                      
606                      	cout << "    _selectPropertyNames[" << i << "]: ";
607                      	cout << '"' << _selectPropertyNames[i].getString() << '"' << endl;
608                          }
609                      
610                          //
611                          // Print the operations:
612                          //
613 chuck           1.1  
614                          for (Uint32 i = 0; i < _operations.size(); i++)
615                          {
616                              if (i == 0)
617                                  cout << endl;
618                      
619                              cout << "    _operations[" << i << "]: ";
620                              cout << '"' << WQLOperationToString(_operations[i]) << '"' << endl;
621                          }
622                      
623                          //
624                          // Print the operands:
625                          //
626                      
627                          for (Uint32 i = 0; i < _operands.size(); i++)
628                          {
629                              if (i == 0)
630                      	    cout << endl;
631                      
632                      	cout << "    _operands[" << i << "]: ";
633                      	cout << '"' << _operands[i].toString() << '"' << endl;
634 chuck           1.1      }
635                      
636                          //
637                          // Print the trailer:
638                          //
639                      
640                          cout << "}" << endl;
641                      }
642                      
643                      Boolean WQLSelectStatementRep::evaluate(const CIMInstance& inCI)
644                      {
645                      	WQLInstancePropertySource source(inCI);
646                      	return evaluateWhereClause(&source);
647                      }
648 david.dillard   1.3  
649 david.dillard   1.7  void WQLSelectStatementRep::validate()
650 chuck           1.1  {
651                      	if(_ctx == NULL){
652                      		MessageLoaderParms parms("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
653                                                     "Trying to process a query with a NULL Query Context.");
654                            throw QueryValidationException(parms);
655                         }
656                      	CIMClass fromClass;
657                      	try
658                         {
659                           fromClass = _ctx->getClass(_className);
660 david.dillard   1.7  
661 carolann.graves 1.4      CIMObjectPath className (String::EMPTY, _ctx->getNamespace (), _className);
662 david.dillard   1.7       Array<CIMName> whereProps =
663 carolann.graves 1.4          getWherePropertyList(className).getPropertyNameArray();
664 david.dillard   1.7       Array<CIMName> selectProps =
665 carolann.graves 1.4          getSelectPropertyList(className).getPropertyNameArray();
666 david.dillard   1.3  
667 carolann.graves 1.4       // make sure all properties match properties on the from class
668 chuck           1.1       for(Uint32 i = 0; i < whereProps.size(); i++){
669                               Uint32 index = fromClass.findProperty(whereProps[i]);
670                      			if(index == PEG_NOT_FOUND){
671                      				MessageLoaderParms parms("WQL.WQLSelectStatementRep.PROP_NOT_FOUND",
672                                                           "The property $0 was not found in the FROM class $1",
673                                                           whereProps[i].getString(),
674                                                           fromClass.getClassName().getString());
675                                  throw QueryMissingPropertyException(parms);
676                      			}
677                               else
678                               {
679                                 //
680                                 //  Property exists in class
681                                 //  Verify it is not an array property
682                                 //
683                                 CIMProperty classProperty = fromClass.getProperty(index);
684                                 if (classProperty.isArray ())
685                                 {
686                                   MessageLoaderParms parms("WQL.WQLSelectStatementRep.WHERE_PROP_IS_ARRAY",
687                                                            "Array property $0 is not supported in the WQL WHERE clause.",
688                                                           whereProps[i].getString());
689 chuck           1.1               throw QueryValidationException(parms);
690                                 }
691                               }
692                      		}
693                      
694                           for(Uint32 i = 0; i < selectProps.size(); i++){
695                             if(fromClass.findProperty(selectProps[i]) == PEG_NOT_FOUND){
696                               MessageLoaderParms parms("WQL.WQLSelectStatementRep.PROP_NOT_FOUND",
697                                                        "The property $0 was not found in the FROM class $1",
698                                                        selectProps[i].getString(),
699                                                        fromClass.getClassName().getString());
700                               throw QueryMissingPropertyException(parms);
701                             }
702                           }
703                         }
704 david.dillard   1.3     catch (const CIMException& ce)
705 chuck           1.1     {
706                           if (ce.getCode() == CIM_ERR_INVALID_CLASS ||
707                               ce.getCode() == CIM_ERR_NOT_FOUND)
708                           {
709                             MessageLoaderParms parms("WQL.WQLSelectStatementRep.CLASSNAME_NOT_IN_REPOSITORY",
710                                                                       "The class name $0 was not found in the repository.",
711                                                                       _className.getString());
712                             throw QueryValidationException(parms);
713                           }
714                           else
715                           {
716 david.dillard   1.3         throw;
717 chuck           1.1       }
718                         }
719                      }
720 david.dillard   1.3  
721 chuck           1.1  CIMPropertyList WQLSelectStatementRep::getPropertyList(const CIMObjectPath& inClassName)
722                      {
723                      	if(_ctx == NULL){
724                      		MessageLoaderParms parms("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
725                                                     "Trying to process a query with a NULL Query Context.");
726 david.dillard   1.3        throw QueryRuntimeException(parms);
727 chuck           1.1  	}
728                      
729                      	if(_allProperties)
730                           return CIMPropertyList();
731                      
732                      	CIMName className = inClassName.getClassName();
733                        	if (className.isNull())
734                        	{
735                           // If the caller passed in an empty className, then the
736                           // FROM class is to be used.
737                           className = _className;
738                      	}
739                      
740                      	// check if inClassName is the From class
741                      	if(!(className == _className)){
742                      		// check if inClassName is a subclass of the From class
743                      		if(!_ctx->isSubClass(_className,className)){
744                      			MessageLoaderParms parms("WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",
745                                                       "Class $0 does not match the FROM class or any of its subclasses.",
746                                                        className.getString());
747                      			throw QueryRuntimeException(parms);
748 chuck           1.1  		}
749                      	}
750                      
751 david.dillard   1.7  	Array<CIMName> names =
752 carolann.graves 1.4              getWherePropertyList(inClassName).getPropertyNameArray();
753 david.dillard   1.7  	Array<CIMName> selectList =
754 carolann.graves 1.4              getSelectPropertyList(inClassName).getPropertyNameArray();
755 david.dillard   1.7  
756 chuck           1.1  	// check for duplicates and remove them
757                      	for(Uint32 i = 0; i < names.size(); i++){
758                      		for(Uint32 j = 0; j < selectList.size(); j++){
759                      			if(names[i] == selectList[j])
760                      				selectList.remove(j);
761                              	}
762                      	}
763                      
764                      	names.appendArray(selectList);
765                      	CIMPropertyList list = CIMPropertyList();
766                      	list.set(names);
767                      	return list;
768                      }
769                      
770                      Array<CIMObjectPath> WQLSelectStatementRep::getClassPathList()
771                      {
772                      	if(_ctx == NULL){
773                      		MessageLoaderParms parms("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
774                                                               "Trying to process a query with a NULL Query Context.");
775                            throw QueryRuntimeException(parms);
776                         }
777 chuck           1.1  	CIMObjectPath path(String::EMPTY, _ctx->getNamespace(), _className);
778                        	Array<CIMObjectPath> paths;
779                        	paths.append(path);
780                        	return paths;
781                      }
782                      
783                      PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2