1
2
3
4
5
6 package com.hack23.cia.service.dao;
7
8 import java.util.List;
9
10 import org.hibernate.HibernateException;
11 import org.hibernate.criterion.Order;
12 import org.hibernate.criterion.Restrictions;
13
14 import com.hack23.cia.model.sweden.impl.Ballot;
15 import com.hack23.cia.model.sweden.impl.Vote;
16 import com.hack23.cia.model.sweden.impl.Ballot.ImportStatus;
17
18 /***
19 * The Class BallotDAOImpl.
20 */
21 public class BallotDAOImpl extends GenericHibernateDAO<Ballot, Long> implements
22 BallotDAO {
23
24 /***
25 * Instantiates a new ballot dao impl.
26 */
27 public BallotDAOImpl() {
28 super(Ballot.class);
29 }
30
31
32
33
34
35
36 @SuppressWarnings("unchecked")
37 @Override
38 public final List<Ballot> getAllCompleted() {
39 try {
40 return getSession().createCriteria(Ballot.class).add(
41 Restrictions.eq("importStatus", ImportStatus.Completed))
42 .setCacheable(true).list();
43 } catch (final HibernateException hibernateException) {
44 throw getHibernateTemplate().convertHibernateAccessException(
45 hibernateException);
46 }
47 }
48
49
50
51
52
53
54 @Override
55 @SuppressWarnings("unchecked")
56 public final List<Ballot> getAllCreated() {
57 try {
58 return getSession().createCriteria(Ballot.class).add(
59 Restrictions.eq("importStatus", ImportStatus.Created))
60 .setCacheable(true).list();
61 } catch (final HibernateException hibernateException) {
62 throw getHibernateTemplate().convertHibernateAccessException(
63 hibernateException);
64 }
65 }
66
67
68
69
70
71
72 @Override
73 @SuppressWarnings("unchecked")
74 public final List<Ballot> getAllOrderedByWeek() {
75 return this
76 .getHibernateTemplate()
77 .find(
78 "select week(ballot.datum),ballot from Ballot ballot order by week(ballot.datum)");
79 }
80
81
82
83
84
85
86 @Override
87 public final Ballot getLast() {
88 try {
89 return ((Vote) getSession().createCriteria(Vote.class)
90 .setMaxResults(1).addOrder((Order.desc("datum")))
91 .setCacheable(true).setMaxResults(1).uniqueResult())
92 .getBallot();
93 } catch (final HibernateException hibernateException) {
94 throw getHibernateTemplate().convertHibernateAccessException(
95 hibernateException);
96 }
97 }
98
99 }