1
2
3
4
5 package org.directdemocracyportal.democracy.service.dao.hibernate;
6
7 import java.util.List;
8
9 import org.directdemocracyportal.democracy.model.world.Document;
10 import org.directdemocracyportal.democracy.model.world.Person;
11 import org.directdemocracyportal.democracy.model.world.Resolution;
12 import org.directdemocracyportal.democracy.model.world.Vote;
13 import org.directdemocracyportal.democracy.model.world.Resolution.ResolutionState;
14 import org.directdemocracyportal.democracy.service.dao.DocumentDAO;
15 import org.hibernate.criterion.DetachedCriteria;
16 import org.hibernate.criterion.Order;
17 import org.hibernate.criterion.Restrictions;
18 import org.springframework.dao.DataAccessException;
19 import org.springframework.transaction.annotation.Propagation;
20 import org.springframework.transaction.annotation.Transactional;
21
22 /***
23 * The Class HibernateDocumentDAO.
24 */
25 @Transactional(propagation = Propagation.MANDATORY)
26 public class HibernateDocumentDAO extends GenericHibernateDAO<Document, Long>
27 implements DocumentDAO
28 {
29
30 /***
31 * Instantiates a new hibernate document dao.
32 */
33 public HibernateDocumentDAO() {
34 super(Document.class);
35 }
36
37
38
39
40 public List<Resolution> getDecidedResolutionsInDateOrder() throws DataAccessException {
41 DetachedCriteria findDecided = DetachedCriteria
42 .forClass(Resolution.class);
43 findDecided.add(Restrictions.eq("resolutionState", ResolutionState.Decided));
44 findDecided.addOrder(Order.asc("decidedDate"));
45
46 @SuppressWarnings("unchecked")
47 List<Resolution> result = this.getHibernateTemplate().findByCriteria(
48 findDecided);
49
50 return result;
51 }
52
53
54
55
56 @Override
57 public List<Vote> getVotesForPerson(Person person) {
58 DetachedCriteria findVotes = DetachedCriteria
59 .forClass(Vote.class);
60 findVotes.add(Restrictions.eq("owner", person));
61 findVotes.addOrder(Order.asc("voteDate"));
62
63 @SuppressWarnings("unchecked")
64 List<Vote> result = this.getHibernateTemplate().findByCriteria(
65 findVotes);
66
67 return result;
68 }
69 }