1 25 package org.ofbiz.entity.condition; 26 27 import java.sql.Timestamp ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.ofbiz.base.util.UtilDateTime; 32 import org.ofbiz.entity.GenericDelegator; 33 import org.ofbiz.entity.GenericModelException; 34 import org.ofbiz.entity.model.ModelEntity; 35 36 public class EntityDateFilterCondition extends EntityCondition { 37 38 protected String fromDateName; 39 protected String thruDateName; 40 41 public EntityDateFilterCondition(String fromDateName, String thruDateName) { 42 this.fromDateName = fromDateName; 43 this.thruDateName = thruDateName; 44 } 45 46 public String makeWhereString(ModelEntity modelEntity, List entityConditionParams) { 47 EntityCondition condition = makeCondition(); 48 return condition.makeWhereString(modelEntity, entityConditionParams); 49 } 50 51 public void checkCondition(ModelEntity modelEntity) throws GenericModelException { 52 EntityCondition condition = makeCondition(); 53 condition.checkCondition(modelEntity); 54 } 55 56 public boolean mapMatches(GenericDelegator delegator, Map map) { 57 EntityCondition condition = makeCondition(); 58 return condition.mapMatches(delegator, map); 59 } 60 61 public boolean equals(Object obj) { 62 if (!(obj instanceof EntityDateFilterCondition)) return false; 63 EntityDateFilterCondition other = (EntityDateFilterCondition) obj; 64 return equals(fromDateName, other.fromDateName) && equals(thruDateName, other.thruDateName); 65 } 66 67 public int hashCode() { 68 return hashCode(fromDateName) ^ hashCode(thruDateName); 69 } 70 71 public void visit(EntityConditionVisitor visitor) { 72 visitor.acceptEntityDateFilterCondition(this); 73 } 74 75 public void accept(EntityConditionVisitor visitor) { 76 visitor.acceptEntityDateFilterCondition(this); 77 } 78 79 public EntityCondition freeze() { 80 return this; 81 } 82 83 public void encryptConditionFields(ModelEntity modelEntity, GenericDelegator delegator) { 84 } 86 87 protected EntityCondition makeCondition() { 88 return makeCondition(UtilDateTime.nowTimestamp(), fromDateName, thruDateName); 89 } 90 91 public static EntityExpr makeCondition(Timestamp moment, String fromDateName, String thruDateName) { 92 return new EntityExpr( 93 new EntityExpr( 94 new EntityExpr( thruDateName, EntityOperator.EQUALS, null ), 95 EntityOperator.OR, 96 new EntityExpr( thruDateName, EntityOperator.GREATER_THAN, moment ) 97 ), 98 EntityOperator.AND, 99 new EntityExpr( 100 new EntityExpr( fromDateName, EntityOperator.EQUALS, null ), 101 EntityOperator.OR, 102 new EntityExpr( fromDateName, EntityOperator.LESS_THAN_EQUAL_TO, moment ) 103 ) 104 ); 105 } 106 } 107 | Popular Tags |