1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.model.common;
17
18 import java.util.Collections;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.Map;
22
23 import org.seasar.tuigwaa.database.DataTable;
24 import org.seasar.tuigwaa.database.function.DaoMethod;
25 import org.seasar.tuigwaa.database.function.criteria.CriteriaListFunction;
26 import org.seasar.tuigwaa.database.function.criteria.EqCriteriaFunction;
27
28
29 public class EntityDAOImpl implements EntityDAO {
30
31 private Map funcMap_ = Collections.synchronizedMap(new HashMap());
32
33 public EntityDAOImpl(Map funcMap) {
34 funcMap_.putAll(funcMap);
35 }
36
37 public DaoMethod getMethod(String methodName) {
38 return (DaoMethod) funcMap_.get(methodName);
39 }
40
41 public Object load(Long id) {
42 return getMethod(LOAD).evaluate(id);
43 }
44
45 public Object loadByValue(String attrName, Object value) {
46 DaoMethod method = getMethod(INJECT_CRITERIA);
47 EqCriteriaFunction eq = new EqCriteriaFunction(attrName, value);
48 DataTable dataTable = (DataTable) method.evaluate(eq);
49 if (dataTable.getRowSize() > 0) {
50 return dataTable.getRowObject(0);
51 } else {
52 return null;
53 }
54 }
55
56 public void delete(Long id) {
57 getMethod(DELETE).evaluate(id);
58 }
59
60 public void deleteAll() {
61 getMethod(DELETEALL).evaluate();
62 }
63
64 public void saveOrUpdate(Object obj) {
65 getMethod(SAVEUPDATE).evaluate(obj);
66 }
67
68 public DataTable list() {
69 return (DataTable) getMethod(LIST).evaluate();
70 }
71
72 public DataTable find(Map filterMap) {
73 CriteriaListFunction list = new CriteriaListFunction();
74 for(Iterator i = filterMap.keySet().iterator();i.hasNext();){
75 String key = (String)i.next();
76 Object value = filterMap.get(key);
77 list.addFunction(new EqCriteriaFunction(key, value));
78 }
79 return (DataTable)getMethod(INJECT_CRITERIA).evaluate(list);
80 }
81
82 public Object getValue(String name) {
83 return getMethod(name).evaluate();
84 }
85 }