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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2