1 24 25 package org.ofbiz.entity.condition; 26 27 import java.util.List ; 28 import java.util.Map ; 29 30 import org.ofbiz.entity.GenericDelegator; 31 import org.ofbiz.entity.GenericModelException; 32 import org.ofbiz.entity.model.ModelEntity; 33 34 43 public abstract class EntityConditionFunction extends EntityCondition { 44 45 public static final int ID_NOT = 1; 46 47 public static class NOT extends EntityConditionFunction { 48 public NOT(EntityCondition nested) { super(ID_NOT, "NOT", nested); } 49 public boolean mapMatches(GenericDelegator delegator, Map map) { 50 return !condition.mapMatches(delegator, map); 51 } 52 public EntityCondition freeze() { 53 return new NOT(condition.freeze()); 54 } 55 public void encryptConditionFields(ModelEntity modelEntity, GenericDelegator delegator) { 56 } 58 }; 59 60 protected int idInt; 61 protected String codeString; 62 protected EntityCondition condition; 63 64 protected EntityConditionFunction(int id, String code, EntityCondition condition) { 65 idInt = id; 66 codeString = code; 67 this.condition = condition; 68 } 69 70 public String getCode() { 71 if (codeString == null) 72 return "null"; 73 else 74 return codeString; 75 } 76 77 public int getId() { 78 return idInt; 79 } 80 81 public void visit(EntityConditionVisitor visitor) { 82 visitor.acceptEntityConditionFunction(this, condition); 83 } 84 85 public boolean equals(Object obj) { 86 if (!(obj instanceof EntityConditionFunction)) return false; 87 EntityConditionFunction otherFunc = (EntityConditionFunction) obj; 88 return 89 this.idInt == otherFunc.idInt 90 && ( this.condition != null ? condition.equals( otherFunc.condition ) : otherFunc.condition != null ); 91 } 92 93 public int hashCode() { 94 return idInt ^ condition.hashCode(); 95 } 96 97 public String makeWhereString(ModelEntity modelEntity, List entityConditionParams) { 98 StringBuffer sb = new StringBuffer (); 99 sb.append(codeString).append('('); 100 sb.append(condition.makeWhereString(modelEntity, entityConditionParams)); 101 sb.append(')'); 102 return sb.toString(); 103 } 104 105 public void checkCondition(ModelEntity modelEntity) throws GenericModelException { 106 condition.checkCondition(modelEntity); 107 } 108 } 109 | Popular Tags |