001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.entity.condition;
019:
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.ofbiz.entity.GenericDelegator;
025: import org.ofbiz.entity.GenericModelException;
026: import org.ofbiz.entity.config.DatasourceInfo;
027: import org.ofbiz.entity.model.ModelEntity;
028:
029: /**
030: * Encapsulates a list of EntityConditions to be used as a single EntityCondition combined as specified
031: *
032: */
033: public abstract class EntityConditionListBase extends EntityCondition {
034: public static final String module = EntityConditionListBase.class
035: .getName();
036:
037: protected List conditionList;
038: protected EntityJoinOperator operator;
039:
040: protected EntityConditionListBase() {
041: }
042:
043: public EntityConditionListBase(List conditionList,
044: EntityJoinOperator operator) {
045: this .conditionList = conditionList;
046: this .operator = operator;
047: }
048:
049: public EntityOperator getOperator() {
050: return this .operator;
051: }
052:
053: public EntityCondition getCondition(int index) {
054: return (EntityCondition) this .conditionList.get(index);
055: }
056:
057: protected int getConditionListSize() {
058: return this .conditionList.size();
059: }
060:
061: protected Iterator getConditionIterator() {
062: return this .conditionList.iterator();
063: }
064:
065: public void visit(EntityConditionVisitor visitor) {
066: visitor.acceptEntityJoinOperator(operator, conditionList);
067: }
068:
069: public String makeWhereString(ModelEntity modelEntity,
070: List entityConditionParams, DatasourceInfo datasourceInfo) {
071: // if (Debug.verboseOn()) Debug.logVerbose("makeWhereString for entity " + modelEntity.getEntityName(), module);
072: StringBuffer sql = new StringBuffer();
073: operator.addSqlValue(sql, modelEntity, entityConditionParams,
074: conditionList, datasourceInfo);
075: return sql.toString();
076: }
077:
078: public void checkCondition(ModelEntity modelEntity)
079: throws GenericModelException {
080: // if (Debug.verboseOn()) Debug.logVerbose("checkCondition for entity " + modelEntity.getEntityName(), module);
081: operator.validateSql(modelEntity, conditionList);
082: }
083:
084: public boolean mapMatches(GenericDelegator delegator, Map map) {
085: return operator.mapMatches(delegator, map, conditionList);
086: }
087:
088: public EntityCondition freeze() {
089: return operator.freeze(conditionList);
090: }
091:
092: public void encryptConditionFields(ModelEntity modelEntity,
093: GenericDelegator delegator) {
094: Iterator conditionIter = this .conditionList.iterator();
095: while (conditionIter.hasNext()) {
096: EntityCondition cond = (EntityCondition) conditionIter
097: .next();
098: cond.encryptConditionFields(modelEntity, delegator);
099: }
100: }
101:
102: public boolean equals(Object obj) {
103: if (!(obj instanceof EntityConditionListBase))
104: return false;
105: EntityConditionListBase other = (EntityConditionListBase) obj;
106:
107: boolean isEqual = conditionList.equals(other.conditionList)
108: && operator.equals(other.operator);
109: //if (!isEqual) {
110: // Debug.logWarning("EntityConditionListBase.equals is false:\n this.operator=" + this.operator + "; other.operator=" + other.operator +
111: // "\nthis.conditionList=" + this.conditionList +
112: // "\nother.conditionList=" + other.conditionList, module);
113: //}
114: return isEqual;
115: }
116:
117: public int hashCode() {
118: return conditionList.hashCode() + operator.hashCode();
119: }
120: }
|