View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
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      /* (non-Javadoc)
38       * @see org.directdemocracyportal.democracy.service.dao.DocumentDAO#getDecidedResolutionsInDateOrder()
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      /* (non-Javadoc)
54       * @see org.directdemocracyportal.democracy.service.dao.DocumentDAO#getVotesForPerson(org.directdemocracyportal.democracy.model.world.Person)
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  }