Coverage Report - org.directdemocracyportal.democracy.service.dao.hibernate.HibernatePoliticalPartyDAO
 
Classes in this File Line Coverage Branch Coverage Complexity
HibernatePoliticalPartyDAO
54%
6/11
25%
1/4
1.5
 
 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.application.OnlinePoliticalParty;
 10  
 import org.directdemocracyportal.democracy.model.world.PoliticalParty;
 11  
 import org.directdemocracyportal.democracy.service.dao.PoliticalPartyDAO;
 12  
 import org.hibernate.criterion.DetachedCriteria;
 13  
 import org.hibernate.criterion.Restrictions;
 14  
 import org.springframework.dao.DataAccessException;
 15  
 import org.springframework.transaction.annotation.Propagation;
 16  
 import org.springframework.transaction.annotation.Transactional;
 17  
 
 18  
 /**
 19  
  * The Class HibernatePoliticalPartyDAO.
 20  
  */
 21  
 @Transactional(propagation = Propagation.MANDATORY)
 22  
 public class HibernatePoliticalPartyDAO extends
 23  
         GenericHibernateDAO<PoliticalParty, Long> implements PoliticalPartyDAO
 24  
 {
 25  
 
 26  
     /**
 27  
      * Instantiates a new hibernate political party dao.
 28  
      */
 29  
     public HibernatePoliticalPartyDAO() {
 30  1
         super(PoliticalParty.class);
 31  1
     }
 32  
 
 33  
     /*
 34  
      * (non-Javadoc)
 35  
      *
 36  
      * @see org.directdemocracyportal.democracy.service.dao.PoliticalPartyDAO#findByName(java.lang.String)
 37  
      */
 38  
     @Transactional(readOnly = true)
 39  
     public PoliticalParty findByName(String name) throws DataAccessException {
 40  1
         DetachedCriteria findPartyByName = DetachedCriteria
 41  
                 .forClass(PoliticalParty.class);
 42  1
         findPartyByName.add(Restrictions.eq("name", name));
 43  
 
 44  
         @SuppressWarnings("unchecked")
 45  1
         List<PoliticalParty> result = this.getHibernateTemplate()
 46  
                 .findByCriteria(findPartyByName);
 47  
 
 48  1
         return result.isEmpty() ? null : result.get(0);
 49  
     }
 50  
 
 51  
     /*
 52  
      * (non-Javadoc)
 53  
      *
 54  
      * @see org.directdemocracyportal.democracy.service.dao.PoliticalPartyDAO#findByShortCode(java.lang.String)
 55  
      */
 56  
     @Override
 57  
     public PoliticalParty findByShortCode(String shortCode) {
 58  0
         DetachedCriteria findPartyByShortCode = DetachedCriteria
 59  
                 .forClass(PoliticalParty.class);
 60  0
         findPartyByShortCode.add(Restrictions.eq("shortCode", shortCode));
 61  
 
 62  
         @SuppressWarnings("unchecked")
 63  0
         List<PoliticalParty> result = this.getHibernateTemplate()
 64  
                 .findByCriteria(findPartyByShortCode);
 65  
 
 66  0
         return result.isEmpty() ? null : result.get(0);
 67  
     }
 68  
 
 69  
     /*
 70  
      * (non-Javadoc)
 71  
      *
 72  
      * @see org.directdemocracyportal.democracy.service.dao.PoliticalPartyDAO#getAllOnline()
 73  
      */
 74  
     @SuppressWarnings("unchecked")
 75  
     public List<OnlinePoliticalParty> getAllOnline() throws DataAccessException {
 76  0
         return getHibernateTemplate().find(
 77  
                 "from " + OnlinePoliticalParty.class.getSimpleName());
 78  
     }
 79  
 }