1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.imca.model.entities;
17
18 import java.util.Collection;
19 import java.util.List;
20
21 import javax.persistence.EntityManager;
22 import javax.persistence.Query;
23
24 import net.sf.imca.model.AssociationBO;
25
26 public class AssociationDAO {
27
28 @SuppressWarnings("unchecked")
29 public AssociationEntity findAssociation(EntityManager em,
30 String countryCode, String area) {
31
32 Query query = em.createNamedQuery("findAssociationByCountryCodeAndArea");
33 query.setParameter("isoCountryCode", countryCode);
34 query.setParameter("area", area);
35 List<AssociationEntity> list = query.getResultList();
36
37 if (list.size() == 1) {
38 return list.get(0);
39 }
40 return null;
41 }
42
43
44 @SuppressWarnings("unchecked")
45 public List<AssociationEntity> getAssociationsInCountry(EntityManager em,
46 String countryCode) {
47
48 Query query = em.createNamedQuery("findAssociationByCountryCode");
49 query.setParameter("isoCountryCode", countryCode);
50
51 return query.getResultList();
52
53 }
54
55 @SuppressWarnings("unchecked")
56 public List<CommitteeMemberEntity> findCommitteeMemberships(EntityManager em,
57 PersonEntity person) {
58
59 Query query = em.createNamedQuery("findCommitteeMemberships");
60 query.setParameter("person", person);
61
62 return query.getResultList();
63
64 }
65
66 @SuppressWarnings("unchecked")
67 public List<MembershipTypeEntity> findMembershipTypes(EntityManager em,
68 AssociationEntity association) {
69
70 Query query = em.createNamedQuery("findMembershipTypes");
71 query.setParameter("association", association);
72
73 return query.getResultList();
74
75 }
76
77 public AssociationBO getWorldAssociation(EntityManager em) {
78
79 Query query = em.createNamedQuery("findAssociationByCountryCode");
80 query.setParameter("isoCountryCode", AssociationBO.IMCA_WORLD_COUNTRY_CODE);
81 if ( query.getResultList().size() == 1) {
82 return new AssociationBO((AssociationEntity)
83 query.getResultList().get(0));
84 } else {
85 return null;
86 }
87
88 }
89
90 public List<AssociationEntity> getAssociations(EntityManager em, boolean official) {
91
92 Query query = em.createNamedQuery("findAssociationByIsOfficial");
93 query.setParameter("isOfficial", official);
94 List<AssociationEntity> resultList = query.getResultList();
95 return resultList;
96 }
97
98 @SuppressWarnings("unchecked")
99 public List<AssociationEntity> getAllAssociations(EntityManager em) {
100 Query query = em.createNamedQuery("findAllAssociations");
101 return query.getResultList();
102 }
103
104 @SuppressWarnings("unchecked")
105 public List<AssociationEntity> getAssociationsWithWebsites(EntityManager em) {
106 Query query = em.createNamedQuery("findAssociationsWithWebsites");
107 return query.getResultList();
108 }
109
110 }