View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  }