KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > condition > EntityConditionListBase


1 /*
2  * $Id: EntityConditionListBase.java 5831 2005-09-26 06:52:24Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.entity.condition;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.ofbiz.base.util.Debug;
32 import org.ofbiz.entity.EntityCryptoException;
33 import org.ofbiz.entity.GenericDelegator;
34 import org.ofbiz.entity.GenericModelException;
35 import org.ofbiz.entity.model.ModelEntity;
36 import org.ofbiz.entity.model.ModelField;
37
38 /**
39  * Encapsulates a list of EntityConditions to be used as a single EntityCondition combined as specified
40  *
41  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
42  * @version $Rev: 5831 $
43  * @since 2.0
44  */

45 public abstract class EntityConditionListBase extends EntityCondition {
46     public static final String JavaDoc module = EntityConditionListBase.class.getName();
47
48     protected List JavaDoc conditionList;
49     protected EntityJoinOperator operator;
50
51     protected EntityConditionListBase() {}
52
53     public EntityConditionListBase(List JavaDoc conditionList, EntityJoinOperator operator) {
54         this.conditionList = conditionList;
55         this.operator = operator;
56     }
57
58     public EntityOperator getOperator() {
59         return this.operator;
60     }
61
62     public EntityCondition getCondition(int index) {
63         return (EntityCondition) this.conditionList.get(index);
64     }
65     
66     protected int getConditionListSize() {
67         return this.conditionList.size();
68     }
69     
70     protected Iterator JavaDoc getConditionIterator() {
71         return this.conditionList.iterator();
72     }
73     
74     public void visit(EntityConditionVisitor visitor) {
75         visitor.acceptEntityJoinOperator(operator, conditionList);
76     }
77
78     public String JavaDoc makeWhereString(ModelEntity modelEntity, List JavaDoc entityConditionParams) {
79         // if (Debug.verboseOn()) Debug.logVerbose("makeWhereString for entity " + modelEntity.getEntityName(), module);
80
StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
81         operator.addSqlValue(sql, modelEntity, entityConditionParams, conditionList);
82         return sql.toString();
83     }
84
85     public void checkCondition(ModelEntity modelEntity) throws GenericModelException {
86         // if (Debug.verboseOn()) Debug.logVerbose("checkCondition for entity " + modelEntity.getEntityName(), module);
87
operator.validateSql(modelEntity, conditionList);
88     }
89
90     public boolean mapMatches(GenericDelegator delegator, Map JavaDoc map) {
91         return operator.mapMatches(delegator, map, conditionList);
92     }
93
94     public EntityCondition freeze() {
95         return operator.freeze(conditionList);
96     }
97
98     public void encryptConditionFields(ModelEntity modelEntity, GenericDelegator delegator) {
99         Iterator JavaDoc conditionIter = this.conditionList.iterator();
100         while (conditionIter.hasNext()) {
101             EntityCondition cond = (EntityCondition) conditionIter.next();
102             cond.encryptConditionFields(modelEntity, delegator);
103         }
104     }
105     
106     public boolean equals(Object JavaDoc obj) {
107         if (!(obj instanceof EntityConditionListBase)) return false;
108         EntityConditionListBase other = (EntityConditionListBase) obj;
109         
110         boolean isEqual = conditionList.equals(other.conditionList) && operator.equals(other.operator);
111         //if (!isEqual) {
112
// Debug.logWarning("EntityConditionListBase.equals is false:\n this.operator=" + this.operator + "; other.operator=" + other.operator +
113
// "\nthis.conditionList=" + this.conditionList +
114
// "\nother.conditionList=" + other.conditionList, module);
115
//}
116
return isEqual;
117     }
118
119     public int hashCode() {
120         return conditionList.hashCode() + operator.hashCode();
121     }
122 }
123
Popular Tags