1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.seasar.tuigwaa.database.function.criteria;
23
24 import java.util.Calendar;
25 import java.util.Date;
26
27 import org.seasar.tuigwaa.model.core.impl.TimestampAttribute;
28
29 /***
30 * @author nishioka
31 */
32 public class LeCriteriaFunction extends AbstractCriteriaFunction {
33
34 public LeCriteriaFunction() {
35 super();
36 }
37
38 public LeCriteriaFunction(String field) {
39 super(field);
40 }
41
42 public LeCriteriaFunction(String field, Object value) {
43 super(field, value);
44 }
45
46 public Object evaluate(ICriteria criteria) {
47 return criteria.addLe(getField(), getValue());
48 }
49
50 public Object evaluate(ICriteria criteria, Object value) {
51
52 if (value instanceof Date
53 && criteria.getEntity() != null
54 && criteria.getEntity().getField(getField()) instanceof TimestampAttribute) {
55 Date date = (Date)value;
56 Calendar cal = Calendar.getInstance();
57 cal.setTime(date);
58 cal.add(Calendar.DATE , +1);
59 cal.add(Calendar.MILLISECOND, -1);
60 value = cal.getTime();
61 }
62 return criteria.addLe(getField(), value);
63 }
64
65
66
67 }