View Javadoc
1   package org.itracker.persistence.dao;
2   
3   import org.hibernate.HibernateException;
4   import org.hibernate.criterion.Expression;
5   import org.itracker.model.Project;
6   import org.itracker.model.Version;
7   
8   import java.util.List;
9   
10  /**
11   * Hibernate implementation of <code>VersionDAO</code> interface
12   */
13  public class VersionDAOImpl extends BaseHibernateDAOImpl<Version>
14          implements VersionDAO {
15  
16      /**
17       * find <code>Version</code> by id
18       *
19       * @param versionId id of the <code>Version</code> to find
20       * @return <code>Version</code> found
21       */
22      public Version findByPrimaryKey(Integer versionId) {
23          try {
24              return (Version) getSession().get(Version.class, versionId);
25          } catch (HibernateException e) {
26              throw convertHibernateAccessException(e);
27          }
28      }
29  
30      /**
31       * Finds <code>Version</code>s by a project id and returns them as
32       * a <code>Collection</code>.
33       *
34       * @param projectId id of the parent <code>Project</code>
35       * @return a <code>Collection</code> containing the <code>Version</code>s found
36       */
37      @SuppressWarnings("unchecked")
38      public List<Version> findByProjectId(Integer projectId) {
39          try {
40              Project/../../../org/itracker/model/Project.html#Project">Project project = (Project) getSession().load(Project.class, projectId);
41              return getSession().createCriteria(Version.class)
42                      .add(Expression.eq("project", project))
43                      .list();
44          } catch (HibernateException e) {
45              throw convertHibernateAccessException(e);
46          }
47      }
48  }