01: package com.technoetic.xplanner.domain.repository;
02:
03: import com.technoetic.xplanner.domain.Role;
04: import com.technoetic.xplanner.domain.RoleAssociation;
05: import net.sf.hibernate.Hibernate;
06: import net.sf.hibernate.HibernateException;
07: import net.sf.hibernate.type.Type;
08:
09: public class RoleAssociationRepositoryImpl extends
10: HibernateObjectRepository implements RoleAssociationRepository {
11: private RoleRepository roleRepository;
12:
13: public RoleAssociationRepositoryImpl() throws HibernateException {
14: super (RoleAssociation.class);
15: }
16:
17: public void deleteAllForPersonOnProject(int personId, int projectId)
18: throws RepositoryException {
19: getHibernateTemplate()
20: .delete(
21: "from assoc in "
22: + RoleAssociation.class
23: + " where assoc.personId = ? and assoc.projectId = ?",
24: new Object[] { new Integer(personId),
25: new Integer(projectId) },
26: new Type[] { Hibernate.INTEGER,
27: Hibernate.INTEGER });
28: }
29:
30: public void deleteForPersonOnProject(String roleName, int personId,
31: int projectId) throws RepositoryException {
32: Role role = roleRepository.findRoleByName(roleName);
33: getHibernateTemplate()
34: .delete(
35: "from assoc in "
36: + RoleAssociation.class
37: + " where assoc.roleId = ? and assoc.projectId = ? and assoc.personId = ?",
38: new Object[] { new Integer(role.getId()),
39: new Integer(projectId),
40: new Integer(personId) },
41: new Type[] { Hibernate.INTEGER,
42: Hibernate.INTEGER, Hibernate.INTEGER });
43: }
44:
45: public void insertForPersonOnProject(String roleName, int personId,
46: int projectId) throws RepositoryException {
47: Role role = roleRepository.findRoleByName(roleName);
48: if (role != null) {
49: getHibernateTemplate().save(
50: new RoleAssociation(projectId, personId, role
51: .getId()));
52: }
53: }
54:
55: public void setRoleRepository(RoleRepository roleRepository) {
56: this.roleRepository = roleRepository;
57: }
58: }
|