IssueAttachmentDAOImpl.java

  1. package org.itracker.persistence.dao;

  2. import org.hibernate.HibernateException;
  3. import org.hibernate.Query;
  4. import org.itracker.model.IssueAttachment;

  5. import java.util.List;

  6. /**
  7.  * Persistence Hibernate POJO
  8.  *
  9.  * @author mbae, ready
  10.  */
  11. public class IssueAttachmentDAOImpl extends BaseHibernateDAOImpl<IssueAttachment>
  12.         implements IssueAttachmentDAO {

  13.     public IssueAttachment findByPrimaryKey(Integer attachmentId) {
  14.         try {
  15.             return (IssueAttachment) getSession().get(IssueAttachment.class,
  16.                     attachmentId);
  17.         } catch (HibernateException ex) {
  18.             throw convertHibernateAccessException(ex);
  19.         }
  20.     }

  21.     public IssueAttachment findByFileName(String fileName) {
  22.         IssueAttachment attachment;

  23.         try {
  24.             Query query = getSession().getNamedQuery(
  25.                     "AttachmentByFileNameQuery");
  26.             query.setString("fileName", fileName);
  27.             attachment = (IssueAttachment) query.uniqueResult();
  28.         } catch (HibernateException ex) {
  29.             throw convertHibernateAccessException(ex);
  30.         }
  31.         return attachment;
  32.     }

  33.     @SuppressWarnings("unchecked")
  34.     public List<IssueAttachment> findAll() {
  35.         List<IssueAttachment> attachments;

  36.         try {
  37.             Query query = getSession().getNamedQuery(
  38.                     "AttachmentsAllQuery");
  39.             attachments = query.list();
  40.         } catch (HibernateException ex) {
  41.             throw convertHibernateAccessException(ex);
  42.         }
  43.         return attachments;
  44.     }

  45.     @SuppressWarnings("unchecked")
  46.     public List<IssueAttachment> findByIssue(Integer issueId) {
  47.         List<IssueAttachment> attachments;

  48.         try {
  49.             Query query = getSession().getNamedQuery(
  50.                     "AttachmentsByIssueQuery");
  51.             query.setInteger("issueId", issueId);
  52.             attachments = query.list();
  53.         } catch (HibernateException ex) {
  54.             throw convertHibernateAccessException(ex);
  55.         }
  56.         return attachments;
  57.     }

  58.     public Long countAll() {
  59.         Long count;
  60.         try {
  61.             Query query = getSession().getNamedQuery(
  62.                     "AttachmentsCountAllQuery");
  63.             count = (Long) query.uniqueResult();
  64.         } catch (HibernateException ex) {
  65.             throw convertHibernateAccessException(ex);
  66.         }
  67.         return count;
  68.     }

  69.     public Long totalAttachmentsSize() {
  70.         Long count;
  71.         try {
  72.             Query query = getSession().getNamedQuery(
  73.                     "TotalAttachmentsSizeQuery");
  74.             count = (Long) query.uniqueResult();
  75.         } catch (HibernateException ex) {
  76.             throw convertHibernateAccessException(ex);
  77.         }

  78.         if (count == null) {
  79.             count = 0L;
  80.         }

  81.         return count;
  82.     }
  83. }