01: /*
02: * $Id: EntityDateFilterCondition.java,v 1.1 2003/11/05 12:08:00 jonesde Exp $
03: *
04: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: *
24: */
25: package org.ofbiz.entity.condition;
26:
27: import java.util.List;
28: import java.sql.Timestamp;
29:
30: import org.ofbiz.base.util.UtilDateTime;
31: import org.ofbiz.entity.GenericEntity;
32: import org.ofbiz.entity.GenericModelException;
33: import org.ofbiz.entity.model.ModelEntity;
34:
35: public class EntityDateFilterCondition extends EntityCondition {
36:
37: protected String fromDateName;
38: protected String thruDateName;
39:
40: public EntityDateFilterCondition(String fromDateName,
41: String thruDateName) {
42: this .fromDateName = fromDateName;
43: this .thruDateName = thruDateName;
44: }
45:
46: public String makeWhereString(ModelEntity modelEntity,
47: List entityConditionParams) {
48: EntityCondition condition = makeCondition();
49: return condition.makeWhereString(modelEntity,
50: entityConditionParams);
51: }
52:
53: public void checkCondition(ModelEntity modelEntity)
54: throws GenericModelException {
55: EntityCondition condition = makeCondition();
56: condition.checkCondition(modelEntity);
57: }
58:
59: public boolean entityMatches(GenericEntity entity) {
60: EntityCondition condition = makeCondition();
61: return condition.entityMatches(entity);
62: }
63:
64: protected EntityCondition makeCondition() {
65: return makeCondition(UtilDateTime.nowTimestamp(), fromDateName,
66: thruDateName);
67: }
68:
69: public static EntityExpr makeCondition(Timestamp moment,
70: String fromDateName, String thruDateName) {
71: return new EntityExpr(new EntityExpr(new EntityExpr(
72: thruDateName, EntityOperator.EQUALS, null),
73: EntityOperator.OR, new EntityExpr(thruDateName,
74: EntityOperator.GREATER_THAN, moment)),
75: EntityOperator.AND, new EntityExpr(new EntityExpr(
76: fromDateName, EntityOperator.EQUALS, null),
77: EntityOperator.OR, new EntityExpr(fromDateName,
78: EntityOperator.LESS_THAN_EQUAL_TO,
79: moment)));
80: }
81: }
|