1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.plugin.database;
17
18 import org.seasar.tuigwaa.database.DataTable;
19 import org.seasar.tuigwaa.database.function.criteria.CriteriaListFunction;
20 import org.seasar.tuigwaa.database.function.criteria.EqCriteriaFunction;
21 import org.seasar.tuigwaa.database.function.criteria.MaxResultCriteriaFunction;
22 import org.seasar.tuigwaa.database.function.criteria.OrderCriteriaFunction;
23 import org.seasar.tuigwaa.model.common.EntityDAO;
24 import org.seasar.tuigwaa.plugin.DaoPlugin;
25 import org.seasar.tuigwaa.system.Constants;
26
27 public class CommentDao extends DaoPlugin {
28
29 public CommentDao(EntityDAO dao) {
30 super(dao);
31 }
32
33 public void save(Comment comment) {
34
35
36 getDao().saveOrUpdate(comment);
37 }
38
39 public DataTable getComments(String siteName, String pageName, int maxSize, String extraKey) {
40 CriteriaListFunction function = new CriteriaListFunction();
41 EqCriteriaFunction eq = new EqCriteriaFunction("pageName", pageName);
42 OrderCriteriaFunction order = new OrderCriteriaFunction(
43 Constants.ENTITY_BUILTIN_CREATIONDATE, null, true);
44 function.addFunction(eq);
45 function.addFunction(order);
46
47 if(extraKey != null && extraKey.length() > 0){
48 EqCriteriaFunction extraKeyEq = new EqCriteriaFunction("extraKey", extraKey);
49 function.addFunction(extraKeyEq);
50 }
51
52 if (maxSize >= 0) {
53 function.addFunction(new MaxResultCriteriaFunction(maxSize));
54 }
55
56 return (DataTable) getDao().getMethod(EntityDAO.INJECT_CRITERIA)
57 .evaluate(function);
58 }
59 }