1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.database.function.aggregation;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.seasar.tuigwaa.database.function.criteria.AbstractCriteriaFunction;
23 import org.seasar.tuigwaa.database.function.criteria.ICriteria;
24
25 import com.isenshi.util.functor.UnaryFunction;
26
27 public class AggregationFunction extends AbstractCriteriaFunction {
28
29 private List functionList = new ArrayList();
30
31 public List getFunctionList() {
32 return functionList;
33 }
34
35 public void addFunction(UnaryFunction function) {
36 if(function!=null){
37 functionList.add(function);
38 }
39 }
40
41 public Object evaluate(ICriteria criteria) {
42 return evaluate(criteria, null);
43 }
44
45 public Object evaluate(ICriteria criteria, Object value) {
46 IProjectionList projectionList = new HibernateProjectionList();
47
48
49 for (Iterator i = functionList.iterator(); i.hasNext();) {
50 ProjectionFunction function = (ProjectionFunction) i.next();
51 String field = function.getField();
52
53
54
55
56
57 if (field!=null&&field.indexOf(".") > 0) {
58 int index = field.indexOf(".");
59 String subcriteria = field.substring(0, index);
60 criteria.createCriteria(subcriteria, subcriteria);
61 }
62 projectionList = (IProjectionList) function.evaluate(projectionList);
63 }
64 return criteria.setProjection(projectionList);
65 }
66 }