1 package info.mikethomas.fahweb.dao;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import info.mikethomas.fahweb.model.User;
26 import java.util.List;
27 import org.hibernate.Query;
28 import org.hibernate.SessionFactory;
29 import org.springframework.stereotype.Repository;
30 import org.springframework.transaction.annotation.Transactional;
31
32
33
34
35
36
37
38 @Repository
39 public class UserDao {
40
41 private SessionFactory sessionFactory;
42
43
44
45
46
47
48 public void setSessionFactory(SessionFactory sessionFactory) {
49 this.sessionFactory = sessionFactory;
50 }
51
52
53
54
55
56
57 @Transactional
58 public void addUser(User user) {
59 sessionFactory.getCurrentSession().save(user);
60 }
61
62
63
64
65
66
67
68
69 @Transactional
70 public List<User> listUser(int firstResult, int maxResults) {
71 Query query = sessionFactory.getCurrentSession().createQuery("FROM User ORDER BY newCredit DESC");
72 query.setFirstResult(firstResult);
73 query.setMaxResults(maxResults);
74 return query.list();
75 }
76
77
78
79
80
81
82
83
84
85 @Transactional
86 public List<User> listUserForTeam(int team, int firstResult, int maxResults) {
87 Query query = sessionFactory.getCurrentSession().createQuery("FROM User WHERE team=:team ORDER BY newCredit DESC");
88 query.setFirstResult(firstResult);
89 query.setMaxResults(maxResults);
90 query.setInteger("team", team);
91 return query.list();
92 }
93 }