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.List;
021: import java.util.Map;
022:
023: import org.ofbiz.entity.GenericDelegator;
024: import org.ofbiz.entity.GenericModelException;
025: import org.ofbiz.entity.config.DatasourceInfo;
026: import org.ofbiz.entity.model.ModelEntity;
027:
028: /**
029: * Encapsulates operations between entities and entity fields. This is a immutable class.
030: *
031: */
032: public abstract class EntityConditionFunction extends EntityCondition {
033:
034: public static final int ID_NOT = 1;
035:
036: public static class NOT extends EntityConditionFunction {
037: public NOT(EntityCondition nested) {
038: super (ID_NOT, "NOT", nested);
039: }
040:
041: public boolean mapMatches(GenericDelegator delegator, Map map) {
042: return !condition.mapMatches(delegator, map);
043: }
044:
045: public EntityCondition freeze() {
046: return new NOT(condition.freeze());
047: }
048:
049: public void encryptConditionFields(ModelEntity modelEntity,
050: GenericDelegator delegator) {
051: // nothing to do here...
052: }
053: };
054:
055: protected int idInt;
056: protected String codeString;
057: protected EntityCondition condition;
058:
059: protected EntityConditionFunction(int id, String code,
060: EntityCondition condition) {
061: idInt = id;
062: codeString = code;
063: this .condition = condition;
064: }
065:
066: public String getCode() {
067: if (codeString == null)
068: return "null";
069: else
070: return codeString;
071: }
072:
073: public int getId() {
074: return idInt;
075: }
076:
077: public void visit(EntityConditionVisitor visitor) {
078: visitor.acceptEntityConditionFunction(this , condition);
079: }
080:
081: public boolean equals(Object obj) {
082: if (!(obj instanceof EntityConditionFunction))
083: return false;
084: EntityConditionFunction otherFunc = (EntityConditionFunction) obj;
085: return this .idInt == otherFunc.idInt
086: && (this .condition != null ? condition
087: .equals(otherFunc.condition)
088: : otherFunc.condition != null);
089: }
090:
091: public int hashCode() {
092: return idInt ^ condition.hashCode();
093: }
094:
095: public String makeWhereString(ModelEntity modelEntity,
096: List entityConditionParams, DatasourceInfo datasourceInfo) {
097: StringBuffer sb = new StringBuffer();
098: sb.append(codeString).append('(');
099: sb.append(condition.makeWhereString(modelEntity,
100: entityConditionParams, datasourceInfo));
101: sb.append(')');
102: return sb.toString();
103: }
104:
105: public void checkCondition(ModelEntity modelEntity)
106: throws GenericModelException {
107: condition.checkCondition(modelEntity);
108: }
109: }
|