View Javadoc
1   package org.itracker.persistence.dao;
2   
3   import org.hibernate.HibernateException;
4   import org.hibernate.Query;
5   import org.itracker.model.Project;
6   
7   import java.util.Date;
8   import java.util.List;
9   
10  /**
11   * This is the implementation bean that seems to make the Hibernate request.
12   *
13   * @author ready
14   */
15  public class ProjectDAOImpl extends BaseHibernateDAOImpl<Project>
16          implements ProjectDAO {
17  
18      public Project findByPrimaryKey(Integer projectId) {
19          Project project;
20          try {
21              project = (Project) getSession().get(Project.class, projectId);
22          } catch (HibernateException ex) {
23              throw convertHibernateAccessException(ex);
24          }
25          return project;
26      }
27  
28      @SuppressWarnings("unchecked")
29      public List<Project> findAll() {
30          List<Project> projects;
31  
32          try {
33              Query query = getSession().getNamedQuery("ProjectsAllQuery");
34              projects = query.list();
35          } catch (HibernateException ex) {
36              throw convertHibernateAccessException(ex);
37          }
38          return projects;
39      }
40  
41      @SuppressWarnings("unchecked")
42      public List<Project> findByStatus(int status) {
43          List<Project> projects;
44  
45          try {
46              Query query = getSession().getNamedQuery("ProjectsByStatusQuery");
47              query.setInteger("projectStatus", status);
48              projects = query.list();
49          } catch (HibernateException ex) {
50              throw convertHibernateAccessException(ex);
51          }
52          return projects;
53      }
54  
55      @SuppressWarnings("unchecked")
56      public List<Project> findAllAvailable() {
57          List<Project> projects;
58  
59          try {
60              Query query = getSession().getNamedQuery("ProjectsAvailableQuery");
61              projects = query.list();
62          } catch (HibernateException ex) {
63              throw convertHibernateAccessException(ex);
64          }
65          return projects;
66      }
67  
68      @SuppressWarnings("unchecked")
69      public Date getLastIssueUpdateDate(Integer projectId) {
70          Query q = getSession().getNamedQuery("ProjectsLastModifiedIssueDate");
71          q.setParameter("projectId", projectId);
72  
73          List result = q.list();
74          if (result != null && result.size() == 1) {
75              return (Date) result.get(0);
76          }
77          return null;
78      }
79  
80      public Project findByName(String name) {
81  
82          Object project;
83          try {
84              Query query = getSession().getNamedQuery("ProjectByNameQuery");
85              query.setParameter("projectName", name);
86              project = query.uniqueResult();
87              return (Project) project;
88          } catch (HibernateException ex) {
89              throw convertHibernateAccessException(ex);
90          }
91  
92      }
93  
94  }