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   
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  import org.springframework.transaction.annotation.Transactional;
14  
15  import com.hack23.cia.model.sweden.impl.CommitteeReport;
16  import com.hack23.cia.model.sweden.impl.CommitteeReport.ImportStatus;
17  
18  /***
19   * The Class CommitteeReportDAOImpl.
20   */
21  public class CommitteeReportDAOImpl extends
22          GenericHibernateDAO<CommitteeReport, Long> implements
23          CommitteeReportDAO {
24  
25      /***
26       * Instantiates a new committee report dao impl.
27       */
28      public CommitteeReportDAOImpl() {
29          super(CommitteeReport.class);
30      }
31  
32      /*
33       * (non-Javadoc)
34       * 
35       * @see
36       * com.hack23.cia.service.dao.CommiteeReportDAO#findByName(java.lang.String)
37       */
38      @Override
39  	@Transactional(readOnly = true)
40      public final CommitteeReport findByName(final String name) {
41          try {
42              return (CommitteeReport) getSession()
43                      .createCriteria(CommitteeReport.class)
44                      .add(Restrictions.eq("name", name)).setCacheable(true).uniqueResult(); //$NON-NLS-1$
45          } catch (final HibernateException hibernateException) {
46              throw getHibernateTemplate().convertHibernateAccessException(
47                      hibernateException);
48          }
49      }
50  
51      /*
52       * (non-Javadoc)
53       * 
54       * @see com.hack23.cia.service.dao.CommiteeReportDAO#getAllCreated()
55       */
56      @Override
57  	@SuppressWarnings("unchecked")
58      public final List<CommitteeReport> getAllCreated() {
59          try {
60              return getSession().createCriteria(CommitteeReport.class).add(
61                      Restrictions.eq("importStatus", ImportStatus.Created)) //$NON-NLS-1$
62                      .addOrder(Order.asc("name")).setCacheable(true).list(); //$NON-NLS-1$
63          } catch (final HibernateException hibernateException) {
64              throw getHibernateTemplate().convertHibernateAccessException(
65                      hibernateException);
66          }
67      }
68  
69      /*
70       * (non-Javadoc)
71       * 
72       * @see com.hack23.cia.service.dao.CommiteeReportDAO#getAllLastDecided()
73       */
74      @SuppressWarnings("unchecked")
75      @Override
76      public final List<CommitteeReport> getAllLastDecided() {
77          try {
78              return getSession().createCriteria(CommitteeReport.class).addOrder(
79                      Order.desc("decisionDate")).setCacheable(true).list(); //$NON-NLS-1$
80          } catch (final HibernateException hibernateException) {
81              throw getHibernateTemplate().convertHibernateAccessException(
82                      hibernateException);
83          }
84      }
85  
86      /*
87       * (non-Javadoc)
88       * 
89       * @see com.hack23.cia.service.dao.CommiteeReportDAO#getLastDecided()
90       */
91      @SuppressWarnings("unchecked")
92      @Override
93      public final List<CommitteeReport> getLastDecided() {
94          try {
95              return getSession()
96                      .createCriteria(CommitteeReport.class)
97                      .add(
98                              Restrictions.eq(
99                                      "importStatus", ImportStatus.Completed)) //$NON-NLS-1$
100                     .addOrder(Order.desc("decisionDate")).setCacheable(true).setMaxResults(10).list(); //$NON-NLS-1$
101         } catch (final HibernateException hibernateException) {
102             throw getHibernateTemplate().convertHibernateAccessException(
103                     hibernateException);
104         }
105     }
106 
107 }