1 karl 1.9 //%2006////////////////////////////////////////////////////////////////////////
|
2 chuck 1.2 //
|
3 karl 1.7 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 chuck 1.2 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.9 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 chuck 1.2 //
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 //
21 // 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 // Authors: David Rosckes (rosckes@us.ibm.com)
33 // Bert Rivero (hurivero@us.ibm.com)
34 chuck 1.2 // Chuck Carmack (carmack@us.ibm.com)
35 // Brian Lucier (lucier@us.ibm.com)
36 //
|
37 vijay.eli 1.8 // Modified By: Vijay Eli, IBM (vijayeli@in.ibm.com) bug#3590
|
38 chuck 1.2 //
39 //%/////////////////////////////////////////////////////////////////////////////
40
41 #include <Pegasus/Common/InternalException.h>
42 #include "CQLPredicate.h"
43 #include "CQLSimplePredicate.h"
44 #include "CQLPredicateRep.h"
45 #include <Pegasus/CQL/CQLFactory.h>
46 #include <Pegasus/Query/QueryCommon/QueryContext.h>
|
47 humberto 1.3 #include <Pegasus/Common/Tracer.h>
|
48 chuck 1.2
49 PEGASUS_NAMESPACE_BEGIN
50
51 CQLPredicateRep::CQLPredicateRep():
|
52 humberto 1.5 _invert(false)
|
53 chuck 1.2 {
54
55 }
56
57 CQLPredicateRep::CQLPredicateRep(const CQLSimplePredicate& inSimplePredicate, Boolean inVerted):
|
58 humberto 1.5 _simplePredicate(inSimplePredicate), _invert(inVerted)
|
59 chuck 1.2 {
|
60 humberto 1.5
|
61 chuck 1.2 }
62
63 CQLPredicateRep::CQLPredicateRep(const CQLPredicate& inPredicate, Boolean inInverted):
|
64 humberto 1.5 _invert(inInverted)
|
65 chuck 1.2 {
|
66 humberto 1.5 _predicates.append(inPredicate);
|
67 chuck 1.2 }
68
69 CQLPredicateRep::CQLPredicateRep(const CQLPredicateRep* rep):
|
70 humberto 1.5 _invert(false)
|
71 chuck 1.2 {
72 _predicates = rep->_predicates;
73 _simplePredicate = rep->_simplePredicate;
74 _operators = rep->_operators;
75 _invert = rep->_invert;
76 }
77
78 Boolean CQLPredicateRep::evaluate(CIMInstance CI, QueryContext& QueryCtx)
79 {
|
80 humberto 1.3 PEG_METHOD_ENTER(TRC_CQL, "CQLIPredicateRep::evaluate");
|
81 chuck 1.2 Boolean result = false;
|
82 humberto 1.5
|
83 chuck 1.2 if (isSimple())
84 {
85 result = _simplePredicate.evaluate(CI, QueryCtx);
86 }
87 else
88 {
89 result = _predicates[0].evaluate(CI, QueryCtx);
90 for (Uint32 i = 0; i < _operators.size(); i++)
91 {
92 if (_operators[i] == AND)
93 {
94 if(result)
95 {
96 result = _predicates[i+1].evaluate(CI, QueryCtx);
97 }
98 }
99 else
100 {
101 if(result)
102 {
103 break;
104 chuck 1.2 }
105 else
106 {
107 result = _predicates[i+1].evaluate(CI, QueryCtx);
108 }
109 }
110 }
111 }
|
112 humberto 1.3 PEG_METHOD_EXIT();
|
113 chuck 1.2 return (getInverted()) ? !result : result;
114 }
115
116 Boolean CQLPredicateRep::getInverted()const{
117 return _invert;
118 }
119
|
120 humberto 1.6 void CQLPredicateRep::setInverted(Boolean invert){
121 _invert = invert;
|
122 chuck 1.2 }
123
124 void CQLPredicateRep::appendPredicate(const CQLPredicate& inPredicate){
125 _predicates.append(inPredicate);
126 }
127
128 void CQLPredicateRep::appendPredicate(const CQLPredicate& inPredicate, BooleanOpType inBooleanOperator)
129 {
130 _predicates.append(inPredicate);
131 _operators.append(inBooleanOperator);
132 }
133
134 Array<CQLPredicate> CQLPredicateRep::getPredicates()const{
135 return _predicates;
136 }
137
138 CQLSimplePredicate CQLPredicateRep::getSimplePredicate()const{
139 return _simplePredicate;
140 }
141
142 Array<BooleanOpType> CQLPredicateRep::getOperators()const{
143 chuck 1.2 return _operators;
144 }
145
|
146 vijay.eli 1.8 void CQLPredicateRep::applyContext(const QueryContext& queryContext)
|
147 chuck 1.2 {
|
148 humberto 1.3 PEG_METHOD_ENTER(TRC_CQL, "CQLPredicateRep::applyContext");
|
149 chuck 1.2 if (isSimple())
150 {
151 _simplePredicate.applyContext(queryContext);
152 }
153 else
154 {
155 for (Uint32 i = 0; i <_predicates.size(); i++)
156 {
157 _predicates[i].applyContext(queryContext);
158 }
159 }
|
160 humberto 1.3 PEG_METHOD_EXIT();
|
161 chuck 1.2 }
162
163 Boolean CQLPredicateRep::isSimple()const{
164 return (_predicates.size() == 0);
165 }
166
167 Boolean CQLPredicateRep::isSimpleValue()const{
|
168 humberto 1.5 return (isSimple() && _simplePredicate.isSimpleValue());
|
169 chuck 1.2 }
170
171 String CQLPredicateRep::toString()const{
172 if(isSimple()){
173 String s;
|
174 humberto 1.5 if(_invert) s = "NOT ";
175 s.append(_simplePredicate.toString());
176 return s;
|
177 chuck 1.2 }
178 String s;
179 if(_invert) s = "NOT ";
180 for(Uint32 i = 0; i < _predicates.size(); i++){
181 s.append(_predicates[i].toString());
182 if(i < _operators.size()){
183 switch(_operators[i]){
184 case AND: s.append(" AND ");
185 break;
186 case OR: s.append(" OR ");
187 break;
188 }
189 }
190 }
191 return s;
192 }
193
194 PEGASUS_NAMESPACE_END
|