1 package org.itracker.persistence.dao;
2
3 import org.hibernate.HibernateException;
4 import org.hibernate.Query;
5 import org.itracker.model.IssueAttachment;
6
7 import java.util.List;
8
9
10
11
12
13
14 public class IssueAttachmentDAOImpl extends BaseHibernateDAOImpl<IssueAttachment>
15 implements IssueAttachmentDAO {
16
17 public IssueAttachment findByPrimaryKey(Integer attachmentId) {
18 try {
19 return (IssueAttachment) getSession().get(IssueAttachment.class,
20 attachmentId);
21 } catch (HibernateException ex) {
22 throw convertHibernateAccessException(ex);
23 }
24 }
25
26 public IssueAttachment findByFileName(String fileName) {
27 IssueAttachment attachment;
28
29 try {
30 Query query = getSession().getNamedQuery(
31 "AttachmentByFileNameQuery");
32 query.setString("fileName", fileName);
33 attachment = (IssueAttachment) query.uniqueResult();
34 } catch (HibernateException ex) {
35 throw convertHibernateAccessException(ex);
36 }
37 return attachment;
38 }
39
40 @SuppressWarnings("unchecked")
41 public List<IssueAttachment> findAll() {
42 List<IssueAttachment> attachments;
43
44 try {
45 Query query = getSession().getNamedQuery(
46 "AttachmentsAllQuery");
47 attachments = query.list();
48 } catch (HibernateException ex) {
49 throw convertHibernateAccessException(ex);
50 }
51 return attachments;
52 }
53
54 @SuppressWarnings("unchecked")
55 public List<IssueAttachment> findByIssue(Integer issueId) {
56 List<IssueAttachment> attachments;
57
58 try {
59 Query query = getSession().getNamedQuery(
60 "AttachmentsByIssueQuery");
61 query.setInteger("issueId", issueId);
62 attachments = query.list();
63 } catch (HibernateException ex) {
64 throw convertHibernateAccessException(ex);
65 }
66 return attachments;
67 }
68
69 public Long countAll() {
70 Long count;
71 try {
72 Query query = getSession().getNamedQuery(
73 "AttachmentsCountAllQuery");
74 count = (Long) query.uniqueResult();
75 } catch (HibernateException ex) {
76 throw convertHibernateAccessException(ex);
77 }
78 return count;
79 }
80
81 public Long totalAttachmentsSize() {
82 Long count;
83 try {
84 Query query = getSession().getNamedQuery(
85 "TotalAttachmentsSizeQuery");
86 count = (Long) query.uniqueResult();
87 } catch (HibernateException ex) {
88 throw convertHibernateAccessException(ex);
89 }
90
91 if (count == null) {
92 count = 0L;
93 }
94
95 return count;
96 }
97 }