View Javadoc
1   package org.itracker.persistence.dao;
2   
3   import org.hibernate.HibernateException;
4   import org.hibernate.Query;
5   import org.itracker.model.ProjectScript;
6   
7   import java.util.List;
8   
9   /**
10   * ProjectScript DAO implementation.
11   *
12   * @author johnny
13   */
14  public class ProjectScriptDAOImpl extends BaseHibernateDAOImpl<ProjectScript>
15          implements ProjectScriptDAO {
16  
17      /**
18       *
19       */
20      public ProjectScriptDAOImpl() {
21      }
22  
23      public ProjectScript findByPrimaryKey(Integer scriptId) {
24          ProjectScript script;
25  
26          try {
27              script = (ProjectScript) getSession().get(ProjectScript.class, scriptId);
28          } catch (HibernateException ex) {
29              throw convertHibernateAccessException(ex);
30          }
31          return script;
32      }
33  
34      @SuppressWarnings("unchecked")
35      public List<ProjectScript> findAll() {
36          List<ProjectScript> scripts;
37  
38          try {
39              Query query = getSession().getNamedQuery("ProjectScriptsAllQuery");
40              scripts = query.list();
41          } catch (HibernateException ex) {
42              throw convertHibernateAccessException(ex);
43          }
44          return scripts;
45      }
46  
47      @SuppressWarnings("unchecked")
48      public List<ProjectScript> findByProject(Integer projectId) {
49          List<ProjectScript> scripts;
50  
51          try {
52              Query query = getSession().getNamedQuery(
53                      "ProjectScriptsByProjectQuery");
54              query.setInteger("projectId", projectId);
55              scripts = query.list();
56          } catch (HibernateException ex) {
57              throw convertHibernateAccessException(ex);
58          }
59          return scripts;
60      }
61  
62      @SuppressWarnings("unchecked")
63      public List<ProjectScript> findByProjectField(Integer projectId,
64                                                    Integer fieldId) {
65          List<ProjectScript> scripts;
66  
67          try {
68              Query query = getSession().getNamedQuery(
69                      "ProjectScriptsByProjectAndFieldQuery");
70              query.setInteger("projectId", projectId);
71              query.setInteger("fieldId", fieldId);
72              scripts = query.list();
73          } catch (HibernateException ex) {
74              throw convertHibernateAccessException(ex);
75          }
76          return scripts;
77      }
78  
79  }