View Javadoc

1   /*
2    * Copyright 2007 The International Moth Class Association (IMCA)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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 }