1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 }