View Javadoc

1   /**
2   Copyright (C) 2007  <name of author>
3   
4   This program is free software: you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation, either version 3 of the License, or
7   (at your option) any later version.
8   
9   This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  GNU General Public License for more details.
13  
14  You should have received a copy of the GNU General Public License
15  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17  package org.in2.simpleBoard.dao.hibernate;
18  
19  import java.util.Date;
20  import java.util.List;
21  
22  import org.appfuse.dao.hibernate.GenericDaoHibernate;
23  import org.in2.simpleBoard.dao.BoardDao;
24  import org.in2.simpleBoard.model.Person;
25  import org.in2.simpleBoard.model.Board;
26  import org.in2.simpleBoard.model.Category;
27  
28  public class BoardDaoHibernate extends GenericDaoHibernate<Board, Long> implements BoardDao {
29  
30      public BoardDaoHibernate() {
31          super(Board.class);
32      }
33  
34      public List<Board> findByUser(Person user) {
35          return findByUserId(user.getId());
36      }
37  
38      public List<Board> findByUserId(Long userId) {
39          return getHibernateTemplate().find("from Board where idUser = ?", userId);
40      }
41  
42      public List<Board> findByCategory(Category category) {
43          return findByUserId(category.getId());
44      }
45      
46      public List<Board> findAllBoard(){
47          return getHibernateTemplate().find("from Board");
48      }
49      
50      public List<Board> findByCategoryId(Long categoryId) {
51          return getHibernateTemplate().find("from Board where idCategory = ?", categoryId);
52      }
53  
54      public List<Board> findByBoard(Board board) {
55          return findByUserId(board.getId());
56      }
57  
58      public Board findByBoardId(Long boardId) {
59      	return (Board) getHibernateTemplate().get(Board.class, boardId);
60      }
61  
62      public List<Board> findByDate(Date date) {
63          //throw new UnsupportedOperationException("Not supported yet.");
64          return getHibernateTemplate().find("from Board where date = ?", "2007-01-01");
65      }
66  
67  }