1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 package net.sf.pmr.core.data.user;
37
38 import java.util.ArrayList;
39 import java.util.Collection;
40 import java.util.HashSet;
41 import java.util.List;
42 import java.util.Set;
43
44 import net.sf.pmr.core.domain.basicProject.BasicProject;
45 import net.sf.pmr.core.domain.user.User;
46 import net.sf.pmr.core.domain.user.UserImpl;
47
48 import org.springframework.dao.support.DataAccessUtils;
49
50 /***
51 * @author Arnaud
52 */
53 public class UserMapperImpl extends
54 org.springframework.orm.hibernate3.support.HibernateDaoSupport
55 implements UserMapper {
56
57 /***
58 * find a user by his Id
59 *
60 * @param id
61 * id
62 * @return Entity User find
63 */
64 public final Object findById(final int id) {
65
66 return (User) getHibernateTemplate().get(UserImpl.class,
67 new Integer(id));
68
69 }
70
71 /***
72 * find a user by his login
73 *
74 * @param login
75 * login
76 * @return Entity User find
77 */
78 public final User findByLogin(final String login) {
79
80 List list = getHibernateTemplate()
81 .find(
82 "from net.sf.pmr.core.domain.user.UserImpl user where user.Login = ?",
83 login);
84 return (User) DataAccessUtils.uniqueResult(list);
85
86 }
87
88 /***
89 * find all users
90 *
91 * @return List of user
92 */
93 public final List findAll() {
94
95 return getHibernateTemplate().loadAll(User.class);
96
97 }
98
99 /***
100 * Count All User
101 *
102 * @return int number of user
103 */
104 public final Integer countAll() {
105
106 List list = getHibernateTemplate().find(
107 "select count(*) from net.sf.pmr.core.domain.user.UserImpl");
108 return (Integer) DataAccessUtils.uniqueResult(list);
109
110 }
111
112 /***
113 * add or update a user
114 *
115 * @param entity
116 * user to update
117 */
118 public final void addOrUpdate(final Object entity) {
119
120 getHibernateTemplate().saveOrUpdate((User) entity);
121
122 }
123
124 /***
125 * Delete a user
126 *
127 * @param entity
128 * user to delete
129 */
130 public final void delete(final Object entity) {
131
132 getHibernateTemplate().delete((User) entity);
133
134 }
135
136 /***
137 * @see net.sf.pmr.keopsframework.data.DomainListMapper#findCollectionForObject(java.lang.Object)
138 */
139 public final Collection findCollectionForObject(final Object object) {
140
141 Set collectionToReturn = new HashSet();
142
143 if (object instanceof BasicProject) {
144
145 BasicProject basicProject = (BasicProject) object;
146
147 List list = getHibernateTemplate()
148 .find(
149 "from net.sf.pmr.core.domain.user.UserImpl user where ? in elements(user.Projects)",
150 basicProject);
151
152 collectionToReturn.addAll(list);
153
154 }
155
156 return collectionToReturn;
157
158 }
159 }