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.GenericEntity; 32 import org.ofbiz.entity.GenericModelException; 33 import org.ofbiz.entity.config.DatasourceInfo; 34 import org.ofbiz.entity.model.ModelEntity; 35 import org.ofbiz.entity.model.ModelField; 36 37 46 public class EntityFieldValue extends EntityConditionValue { 47 48 protected String fieldName; 49 50 public EntityFieldValue(String fieldName) { 51 this.fieldName = fieldName; 52 } 53 54 public String getFieldName() { 55 return fieldName; 56 } 57 58 public int hashCode() { 59 return fieldName.hashCode(); 60 } 61 62 public boolean equals(Object obj) { 63 if (!(obj instanceof EntityFieldValue)) return false; 64 EntityFieldValue otherValue = (EntityFieldValue) obj; 65 return fieldName.equals(otherValue.fieldName); 66 } 67 68 public ModelField getModelField(ModelEntity modelEntity) { 69 return getField(modelEntity, fieldName); 70 } 71 72 public void addSqlValue(StringBuffer sql, Map tableAliases, ModelEntity modelEntity, List entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { 73 sql.append(getColName(tableAliases, modelEntity, fieldName, includeTableNamePrefix, datasourceInfo)); 74 } 75 76 public void validateSql(ModelEntity modelEntity) throws GenericModelException { 77 ModelField field = getModelField(modelEntity); 78 if (field == null) { 79 throw new GenericModelException("Field with name " + fieldName + " not found in the " + modelEntity.getEntityName() + " Entity"); 80 } 81 } 82 83 public Object getValue(GenericDelegator delegator, Map map) { 84 if (map == null) { 85 return null; 86 } 87 if (map instanceof GenericEntity.NULL) { 88 return null; 89 } else { 90 return map.get(fieldName); 91 } 92 } 93 94 public void visit(EntityConditionVisitor visitor) { 95 visitor.acceptEntityFieldValue(this); 96 } 97 98 public void accept(EntityConditionVisitor visitor) { 99 visitor.acceptEntityFieldValue(this); 100 } 101 102 public EntityConditionValue freeze() { 103 return this; 104 } 105 } 106 | Popular Tags |