1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // CegoPredDesc.cc
4 // ---------------
5 // Cego predicate structure class definition
6 //
7 // Design and Implementation by Bjoern Lemke
8 //
9 // (C)opyright 2000-2019 Bjoern Lemke
10 //
11 // IMPLEMENTATION MODULE
12 //
13 // Class: CegoPredDesc
14 //
15 // Description: The CegoPrdDesc class is a container class for the query predicate representation
16 //
17 // Status: CLEAN
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21 // CEGO INCLUDES
22 #include "CegoPredDesc.h"
23 #include "CegoCondDesc.h"
24 #include "CegoSelect.h"
25 #include "CegoXMLdef.h"
26 #include "CegoDatabaseFormater.h"
27
28 // POSIX INCLUDES
29 #include <string.h>
30 #include <stdlib.h>
31
CegoPredDesc(char * buf,CegoDistManager * pGTM,int tabSetId)32 CegoPredDesc::CegoPredDesc(char* buf, CegoDistManager *pGTM, int tabSetId)
33 {
34 _pExpr1 = 0;
35 _pExpr2 = 0;
36 _pExpr3 = 0;
37 _pC = 0;
38 _pNotPred = 0;
39 _isChecked = false;
40 _pSelect = 0;
41 _pMatcher = 0;
42 decode(buf, pGTM, tabSetId);
43 }
44
CegoPredDesc(Element * pPredElement,CegoDistManager * pGTM)45 CegoPredDesc::CegoPredDesc(Element* pPredElement, CegoDistManager *pGTM)
46 {
47 _pExpr1 = 0;
48 _pExpr2 = 0;
49 _pExpr3 = 0;
50 _pC = 0;
51 _pNotPred = 0;
52 _isChecked = false;
53 _pSelect = 0;
54 _pMatcher = 0;
55 fromElement(pPredElement, pGTM);
56 }
57
CegoPredDesc(CegoExpr * pExpr1,CegoExpr * pExpr2,const CegoComparison & comp)58 CegoPredDesc::CegoPredDesc(CegoExpr *pExpr1, CegoExpr* pExpr2, const CegoComparison& comp)
59 {
60 _pExpr1 = pExpr1;
61 _pExpr2 = pExpr2;
62 _pExpr3 = 0;
63 _comp = comp;
64 _pC = 0;
65 _pNotPred = 0;
66 _mode = CegoPredDesc::EXPRCOMP;
67 _isChecked = false;
68 _pSelect = 0;
69 _pMatcher = 0;
70 }
71
CegoPredDesc(CegoExpr * pExpr1,CegoExpr * pExpr2,CegoExpr * pExpr3)72 CegoPredDesc::CegoPredDesc(CegoExpr *pExpr1, CegoExpr* pExpr2, CegoExpr* pExpr3 )
73 {
74 _pExpr1 = pExpr1;
75 _pExpr2 = pExpr2;
76 _pExpr3 = pExpr3;
77 _pC = 0;
78 _pNotPred = 0;
79 _mode = CegoPredDesc::BETWEEN;
80 _isChecked = false;
81 _pSelect = 0;
82 _pMatcher = 0;
83 }
84
CegoPredDesc(CegoExpr * pExpr,const Chain & pattern,bool isNegated)85 CegoPredDesc::CegoPredDesc(CegoExpr *pExpr, const Chain& pattern, bool isNegated)
86 {
87 _pExpr1 = pExpr;
88 _pExpr2 = 0;
89 _pExpr3 = 0;
90 _pattern = pattern;
91 Chain sqlPattern = Chain("^") + pattern + Chain("$");
92 sqlPattern.replaceAll(Chain("%"), Chain(".*"), sqlPattern);
93 sqlPattern.replaceAll(Chain("_"), Chain("."), sqlPattern);
94
95 _pMatcher = new Matcher(sqlPattern);
96 _pMatcher->prepare();
97
98 if ( isNegated )
99 _mode = CegoPredDesc::ISNOTLIKE;
100 else
101 _mode = CegoPredDesc::ISLIKE;
102
103 _isChecked = false;
104 _pSelect = 0;
105 _pC = 0;
106 _pNotPred = 0;
107 }
108
CegoPredDesc(const CegoPredDesc & p)109 CegoPredDesc::CegoPredDesc(const CegoPredDesc& p)
110 {
111 *this = p;
112 }
113
CegoPredDesc(CegoCondDesc * pC)114 CegoPredDesc::CegoPredDesc(CegoCondDesc *pC)
115 {
116 _pExpr1 = 0;
117 _pExpr2 = 0;
118 _pExpr3 = 0;
119 _pC = pC;
120 _pNotPred = 0;
121 _isChecked = false;
122 _pSelect = 0;
123 _pMatcher = 0;
124 _mode = CegoPredDesc::CONDITION;
125 }
126
CegoPredDesc(CegoPredDesc * pNotPred)127 CegoPredDesc::CegoPredDesc(CegoPredDesc *pNotPred)
128 {
129 _pExpr1 = 0;
130 _pExpr2 = 0;
131 _pExpr3 = 0;
132 _pC = 0;
133 _isChecked = false;
134 _pSelect = 0;
135 _pMatcher = 0;
136 _pNotPred = pNotPred;
137 _mode = CegoPredDesc::NOTPRED;
138 }
139
CegoPredDesc(CegoSelect * pSelect)140 CegoPredDesc::CegoPredDesc(CegoSelect *pSelect)
141 {
142 _pExpr1 = 0;
143 _pExpr2 = 0;
144 _pExpr3 = 0;
145 _pSelect = pSelect;
146 _pMatcher = 0;
147 _pC = 0;
148 _pNotPred = 0;
149 _mode = CegoPredDesc::EXISTSCOMP;
150 _isChecked = false;
151 }
152
CegoPredDesc(CegoExpr * pExpr,ListT<CegoExpr * > & exprList,bool isNegated)153 CegoPredDesc::CegoPredDesc(CegoExpr *pExpr, ListT<CegoExpr*>& exprList, bool isNegated)
154 {
155 _pExpr1 = pExpr;
156 _pExpr2 = 0;
157 _pExpr3 = 0;
158 _exprList = exprList;
159 _pSelect = 0;
160 _pMatcher = 0;
161 _pC = 0;
162 _pNotPred = 0;
163 if ( isNegated )
164 _mode = CegoPredDesc::NOTIN;
165 else
166 _mode = CegoPredDesc::IN;
167 _isChecked = false;
168 }
169
CegoPredDesc(CegoExpr * pExpr,CegoSelect * pSelect,bool isNegated)170 CegoPredDesc::CegoPredDesc(CegoExpr *pExpr, CegoSelect* pSelect, bool isNegated)
171 {
172 _pExpr1 = pExpr;
173 _pExpr2 = 0;
174 _pExpr3 = 0;
175 _pSelect = pSelect;
176 _pMatcher = 0;
177 _pC = 0;
178 _pNotPred = 0;
179 if ( isNegated )
180 _mode = CegoPredDesc::NOTINSUB;
181 else
182 _mode = CegoPredDesc::INSUB;
183 _isChecked = false;
184 }
185
CegoPredDesc(CegoExpr * pExpr,bool isNull)186 CegoPredDesc::CegoPredDesc(CegoExpr* pExpr, bool isNull)
187 {
188 _pExpr1 = pExpr;
189 _pExpr2 = 0;
190 _pExpr3 = 0;
191 _pSelect = 0;
192 _pMatcher = 0;
193 _pC = 0;
194 _pNotPred = 0;
195 if ( isNull )
196 _mode = CegoPredDesc::NULLCOMP;
197 else
198 _mode = CegoPredDesc::NOTNULLCOMP;
199 _isChecked = false;
200 }
201
~CegoPredDesc()202 CegoPredDesc::~CegoPredDesc()
203 {
204 if ( _pExpr1 )
205 {
206 delete _pExpr1;
207 }
208 if ( _pExpr2 )
209 {
210 delete _pExpr2;
211 }
212 if ( _pExpr3 )
213 {
214 delete _pExpr3;
215 }
216 if (_pC)
217 {
218 delete _pC;
219 }
220 if (_pNotPred)
221 {
222 delete _pNotPred;
223 }
224 if (_pSelect)
225 {
226 delete _pSelect;
227 }
228 if (_pMatcher)
229 {
230 delete _pMatcher;
231 }
232 }
233
setTabSetId(int tabSetId)234 void CegoPredDesc::setTabSetId(int tabSetId)
235 {
236 if ( _pExpr1 )
237 {
238 _pExpr1->setTabSetId(tabSetId);
239 }
240 if ( _pExpr2 )
241 {
242 _pExpr2->setTabSetId(tabSetId);
243 }
244 if ( _pExpr3 )
245 {
246 _pExpr3->setTabSetId(tabSetId);
247 }
248 if (_pC)
249 {
250 _pC->setTabSetId(tabSetId);
251 }
252 if (_pNotPred)
253 {
254 _pNotPred->setTabSetId(tabSetId);
255 }
256
257 if (_pSelect)
258 {
259 _pSelect->setTabSetId(tabSetId);
260 }
261 }
262
getPlanList(ListT<Element * > & planList)263 void CegoPredDesc::getPlanList(ListT<Element*>& planList)
264 {
265 if (_pSelect)
266 {
267 planList.Insert( _pSelect->getPlan() );
268 }
269 if ( _pC )
270 {
271 _pC->getPlanList(planList);
272 }
273 if (_pNotPred)
274 {
275 _pNotPred->getPlanList(planList);
276 }
277 if ( _pExpr1 )
278 {
279 _pExpr1->getPlanList(planList);
280 }
281 if ( _pExpr2 )
282 {
283 _pExpr2->getPlanList(planList);
284 }
285 if ( _pExpr3 )
286 {
287 _pExpr3->getPlanList(planList);
288 }
289 }
290
operator =(const CegoPredDesc & p)291 CegoPredDesc& CegoPredDesc::operator = ( const CegoPredDesc& p)
292 {
293 _pExpr1 = p._pExpr1;
294 _pExpr2 = p._pExpr2;
295 _pExpr3 = p._pExpr3;
296 _exprList = p._exprList;
297 _pMatcher = p._pMatcher;
298 _comp = p._comp;
299 _pSelect = p._pSelect;
300 _pC = p._pC;
301 _pNotPred = p._pNotPred;
302 _mode = p._mode;
303 _isChecked = p._isChecked;
304 return (*this);
305 }
306
analyzeSelect()307 void CegoPredDesc::analyzeSelect()
308 {
309 if ( _pSelect )
310 _pSelect->prepare();
311 if ( _pC )
312 {
313 if ( _pC->Left() )
314 _pC->Left()->analyzeSelect();
315 if ( _pC->Right() )
316 _pC->Right()->analyzeSelect();
317 }
318 if ( _pNotPred )
319 {
320 _pNotPred->analyzeSelect();
321 }
322 }
323
getSelectQuery()324 CegoSelect* CegoPredDesc::getSelectQuery()
325 {
326 return _pSelect;
327 }
328
getSelectQueryList(ListT<CegoSelect * > & queryList)329 void CegoPredDesc::getSelectQueryList(ListT<CegoSelect*>& queryList)
330 {
331 if ( _pSelect )
332 queryList.Insert(_pSelect);
333
334 if ( _pExpr1 )
335 {
336 _pExpr1->getSelectQueryList(queryList);
337 }
338 if ( _pExpr2 )
339 {
340 _pExpr2->getSelectQueryList(queryList);
341 }
342 if ( _pExpr3 )
343 {
344 _pExpr3->getSelectQueryList(queryList);
345 }
346
347 CegoExpr** pExpr = _exprList.First();
348 while ( pExpr )
349 {
350 (*pExpr)->getSelectQueryList(queryList);
351 pExpr = _exprList.Next();
352 }
353
354 if ( _pC )
355 {
356 if ( _pC->Left() )
357 _pC->Left()->getSelectQueryList(queryList);
358 if ( _pC->Right() )
359 _pC->Right()->getSelectQueryList(queryList);
360 }
361 if ( _pNotPred )
362 {
363 _pNotPred->getSelectQueryList(queryList);
364 }
365 }
366
getCondition()367 CegoCondDesc* CegoPredDesc::getCondition()
368 {
369 return _pC;
370 }
371
getNotPred()372 CegoPredDesc* CegoPredDesc::getNotPred()
373 {
374 return _pNotPred;
375 }
376
getComparison()377 CegoComparison CegoPredDesc::getComparison()
378 {
379 return _comp;
380 }
381
getMode()382 CegoPredDesc::CompMode CegoPredDesc::getMode()
383 {
384 return _mode;
385 }
386
getExpr1()387 CegoExpr* CegoPredDesc::getExpr1()
388 {
389 return _pExpr1;
390 }
391
getExpr2()392 CegoExpr* CegoPredDesc::getExpr2()
393 {
394 return _pExpr2;
395 }
396
getExpr3()397 CegoExpr* CegoPredDesc::getExpr3()
398 {
399 return _pExpr3;
400 }
401
getExprList()402 ListT<CegoExpr*> CegoPredDesc::getExprList()
403 {
404 return _exprList;
405 }
406
setBlock(CegoProcBlock * pBlock)407 void CegoPredDesc::setBlock(CegoProcBlock* pBlock)
408 {
409 if ( _pExpr1 )
410 {
411 _pExpr1->setBlock(pBlock);
412 }
413 if ( _pExpr2 )
414 {
415 _pExpr2->setBlock(pBlock);
416 }
417 if ( _pExpr3 )
418 {
419 _pExpr3->setBlock(pBlock);
420 }
421
422 CegoExpr** pExpr = _exprList.First();
423 while ( pExpr )
424 {
425 (*pExpr)->setBlock(pBlock);
426 pExpr = _exprList.Next();
427 }
428
429 if ( _pSelect )
430 {
431 _pSelect->setProcBlock(pBlock);
432 }
433 if (_pC)
434 {
435 _pC->Left()->setBlock(pBlock);
436 _pC->Right()->setBlock(pBlock);
437 }
438 if (_pNotPred)
439 {
440 _pNotPred->setBlock(pBlock);
441 }
442 }
443
setChecked(bool val)444 void CegoPredDesc::setChecked(bool val)
445 {
446 _isChecked = val;
447 }
448
clearAttrCache()449 void CegoPredDesc::clearAttrCache()
450 {
451 if ( _pExpr1 )
452 {
453 _pExpr1->clearAttrCache();
454 }
455 if ( _pExpr2 )
456 {
457 _pExpr2->clearAttrCache();
458 }
459 if ( _pExpr3 )
460 {
461 _pExpr3->clearAttrCache();
462 }
463
464 CegoExpr** pExpr = _exprList.First();
465 while ( pExpr )
466 {
467 (*pExpr)->clearAttrCache();
468 pExpr = _exprList.Next();
469 }
470
471 if ( _pC )
472 {
473 if ( _pC->Left() )
474 _pC->Left()->clearAttrCache();
475 if ( _pC->Right() )
476 _pC->Right()->clearAttrCache();
477 }
478 if ( _pNotPred )
479 {
480 _pNotPred->clearAttrCache();
481 }
482 }
483
cleanUp()484 void CegoPredDesc::cleanUp()
485 {
486 if ( _pExpr1 )
487 {
488 _pExpr1->cleanUp();
489 }
490 if ( _pExpr2 )
491 {
492 _pExpr2->cleanUp();
493 }
494 if ( _pExpr3 )
495 {
496 _pExpr3->cleanUp();
497 }
498
499 CegoExpr** pExpr = _exprList.First();
500 while ( pExpr )
501 {
502 (*pExpr)->cleanUp();
503 pExpr = _exprList.Next();
504 }
505
506 if (_pNotPred)
507 {
508 _pNotPred->cleanUp();
509 }
510 if (_pC)
511 {
512 _pC->cleanUp();
513 }
514 if (_pSelect)
515 {
516 _pSelect->cleanUp();
517 }
518 }
519
setCheckedRec(bool val)520 void CegoPredDesc::setCheckedRec(bool val)
521 {
522 _isChecked = val;
523 if ( _pC )
524 {
525 _pC->Left()->setCheckedRec(val);
526 _pC->Right()->setCheckedRec(val);
527 }
528 if ( _pNotPred )
529 {
530 _pNotPred->setChecked(val);
531 }
532 }
533
isChecked() const534 bool CegoPredDesc::isChecked() const
535 {
536 return _isChecked;
537 }
538
hasOrCond() const539 bool CegoPredDesc::hasOrCond() const
540 {
541 if (_pC)
542 {
543 if ( _pC->getCondType() == CegoCondDesc::OR )
544 return true;
545 else if ( _pC->getCondType() == CegoCondDesc::AND )
546 return _pC->Left()->hasOrCond() || _pC->Right()->hasOrCond();
547 else if ( _pC->getCondType() == CegoCondDesc::PRED )
548 return _pC->Left()->hasOrCond();
549 }
550 return false;
551 }
552
getPattern() const553 const Chain& CegoPredDesc::getPattern() const
554 {
555 return _pattern;
556 }
557
match(const CegoFieldValue & val) const558 bool CegoPredDesc::match(const CegoFieldValue& val) const
559 {
560 if ( _pMatcher )
561 return _pMatcher->match(val.valAsChain());
562 else
563 throw Exception(EXLOC, "Invalid matcher in predicate");
564 }
565
encode(char * buf)566 void CegoPredDesc::encode(char *buf)
567 {
568 char* pP = (char*)buf;
569
570 memcpy( pP, &_mode, sizeof(CegoPredDesc::CompMode));
571 pP = pP + sizeof(CegoPredDesc::CompMode);
572
573 switch (_mode )
574 {
575 case CegoPredDesc::CONDITION:
576 {
577 _pC->encode(pP);
578 pP = pP + _pC->getEncodingLength();
579 break;
580 }
581 case CegoPredDesc::NOTPRED:
582 {
583 _pNotPred->encode(pP);
584 pP = pP + _pNotPred->getEncodingLength();
585 break;
586 }
587 case CegoPredDesc::EXPRCOMP:
588 {
589 memcpy( pP, &_comp, sizeof(CegoComparison));
590 pP = pP + sizeof(CegoComparison);
591
592 _pExpr1->encode(pP);
593 pP = pP + _pExpr1->getEncodingLength();
594
595 _pExpr2->encode(pP);
596 pP = pP + _pExpr2->getEncodingLength();
597
598 break;
599 }
600 case CegoPredDesc::BETWEEN:
601 {
602 _pExpr1->encode(pP);
603 pP = pP + _pExpr1->getEncodingLength();
604
605 _pExpr2->encode(pP);
606 pP = pP + _pExpr2->getEncodingLength();
607
608 _pExpr3->encode(pP);
609 pP = pP + _pExpr3->getEncodingLength();
610
611 break;
612 }
613 case CegoPredDesc::NULLCOMP:
614 case CegoPredDesc::NOTNULLCOMP:
615 {
616 _pExpr1->encode(pP);
617 pP = pP + _pExpr1->getEncodingLength();
618 break;
619 }
620 case CegoPredDesc::EXISTSCOMP:
621 {
622 _pSelect->encode(pP);
623 pP = pP + _pSelect->getEncodingLength();
624 break;
625 }
626 case CegoPredDesc::INSUB:
627 case CegoPredDesc::NOTINSUB:
628 {
629 _pExpr1->encode(pP);
630 pP = pP + _pExpr1->getEncodingLength();
631 _pSelect->encode(pP);
632 pP = pP + _pSelect->getEncodingLength();
633 break;
634 }
635 case CegoPredDesc::IN:
636 case CegoPredDesc::NOTIN:
637 {
638 _pExpr1->encode(pP);
639 pP = pP + _pExpr1->getEncodingLength();
640
641 int num = _exprList.Size();
642 memcpy( pP, &num, sizeof(int));
643 pP = pP + sizeof(int);
644
645 CegoExpr** pExpr = _exprList.First();
646 while ( pExpr )
647 {
648 (*pExpr)->encode(pP);
649 pP = pP + (*pExpr)->getEncodingLength();
650 pExpr = _exprList.Next();
651 }
652
653 break;
654 }
655 case CegoPredDesc::ISLIKE:
656 case CegoPredDesc::ISNOTLIKE:
657 {
658 _pExpr1->encode(pP);
659 pP = pP + _pExpr1->getEncodingLength();
660
661 char len = _pattern.length();
662
663 memcpy( pP, &len, sizeof(char));
664 pP = pP + sizeof(char);
665
666 memcpy( pP, (char*)_pattern, len);
667 pP = pP + len;
668
669 break;
670 }
671 }
672 }
673
decode(char * buf,CegoDistManager * pGTM,int tabSetId)674 void CegoPredDesc::decode(char *buf, CegoDistManager *pGTM, int tabSetId)
675 {
676 char* pP = (char*)buf;
677
678 memcpy( &_mode, pP, sizeof(CegoPredDesc::CompMode));
679 pP = pP + sizeof(CegoPredDesc::CompMode);
680
681 // init condition and notpred as zero
682 _pC = 0;
683 _pNotPred = 0;
684 _pSelect = 0;
685 _pExpr1=0;
686 _pExpr2=0;
687 _pExpr3=0;
688
689 switch (_mode )
690 {
691 case CegoPredDesc::CONDITION:
692 {
693 _pC = new CegoCondDesc(pP, pGTM, tabSetId);
694 pP = pP + _pC->getEncodingLength();
695 break;
696 }
697 case CegoPredDesc::NOTPRED:
698 {
699 _pNotPred = new CegoPredDesc(pP, pGTM, tabSetId);
700 pP = pP + _pNotPred->getEncodingLength();
701 break;
702 }
703 case CegoPredDesc::EXPRCOMP:
704 {
705 memcpy( &_comp, pP, sizeof(CegoComparison));
706 pP = pP + sizeof(CegoComparison);
707
708 _pExpr1 = new CegoExpr(pP, pGTM, tabSetId);
709 pP = pP + _pExpr1->getEncodingLength();
710
711 _pExpr2 = new CegoExpr(pP, pGTM, tabSetId);
712 pP = pP + _pExpr2->getEncodingLength();
713
714 break;
715 }
716 case CegoPredDesc::BETWEEN:
717 {
718 _pExpr1 = new CegoExpr(pP, pGTM, tabSetId);
719 pP = pP + _pExpr1->getEncodingLength();
720
721 _pExpr2 = new CegoExpr(pP, pGTM, tabSetId);
722 pP = pP + _pExpr2->getEncodingLength();
723
724 _pExpr3 = new CegoExpr(pP, pGTM, tabSetId);
725 pP = pP + _pExpr3->getEncodingLength();
726
727 break;
728 }
729 case CegoPredDesc::NULLCOMP:
730 case CegoPredDesc::NOTNULLCOMP:
731 {
732 _pExpr1 = new CegoExpr(pP, pGTM, tabSetId);
733 pP = pP + _pExpr1->getEncodingLength();
734 break;
735 }
736 case CegoPredDesc::EXISTSCOMP:
737 {
738 _pSelect = new CegoSelect(pP, pGTM, tabSetId);
739 pP = pP + _pSelect->getEncodingLength();
740 break;
741 }
742 case CegoPredDesc::INSUB:
743 case CegoPredDesc::NOTINSUB:
744 {
745 _pExpr1 = new CegoExpr(pP, pGTM, tabSetId);
746 pP = pP + _pExpr1->getEncodingLength();
747 _pSelect = new CegoSelect(pP, pGTM, tabSetId);
748 pP = pP + _pSelect->getEncodingLength();
749 break;
750 }
751 case CegoPredDesc::IN:
752 case CegoPredDesc::NOTIN:
753 {
754 _pExpr1 = new CegoExpr(pP, pGTM, tabSetId);
755 pP = pP + _pExpr1->getEncodingLength();
756
757 int num;
758 memcpy( &num, pP, sizeof(int));
759 pP = pP + sizeof(int);
760
761 for ( int i=0; i<num; i++ )
762 {
763 CegoExpr *pExpr = new CegoExpr(pP, pGTM, tabSetId);
764 _exprList.Insert(pExpr);
765 pP = pP + pExpr->getEncodingLength();
766 }
767
768 break;
769 }
770 case CegoPredDesc::ISLIKE:
771 case CegoPredDesc::ISNOTLIKE:
772 {
773 _pExpr1 = new CegoExpr(pP, pGTM, tabSetId);
774 pP = pP + _pExpr1->getEncodingLength();
775
776 char len;
777 memcpy( &len, pP, sizeof(char));
778 pP = pP + sizeof(char);
779
780 _pattern = Chain(pP, len);
781 pP = pP + len;
782
783 break;
784 }
785 }
786 }
787
getEncodingLength() const788 int CegoPredDesc::getEncodingLength() const
789 {
790 int len = 0;
791
792 len += sizeof(CegoPredDesc::CompMode);
793
794 switch (_mode )
795 {
796 case CegoPredDesc::CONDITION:
797 {
798 len += _pC->getEncodingLength();
799 break;
800 }
801 case CegoPredDesc::NOTPRED:
802 {
803 len += _pNotPred->getEncodingLength();
804 break;
805 }
806 case CegoPredDesc::EXPRCOMP:
807 {
808 len += sizeof(CegoComparison);
809 len += _pExpr1->getEncodingLength();
810 len += _pExpr2->getEncodingLength();
811 break;
812 }
813 case CegoPredDesc::BETWEEN:
814 {
815 len += _pExpr1->getEncodingLength();
816 len += _pExpr2->getEncodingLength();
817 len += _pExpr3->getEncodingLength();
818 break;
819 }
820 case CegoPredDesc::ISLIKE:
821 case CegoPredDesc::ISNOTLIKE:
822 {
823 len += _pExpr1->getEncodingLength();
824 len += 1; // sizeof pattern
825 len += _pattern.length();
826 break;
827 }
828 case CegoPredDesc::NULLCOMP:
829 case CegoPredDesc::NOTNULLCOMP:
830 {
831 len += _pExpr1->getEncodingLength();
832 break;
833 }
834 case CegoPredDesc::EXISTSCOMP:
835 {
836 len += _pSelect->getEncodingLength();
837 break;
838 }
839 case CegoPredDesc::INSUB:
840 case CegoPredDesc::NOTINSUB:
841 {
842 len += _pExpr1->getEncodingLength();
843 len += _pSelect->getEncodingLength();
844 break;
845 }
846 case CegoPredDesc::IN:
847 case CegoPredDesc::NOTIN:
848 {
849 len += _pExpr1->getEncodingLength();
850
851 len += sizeof(int);
852
853 CegoExpr** pExpr = _exprList.First();
854 while ( pExpr )
855 {
856 len += (*pExpr)->getEncodingLength();
857 pExpr = _exprList.Next();
858 }
859 break;
860 }
861 }
862 return len;
863 }
864
getTableRefSet() const865 SetT<Chain> CegoPredDesc::getTableRefSet() const
866 {
867 SetT<Chain> tableRefSet;
868 ListT<CegoAttrDesc*> adList = getAttrRefList();
869 CegoAttrDesc **pAD = adList.First();
870 while ( pAD )
871 {
872 tableRefSet.Insert((*pAD)->getTableName());
873 pAD = adList.Next();
874 }
875 return tableRefSet;
876 }
877
getAttrRefList() const878 ListT<CegoAttrDesc*> CegoPredDesc::getAttrRefList() const
879 {
880 ListT<CegoAttrDesc*> al;
881
882 switch (_mode )
883 {
884 case CegoPredDesc::CONDITION:
885 {
886 al = _pC->getAttrRefList();
887 break;
888 }
889 case CegoPredDesc::NOTPRED:
890 {
891 al = _pNotPred->getAttrRefList();
892 break;
893 }
894 case CegoPredDesc::EXPRCOMP:
895 {
896 al = _pExpr1->getAttrRefList();
897 al += _pExpr2->getAttrRefList();
898 break;
899 }
900 case CegoPredDesc::BETWEEN:
901 {
902 al = _pExpr1->getAttrRefList();
903 al += _pExpr2->getAttrRefList();
904 al += _pExpr3->getAttrRefList();
905 break;
906 }
907 case CegoPredDesc::ISLIKE:
908 case CegoPredDesc::ISNOTLIKE:
909 {
910 al += _pExpr1->getAttrRefList();
911 break;
912 }
913 case CegoPredDesc::NULLCOMP:
914 case CegoPredDesc::NOTNULLCOMP:
915 {
916 al += _pExpr1->getAttrRefList();
917 break;
918 }
919 case CegoPredDesc::INSUB:
920 case CegoPredDesc::NOTINSUB:
921 {
922 al = _pExpr1->getAttrRefList();
923 al += _pSelect->getAttrRefList();
924 break;
925 }
926 case CegoPredDesc::IN:
927 case CegoPredDesc::NOTIN:
928 {
929 al = _pExpr1->getAttrRefList();
930
931 CegoExpr** pExpr = _exprList.First();
932 while ( pExpr )
933 {
934 al += (*pExpr)->getAttrRefList();
935 pExpr = _exprList.Next();
936 }
937 break;
938 }
939 case CegoPredDesc::EXISTSCOMP:
940 {
941 al = _pSelect->getAttrRefList();
942 break;
943 }
944 }
945 return al;
946 }
947
evalReferences(CegoContentObject * pCO,const ListT<CegoField> & fl)948 int CegoPredDesc::evalReferences(CegoContentObject *pCO, const ListT<CegoField>& fl)
949 {
950 int refCount = 0;
951
952 switch (_mode )
953 {
954 case CegoPredDesc::CONDITION:
955 {
956 refCount += _pC->evalReferences(pCO, fl);
957 break;
958 }
959 case CegoPredDesc::NOTPRED:
960 {
961 refCount += _pNotPred->evalReferences(pCO, fl);
962 break;
963 }
964 case CegoPredDesc::EXPRCOMP:
965 {
966 refCount += _pExpr1->evalReferences(pCO, fl);
967 refCount += _pExpr2->evalReferences(pCO, fl);
968 break;
969 }
970 case CegoPredDesc::BETWEEN:
971 {
972 refCount += _pExpr1->evalReferences(pCO, fl);
973 refCount += _pExpr2->evalReferences(pCO, fl);
974 refCount += _pExpr3->evalReferences(pCO, fl);
975 break;
976 }
977 case CegoPredDesc::ISLIKE:
978 case CegoPredDesc::ISNOTLIKE:
979 {
980 refCount += _pExpr1->evalReferences(pCO, fl);
981 break;
982 }
983 case CegoPredDesc::NULLCOMP:
984 case CegoPredDesc::NOTNULLCOMP:
985 {
986 refCount += _pExpr1->evalReferences(pCO, fl);
987 break;
988 }
989 case CegoPredDesc::INSUB:
990 case CegoPredDesc::NOTINSUB:
991 {
992 refCount += _pExpr1->evalReferences(pCO, fl);
993 _pSelect->prepare();
994 refCount += _pSelect->evalExtTableReferences(pCO, fl);
995 break;
996 }
997 case CegoPredDesc::IN:
998 case CegoPredDesc::NOTIN:
999 {
1000 refCount += _pExpr1->evalReferences(pCO, fl);
1001
1002 CegoExpr** pExpr = _exprList.First();
1003 while ( pExpr )
1004 {
1005 refCount += (*pExpr)->evalReferences(pCO, fl);
1006 pExpr = _exprList.Next();
1007 }
1008 break;
1009 }
1010 case CegoPredDesc::EXISTSCOMP:
1011 {
1012 _pSelect->prepare();
1013 refCount += _pSelect->evalExtTableReferences(pCO, fl);
1014 break;
1015 }
1016 }
1017
1018 return refCount;
1019 }
1020
getAggregationList()1021 ListT<CegoAggregation*> CegoPredDesc::getAggregationList()
1022 {
1023 ListT<CegoAggregation*> aggList;
1024
1025 if ( _pExpr1 )
1026 {
1027 aggList = aggList + _pExpr1->getAggregationList();
1028 }
1029
1030 if ( _pExpr2 )
1031 {
1032 aggList = aggList + _pExpr2->getAggregationList();
1033 }
1034
1035 if ( _pExpr3 )
1036 {
1037 aggList = aggList + _pExpr3->getAggregationList();
1038 }
1039
1040 CegoExpr** pExpr = _exprList.First();
1041 while ( pExpr )
1042 {
1043 aggList = aggList + (*pExpr)->getAggregationList();
1044 pExpr = _exprList.Next();
1045 }
1046
1047 if (_pC)
1048 {
1049 aggList = aggList + _pC->getAggregationList();
1050 }
1051
1052 if (_pNotPred)
1053 {
1054 aggList = aggList + _pNotPred->getAggregationList();
1055 }
1056
1057 return aggList;
1058
1059 }
1060
setFieldListArray(ListT<CegoField> ** pFLA)1061 void CegoPredDesc::setFieldListArray(ListT<CegoField> **pFLA)
1062 {
1063
1064 if ( _pExpr1 )
1065 {
1066 _pExpr1->setFieldListArray(pFLA);
1067 }
1068
1069 if ( _pExpr2 )
1070 {
1071 _pExpr2->setFieldListArray(pFLA);
1072 }
1073
1074 if ( _pExpr3 )
1075 {
1076 _pExpr3->setFieldListArray(pFLA);
1077 }
1078 CegoExpr** pExpr = _exprList.First();
1079 while ( pExpr )
1080 {
1081 (*pExpr)->setFieldListArray(pFLA);
1082 pExpr = _exprList.Next();
1083 }
1084
1085 if ( _pC )
1086 {
1087 _pC->setFieldListArray(pFLA);
1088 }
1089
1090 if (_pNotPred)
1091 {
1092 _pNotPred->setFieldListArray(pFLA);
1093 }
1094
1095 }
1096
1097
getFieldList(ListT<CegoField> & fl) const1098 void CegoPredDesc::getFieldList(ListT<CegoField>& fl) const
1099 {
1100 switch (_mode )
1101 {
1102 case CegoPredDesc::CONDITION:
1103 {
1104 _pC->getFieldList(fl);
1105 break;
1106 }
1107 case CegoPredDesc::NOTPRED:
1108 {
1109 _pNotPred->getFieldList(fl);
1110 break;
1111 }
1112 case CegoPredDesc::EXPRCOMP:
1113 {
1114 _pExpr1->getFieldList(fl);
1115 _pExpr2->getFieldList(fl);
1116 break;
1117 }
1118 case CegoPredDesc::BETWEEN:
1119 {
1120 _pExpr1->getFieldList(fl);
1121 _pExpr2->getFieldList(fl);
1122 _pExpr3->getFieldList(fl);
1123 break;
1124 }
1125 case CegoPredDesc::ISLIKE:
1126 case CegoPredDesc::ISNOTLIKE:
1127 {
1128 _pExpr1->getFieldList(fl);
1129 break;
1130 }
1131 case CegoPredDesc::INSUB:
1132 case CegoPredDesc::NOTINSUB:
1133 {
1134 _pExpr1->getFieldList(fl);
1135 _pSelect->getFieldList(fl);
1136 break;
1137 }
1138 case CegoPredDesc::IN:
1139 case CegoPredDesc::NOTIN:
1140 {
1141 _pExpr1->getFieldList(fl);
1142
1143 CegoExpr** pExpr = _exprList.First();
1144 while ( pExpr )
1145 {
1146 (*pExpr)->getFieldList(fl);
1147 pExpr = _exprList.Next();
1148 }
1149 break;
1150 }
1151 case CegoPredDesc::EXISTSCOMP:
1152 {
1153 _pSelect->getFieldList(fl);
1154 break;
1155 }
1156 case CegoPredDesc::NULLCOMP:
1157 case CegoPredDesc::NOTNULLCOMP:
1158 {
1159 _pExpr1->getFieldList(fl);
1160 break;
1161 }
1162 }
1163 }
1164
clone(bool isAttrRef)1165 CegoPredDesc* CegoPredDesc::clone(bool isAttrRef)
1166 {
1167 if ( _mode == CegoPredDesc::EXPRCOMP )
1168 {
1169 return new CegoPredDesc(_pExpr1->clone(isAttrRef), _pExpr2->clone(isAttrRef), _comp);
1170 }
1171 else if ( _mode == CegoPredDesc::BETWEEN )
1172 {
1173 return new CegoPredDesc(_pExpr1->clone(isAttrRef), _pExpr2->clone(isAttrRef), _pExpr3->clone(isAttrRef));
1174 }
1175 else if ( _mode == CegoPredDesc::ISLIKE )
1176 {
1177 return new CegoPredDesc(_pExpr1->clone(isAttrRef), _pattern, false);
1178 }
1179 else if ( _mode == CegoPredDesc::ISNOTLIKE )
1180 {
1181 return new CegoPredDesc(_pExpr1->clone(isAttrRef), _pattern, true);
1182 }
1183 else if ( _mode == CegoPredDesc::CONDITION )
1184 {
1185 return new CegoPredDesc(_pC->clone(isAttrRef));
1186 }
1187 else if ( _mode == CegoPredDesc::NOTPRED )
1188 {
1189 return new CegoPredDesc(_pNotPred->clone(isAttrRef));
1190 }
1191 else if ( _mode == CegoPredDesc::EXISTSCOMP )
1192 {
1193 return new CegoPredDesc(_pSelect->clone(isAttrRef));
1194 }
1195 else if ( _mode == CegoPredDesc::INSUB )
1196 {
1197 return new CegoPredDesc(_pExpr1->clone(isAttrRef), _pSelect->clone(isAttrRef), false);
1198 }
1199 else if ( _mode == CegoPredDesc::NOTINSUB )
1200 {
1201 return new CegoPredDesc(_pExpr1->clone(isAttrRef), _pSelect->clone(isAttrRef), true);
1202 }
1203 else if ( _mode == CegoPredDesc::IN )
1204 {
1205 ListT<CegoExpr*> exprList;
1206
1207 CegoExpr** pExpr = _exprList.First();
1208 while ( pExpr )
1209 {
1210 exprList.Insert((*pExpr)->clone());
1211 pExpr = _exprList.Next();
1212 }
1213 return new CegoPredDesc(_pExpr1->clone(isAttrRef), exprList, false);
1214 }
1215 else if ( _mode == CegoPredDesc::NOTIN )
1216 {
1217 ListT<CegoExpr*> exprList;
1218
1219 CegoExpr** pExpr = _exprList.First();
1220 while ( pExpr )
1221 {
1222 exprList.Insert((*pExpr)->clone());
1223 pExpr = _exprList.Next();
1224 }
1225 return new CegoPredDesc(_pExpr1->clone(isAttrRef), exprList, true);
1226 }
1227 else if ( _mode == CegoPredDesc::NULLCOMP )
1228 {
1229 return new CegoPredDesc(_pExpr1->clone(isAttrRef), true);
1230 }
1231 else if ( _mode == CegoPredDesc::NOTNULLCOMP )
1232 {
1233 return new CegoPredDesc(_pExpr1->clone(isAttrRef), false);
1234 }
1235 throw Exception(EXLOC, "Clone not implemented");
1236 }
1237
getId() const1238 Chain CegoPredDesc::getId() const
1239 {
1240 Chain s;
1241
1242 switch (_mode )
1243 {
1244 case CegoPredDesc::CONDITION:
1245 {
1246 if (_pC->Left())
1247 {
1248 s = Chain("( ");
1249 s += _pC->Left()->getId();
1250
1251 switch(_pC->getCondType())
1252 {
1253 case CegoCondDesc::AND:
1254 s += Chain("a");
1255 break;
1256 case CegoCondDesc::OR:
1257 s += Chain("o");
1258 break;
1259 case CegoCondDesc::PRED:
1260 break;
1261 }
1262 s += _pC->Right()->getId();
1263 }
1264 break;
1265 }
1266 case CegoPredDesc::NOTPRED:
1267 {
1268 s = Chain("n") + _pNotPred->getId();
1269 break;
1270 }
1271 case CegoPredDesc::EXPRCOMP:
1272 {
1273 s = _pExpr1->getId();
1274
1275 switch (_comp)
1276 {
1277 case EQUAL:
1278 s += "=";
1279 break;
1280 case NOT_EQUAL:
1281 s += "!=";
1282 break;
1283 case LESS_THAN:
1284 s += "<";
1285 break;
1286 case MORE_THAN:
1287 s += ">";
1288 break;
1289 case LESS_EQUAL_THAN:
1290 s += "<=";
1291 break;
1292 case MORE_EQUAL_THAN:
1293 s += ">=";
1294 break;
1295 }
1296
1297 s += _pExpr2->getId();
1298 break;
1299 }
1300 case CegoPredDesc::BETWEEN:
1301 {
1302 s = _pExpr2->getId();
1303 s += Chain("bw");
1304 s += _pExpr1->getId();
1305 s += Chain("a");
1306 s += _pExpr3->getId();
1307
1308 break;
1309 }
1310 case CegoPredDesc::ISLIKE:
1311 {
1312 s = _pExpr1->getId();
1313 s += Chain("l");
1314 s += Chain("'") + _pattern + Chain("'");
1315 break;
1316 }
1317 case CegoPredDesc::ISNOTLIKE:
1318 {
1319 s = _pExpr1->getId();
1320 s += Chain("nl");
1321 s += Chain("'") + _pattern + Chain("'");
1322 break;
1323 }
1324 case CegoPredDesc::NULLCOMP:
1325 {
1326 s = _pExpr1->getId();
1327 s += Chain("n");
1328 break;
1329 }
1330 case CegoPredDesc::NOTNULLCOMP:
1331 {
1332 s = _pExpr1->getId();
1333 s += Chain("nn");
1334 break;
1335 }
1336 case CegoPredDesc::EXISTSCOMP:
1337 {
1338 s = Chain("e");
1339 s += _pSelect->getQueryId();
1340 break;
1341 }
1342 case CegoPredDesc::INSUB:
1343 {
1344 s = _pExpr1->getId();
1345 s += Chain("i");
1346 s += Chain("(") + _pSelect->getQueryId() + Chain(")");
1347 break;
1348 }
1349 case CegoPredDesc::NOTINSUB:
1350 {
1351 s = _pExpr1->getId();
1352 s += Chain("ni");
1353 s += Chain("(") + _pSelect->getQueryId() + Chain(")");
1354 break;
1355 }
1356 case CegoPredDesc::IN:
1357 {
1358 s = _pExpr1->getId();
1359 s += Chain("i");
1360
1361 s += Chain("(");
1362 CegoExpr **pExpr = _exprList.First();
1363 while ( pExpr )
1364 {
1365 s += (*pExpr)->getId();
1366 pExpr = _exprList.Next();
1367 if ( pExpr )
1368 s += Chain(",");
1369 }
1370 s += Chain(")");
1371 break;
1372 }
1373 case CegoPredDesc::NOTIN:
1374 {
1375 s = _pExpr1->getId();
1376 s += Chain("ni");
1377
1378 s += Chain("(");
1379 CegoExpr **pExpr = _exprList.First();
1380 while ( pExpr )
1381 {
1382 s += (*pExpr)->getId();
1383 pExpr = _exprList.Next();
1384 if ( pExpr )
1385 s += Chain(",");
1386 }
1387 s += Chain(")");
1388
1389 break;
1390 }
1391 }
1392 return s;
1393 }
1394
toChain(const Chain & indent) const1395 Chain CegoPredDesc::toChain(const Chain& indent) const
1396 {
1397 Chain s;
1398
1399 switch (_mode )
1400 {
1401 case CegoPredDesc::CONDITION:
1402 {
1403 if (_pC->Left())
1404 {
1405 s = Chain("( ");
1406 s += _pC->Left()->toChain(indent);
1407
1408 s += Chain("\n") + indent;
1409 Chain addIndent;
1410 switch(_pC->getCondType())
1411 {
1412 case CegoCondDesc::AND:
1413 s += Chain("and ");
1414 addIndent = Chain(DEFAULTINDENT);
1415 break;
1416 case CegoCondDesc::OR:
1417 s += Chain("or ");
1418 addIndent = Chain(DEFAULTINDENT);
1419 break;
1420 case CegoCondDesc::PRED:
1421 break;
1422 }
1423
1424 s += _pC->Right()->toChain(indent + addIndent);
1425 s += Chain(" )");
1426 }
1427 break;
1428 }
1429 case CegoPredDesc::NOTPRED:
1430 {
1431 s = Chain("not ") + _pNotPred->toChain(indent + Chain(DEFAULTINDENT));
1432 break;
1433 }
1434 case CegoPredDesc::EXPRCOMP:
1435 {
1436 s = _pExpr1->toChain(indent);
1437
1438 switch (_comp)
1439 {
1440 case EQUAL:
1441 s += " = ";
1442 break;
1443 case NOT_EQUAL:
1444 s += " != ";
1445 break;
1446 case LESS_THAN:
1447 s += " < ";
1448 break;
1449 case MORE_THAN:
1450 s += " > ";
1451 break;
1452 case LESS_EQUAL_THAN:
1453 s += " <= ";
1454 break;
1455 case MORE_EQUAL_THAN:
1456 s += " >= ";
1457 break;
1458 }
1459
1460 Chain addIndent;
1461 for ( int i=1; i<s.length(); i++ )
1462 addIndent += Chain(" ");
1463
1464 s += _pExpr2->toChain(indent + addIndent);
1465 break;
1466 }
1467 case CegoPredDesc::BETWEEN:
1468 {
1469 s = _pExpr1->toChain(indent);
1470 s += Chain("\n") + indent;
1471 s += Chain("between ");
1472
1473 Chain addIndent;
1474
1475 addIndent = Chain(DEFAULTINDENT);
1476 s += _pExpr2->toChain(indent + addIndent);
1477 s += Chain("\n") + indent;
1478 s += Chain("and ");
1479
1480 addIndent=Chain(DEFAULTINDENT);
1481 s += _pExpr3->toChain(indent + addIndent);
1482
1483 break;
1484 }
1485 case CegoPredDesc::ISLIKE:
1486 {
1487 s = _pExpr1->toChain(indent);
1488 s += Chain(" like ");
1489 s += Chain("'") + _pattern + Chain("'");
1490 break;
1491 }
1492 case CegoPredDesc::ISNOTLIKE:
1493 {
1494 s = _pExpr1->toChain(indent);
1495 s += Chain(" not like ");
1496 s += Chain("'") + _pattern + Chain("'");
1497 break;
1498 }
1499 case CegoPredDesc::NULLCOMP:
1500 {
1501 s = _pExpr1->toChain(indent);
1502 s += Chain(" is null ");
1503 break;
1504 }
1505 case CegoPredDesc::NOTNULLCOMP:
1506 {
1507 s = _pExpr1->toChain(indent);
1508 s += Chain(" is not null ");
1509 break;
1510 }
1511 case CegoPredDesc::EXISTSCOMP:
1512 {
1513 s = Chain("exists ( ");
1514 s += _pSelect->toChain(indent + Chain(DEFAULTINDENT)) + Chain(" )");
1515 break;
1516 }
1517 case CegoPredDesc::INSUB:
1518 {
1519 s = _pExpr1->toChain(indent);
1520 s += Chain(" in ( ");
1521
1522 Chain addIndent;
1523 for ( int i=1; i<s.length(); i++ )
1524 addIndent += Chain(" ");
1525
1526 s += _pSelect->toChain(indent + addIndent) + Chain(" )");
1527 break;
1528 }
1529 case CegoPredDesc::NOTINSUB:
1530 {
1531 s = _pExpr1->toChain(indent);
1532 s += Chain(" not in ( ");
1533
1534 Chain addIndent;
1535 for ( int i=1; i<s.length(); i++ )
1536 addIndent += Chain(" ");
1537
1538 s += _pSelect->toChain(indent + addIndent) + Chain(" )");
1539 break;
1540 }
1541 case CegoPredDesc::IN:
1542 {
1543 s = _pExpr1->toChain(indent);
1544 s += Chain(" in ( ");
1545
1546 CegoExpr **pExpr = _exprList.First();
1547 while ( pExpr )
1548 {
1549 s += (*pExpr)->toChain();
1550 pExpr = _exprList.Next();
1551 if ( pExpr )
1552 s += Chain(",");
1553 }
1554 s += Chain(")");
1555
1556 break;
1557 }
1558 case CegoPredDesc::NOTIN:
1559 {
1560 s = _pExpr1->toChain(indent);
1561 s += Chain(" not in ( ");
1562
1563 CegoExpr **pExpr = _exprList.First();
1564 while ( pExpr )
1565 {
1566 s += (*pExpr)->toChain();
1567 pExpr = _exprList.Next();
1568 if ( pExpr )
1569 s += Chain(",");
1570 }
1571 s += Chain(")");
1572
1573 break;
1574 }
1575 }
1576 return s;
1577 }
1578
dbFormat(CegoDatabaseFormater * pForm)1579 Chain CegoPredDesc::dbFormat(CegoDatabaseFormater *pForm)
1580 {
1581 return pForm->formatPred(_mode, _pExpr1, _pExpr2, _pExpr3, _exprList, _comp, _pattern, _pC, _pNotPred, _pSelect);
1582 }
1583
toElement() const1584 Element* CegoPredDesc::toElement() const
1585 {
1586 Element *pPredElement = new Element(XML_PRED_ELEMENT);
1587
1588 switch (_mode )
1589 {
1590 case CegoPredDesc::CONDITION:
1591 {
1592 pPredElement->setAttribute( XML_PRED_ATTR, XML_COND_VALUE );
1593 pPredElement->addContent( _pC->toElement() );
1594 break;
1595 }
1596 case CegoPredDesc::NOTPRED:
1597 {
1598 pPredElement->setAttribute( XML_PRED_ATTR, XML_NOTPRED_VALUE );
1599 pPredElement->addContent( _pNotPred->toElement() );
1600 break;
1601 }
1602 case CegoPredDesc::EXPRCOMP:
1603 {
1604 pPredElement->addContent( _pExpr1->toElement() );
1605 pPredElement->addContent( _pExpr2->toElement() );
1606 pPredElement->setAttribute( XML_PRED_ATTR, XML_EXPRCOMP_VALUE );
1607
1608 switch (_comp)
1609 {
1610 case EQUAL:
1611 pPredElement->setAttribute( XML_COMP_ATTR, XML_EQUAL_VALUE );
1612 break;
1613 case NOT_EQUAL:
1614 pPredElement->setAttribute( XML_COMP_ATTR, XML_NOTEQUAL_VALUE );
1615 break;
1616 case LESS_THAN:
1617 pPredElement->setAttribute( XML_COMP_ATTR, XML_LESSTHAN_VALUE );
1618 break;
1619 case MORE_THAN:
1620 pPredElement->setAttribute( XML_COMP_ATTR, XML_MORETHAN_VALUE );
1621 break;
1622 case LESS_EQUAL_THAN:
1623 pPredElement->setAttribute( XML_COMP_ATTR, XML_LESSEQUALTHAN_VALUE );
1624 break;
1625 case MORE_EQUAL_THAN:
1626 pPredElement->setAttribute( XML_COMP_ATTR, XML_MOREEQUALTHAN_VALUE );
1627 break;
1628 }
1629 break;
1630 }
1631 case CegoPredDesc::BETWEEN:
1632 {
1633 pPredElement->addContent( _pExpr1->toElement() );
1634 pPredElement->addContent( _pExpr2->toElement() );
1635 pPredElement->addContent( _pExpr3->toElement() );
1636 pPredElement->setAttribute( XML_PRED_ATTR, XML_BETWEEN_VALUE );
1637 break;
1638 }
1639 case CegoPredDesc::ISLIKE:
1640 {
1641 pPredElement->setAttribute( XML_PRED_ATTR, XML_ISLIKE_VALUE );
1642 pPredElement->addContent( _pExpr1->toElement() );
1643 pPredElement->setAttribute( XML_PATTERN_ATTR, _pattern );
1644 break;
1645 }
1646 case CegoPredDesc::ISNOTLIKE:
1647 {
1648 pPredElement->setAttribute( XML_PRED_ATTR, XML_ISLIKE_VALUE );
1649 pPredElement->addContent( _pExpr1->toElement() );
1650 pPredElement->setAttribute( XML_PATTERN_ATTR, _pattern );
1651 break;
1652 }
1653 case CegoPredDesc::NULLCOMP:
1654 {
1655 pPredElement->setAttribute( XML_PRED_ATTR, XML_NULLCOMP_VALUE );
1656 pPredElement->addContent ( _pExpr1->toElement() );
1657 break;
1658 }
1659 case CegoPredDesc::NOTNULLCOMP:
1660 {
1661 pPredElement->setAttribute( XML_PRED_ATTR, XML_NOTNULLCOMP_VALUE );
1662 pPredElement->addContent ( _pExpr1->toElement() );
1663 break;
1664 }
1665 case CegoPredDesc::EXISTSCOMP:
1666 {
1667 pPredElement->setAttribute( XML_PRED_ATTR, XML_EXISTS_VALUE );
1668 pPredElement->addContent( _pSelect->toElement() );
1669 break;
1670 }
1671 case CegoPredDesc::INSUB:
1672 {
1673 pPredElement->setAttribute( XML_PRED_ATTR, XML_INQUERY_VALUE );
1674 pPredElement->addContent ( _pExpr1->toElement() );
1675 pPredElement->addContent( _pSelect->toElement() );
1676 break;
1677 }
1678 case CegoPredDesc::NOTINSUB:
1679 {
1680 pPredElement->setAttribute( XML_PRED_ATTR, XML_NOTINQUERY_VALUE );
1681 pPredElement->addContent ( _pExpr1->toElement() );
1682 pPredElement->addContent( _pSelect->toElement() );
1683 break;
1684 }
1685 case CegoPredDesc::IN:
1686 {
1687 pPredElement->setAttribute( XML_PRED_ATTR, XML_IN_VALUE );
1688 pPredElement->addContent ( _pExpr1->toElement() );
1689
1690 CegoExpr **pExpr = _exprList.First();
1691 while ( pExpr )
1692 {
1693 pPredElement->addContent ( (*pExpr)->toElement() );
1694 pExpr = _exprList.Next();
1695 }
1696 break;
1697 }
1698 case CegoPredDesc::NOTIN:
1699 {
1700 pPredElement->setAttribute( XML_PRED_ATTR, XML_NOTIN_VALUE );
1701 pPredElement->addContent ( _pExpr1->toElement() );
1702
1703 CegoExpr **pExpr = _exprList.First();
1704 while ( pExpr )
1705 {
1706 pPredElement->addContent ( (*pExpr)->toElement() );
1707 pExpr = _exprList.Next();
1708 }
1709 break;
1710 }
1711 }
1712 return pPredElement;
1713 }
1714
fromElement(Element * pPredElement,CegoDistManager * pGTM)1715 void CegoPredDesc::fromElement(Element* pPredElement, CegoDistManager *pGTM)
1716 {
1717 if ( _pExpr1 )
1718 delete _pExpr1;
1719 if ( _pExpr2 )
1720 delete _pExpr2;
1721 if ( _pExpr3 )
1722 delete _pExpr3;
1723 if ( _pC )
1724 delete _pC;
1725 if ( _pNotPred )
1726 delete _pNotPred;
1727 if ( _pSelect )
1728 delete _pSelect;
1729
1730 _pExpr1 = 0;
1731 _pExpr2 = 0;
1732 _pExpr3 = 0;
1733 _pC = 0;
1734 _pNotPred = 0;
1735 _isChecked = false;
1736 _pSelect = 0;
1737
1738 Chain mode = pPredElement->getAttributeValue( XML_PRED_ATTR );
1739
1740 if ( mode == Chain(XML_COND_VALUE) )
1741 {
1742 _mode = CegoPredDesc::CONDITION;
1743
1744 ListT<Element*> cel = pPredElement->getChildren(XML_COND_ELEMENT);
1745 Element **pCE = cel.First();
1746 if ( pCE )
1747 {
1748 _pC = new CegoCondDesc(*pCE, pGTM);
1749 }
1750 else
1751 {
1752 throw Exception(EXLOC, "Invalid element");
1753 }
1754 }
1755 else if ( mode == Chain(XML_NOTPRED_VALUE) )
1756 {
1757 _mode = CegoPredDesc::NOTPRED;
1758
1759 ListT<Element*> npl = pPredElement->getChildren(XML_PRED_ELEMENT);
1760 Element **pNPE = npl.First();
1761 if ( pNPE )
1762 {
1763 _pNotPred = new CegoPredDesc(*pNPE, pGTM);
1764 }
1765 else
1766 {
1767 throw Exception(EXLOC, "Invalid element");
1768 }
1769 }
1770 else if ( mode == Chain(XML_EXPRCOMP_VALUE) )
1771 {
1772 _mode = CegoPredDesc::EXPRCOMP;
1773
1774 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1775 Element **pEE = el.First();
1776 if ( pEE )
1777 {
1778 _pExpr1 = new CegoExpr(*pEE, pGTM);
1779 }
1780 pEE = el.Next();
1781 if ( pEE )
1782 {
1783 _pExpr2 = new CegoExpr(*pEE, pGTM);
1784 }
1785
1786 Chain compString = pPredElement->getAttributeValue( XML_COMP_ATTR );
1787
1788 if ( compString == Chain(XML_EQUAL_VALUE) )
1789 {
1790 _comp = EQUAL;
1791 }
1792 else if ( compString == Chain(XML_NOTEQUAL_VALUE) )
1793 {
1794 _comp = NOT_EQUAL;
1795 }
1796 else if ( compString == Chain(XML_LESSTHAN_VALUE) )
1797 {
1798 _comp = LESS_THAN;
1799 }
1800 else if ( compString == Chain(XML_MORETHAN_VALUE) )
1801 {
1802 _comp = MORE_THAN;
1803 }
1804 else if ( compString == Chain(XML_LESSEQUALTHAN_VALUE) )
1805 {
1806 _comp = LESS_EQUAL_THAN;
1807 }
1808 else if ( compString == Chain(XML_MOREEQUALTHAN_VALUE) )
1809 {
1810 _comp = MORE_EQUAL_THAN;
1811 }
1812 }
1813 else if ( mode == Chain(XML_BETWEEN_VALUE) )
1814 {
1815 _mode = CegoPredDesc::BETWEEN;
1816
1817 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1818 Element **pEE = el.First();
1819 if ( pEE )
1820 {
1821 _pExpr1 = new CegoExpr(*pEE, pGTM);
1822 }
1823 pEE = el.Next();
1824 if ( pEE )
1825 {
1826 _pExpr2 = new CegoExpr(*pEE, pGTM);
1827 }
1828 pEE = el.Next();
1829 if ( pEE )
1830 {
1831 _pExpr3 = new CegoExpr(*pEE, pGTM);
1832 }
1833 }
1834 else if ( mode == Chain(XML_ISLIKE_VALUE) )
1835 {
1836 _mode = CegoPredDesc::ISLIKE;
1837 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1838 Element **pEE = el.First();
1839 if ( pEE )
1840 {
1841 _pExpr1 = new CegoExpr(*pEE, pGTM);
1842 }
1843
1844 _pattern = pPredElement->getAttributeValue( XML_PATTERN_ATTR );
1845 }
1846 else if ( mode == Chain(XML_ISNOTLIKE_VALUE) )
1847 {
1848 _mode = CegoPredDesc::ISNOTLIKE;
1849 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1850 Element **pEE = el.First();
1851 if ( pEE )
1852 {
1853 _pExpr1 = new CegoExpr(*pEE, pGTM);
1854 }
1855
1856 _pattern = pPredElement->getAttributeValue( XML_PATTERN_ATTR );
1857 }
1858 else if ( mode == Chain(XML_NULLCOMP_VALUE) )
1859 {
1860 _mode = CegoPredDesc::NULLCOMP;
1861 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1862 Element **pEE = el.First();
1863 if ( pEE )
1864 {
1865 _pExpr1 = new CegoExpr(*pEE, pGTM);
1866 }
1867 }
1868 else if ( mode == Chain(XML_NOTNULLCOMP_VALUE) )
1869 {
1870 _mode = CegoPredDesc::NOTNULLCOMP;
1871 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1872 Element **pEE = el.First();
1873 if ( pEE )
1874 {
1875 _pExpr1 = new CegoExpr(*pEE, pGTM);
1876 }
1877 }
1878 else if ( mode == Chain(XML_EXISTS_VALUE) )
1879 {
1880 _mode = CegoPredDesc::EXISTSCOMP;
1881 ListT<Element*> sl = pPredElement->getChildren(XML_SELECT_ELEMENT);
1882 Element **pSE = sl.First();
1883 if ( pSE )
1884 {
1885 _pSelect = new CegoSelect(*pSE, pGTM);
1886 }
1887 }
1888 else if ( mode == Chain(XML_IN_VALUE) )
1889 {
1890 _mode = CegoPredDesc::IN;
1891
1892 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1893 Element **pEE = el.First();
1894 if ( pEE )
1895 {
1896 _pExpr1 = new CegoExpr(*pEE, pGTM);
1897 }
1898
1899 pEE = el.Next();
1900 while ( pEE )
1901 {
1902 _exprList.Insert( new CegoExpr(*pEE, pGTM) );
1903 pEE = el.Next();
1904 }
1905 }
1906 else if ( mode == Chain(XML_NOTIN_VALUE) )
1907 {
1908 _mode = CegoPredDesc::NOTIN;
1909
1910 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1911 Element **pEE = el.First();
1912 if ( pEE )
1913 {
1914 _pExpr1 = new CegoExpr(*pEE, pGTM);
1915 }
1916
1917 pEE = el.Next();
1918 while ( pEE )
1919 {
1920 _exprList.Insert( new CegoExpr(*pEE, pGTM) );
1921 pEE = el.Next();
1922 }
1923 }
1924 else if ( mode == Chain(XML_INQUERY_VALUE) )
1925 {
1926 _mode = CegoPredDesc::INSUB;
1927
1928 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1929 Element **pEE = el.First();
1930 if ( pEE )
1931 {
1932 _pExpr1 = new CegoExpr(*pEE, pGTM);
1933 }
1934
1935 ListT<Element*> sl = pPredElement->getChildren(XML_SELECT_ELEMENT);
1936 Element **pSE = sl.First();
1937 if ( pSE )
1938 {
1939 _pSelect = new CegoSelect(*pSE, pGTM);
1940 }
1941 }
1942 else if ( mode == Chain(XML_NOTINQUERY_VALUE) )
1943 {
1944 _mode = CegoPredDesc::NOTINSUB;
1945
1946 ListT<Element*> el = pPredElement->getChildren(XML_EXPR_ELEMENT);
1947 Element **pEE = el.First();
1948 if ( pEE )
1949 {
1950 _pExpr1 = new CegoExpr(*pEE, pGTM);
1951 }
1952
1953 ListT<Element*> sl = pPredElement->getChildren(XML_SELECT_ELEMENT);
1954 Element **pSE = sl.First();
1955 if ( pSE )
1956 {
1957 _pSelect = new CegoSelect(*pSE, pGTM);
1958 }
1959 }
1960 }
1961
operator <<(ostream & s,const CegoPredDesc & p)1962 ostream& operator << (ostream& s, const CegoPredDesc& p)
1963 {
1964 s << p.toChain();
1965 return s;
1966 }
1967