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.List;
20  
21  import org.appfuse.dao.hibernate.GenericDaoHibernate;
22  import org.in2.simpleBoard.InternalException;
23  import org.in2.simpleBoard.dao.PersonDao;
24  import org.in2.simpleBoard.model.Person;
25  
26  public class PersonDaoHibernate extends GenericDaoHibernate<Person, Long> implements PersonDao {
27  
28      public PersonDaoHibernate() {
29          super(Person.class);
30      }
31  
32      public Person findByUserName(String userName) throws InternalException {
33          List<Person> users = getHibernateTemplate().find("from Person where userName=?", userName);
34          if (users.size() > 1) {
35          	throw new InternalException();
36          }
37          if(users != null)
38          	return users.get(0);
39          else
40          	return null;
41      }
42  
43      public List<Person> findByName(String name) {
44          return getHibernateTemplate().find("from Person where name=?", name);        
45      }
46  
47      public List<Person> findBySurname(String surname) {
48          return getHibernateTemplate().find("from Person where surname=?", surname);
49      }
50  
51      public List<Person> findByEmail(String email) {
52          return getHibernateTemplate().find("from Person where email=?", email);
53      }
54  
55  }