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 org.hibernate.HibernateException;
9   import org.hibernate.criterion.Restrictions;
10  import org.springframework.transaction.annotation.Transactional;
11  
12  import com.hack23.cia.model.sweden.impl.PoliticalParty;
13  
14  /***
15   * The Class PoliticalPartyDAOImpl.
16   */
17  public class PoliticalPartyDAOImpl extends
18          GenericHibernateDAO<PoliticalParty, Long> implements
19          PoliticalPartyDAO {
20  
21      /***
22       * Instantiates a new political party dao impl.
23       */
24      public PoliticalPartyDAOImpl() {
25          super(PoliticalParty.class);
26      }
27  
28      /*
29       * (non-Javadoc)
30       * 
31       * @see
32       * com.hack23.cia.service.dao.CommiteeReportDAO#findByName(java.lang.String)
33       */
34      @Override
35  	@Transactional(readOnly = true)
36      public final PoliticalParty findByName(final String name) {
37          try {
38              return (PoliticalParty) getSession()
39                      .createCriteria(PoliticalParty.class)
40                      .add(Restrictions.eq("name", name)).setCacheable(true).uniqueResult(); //$NON-NLS-1$
41          } catch (final HibernateException hibernateException) {
42              throw getHibernateTemplate().convertHibernateAccessException(
43                      hibernateException);
44          }
45      }
46  
47  	/* (non-Javadoc)
48  	 * @see com.hack23.cia.service.dao.PoliticalPartyDAO#findByShortCode(java.lang.String)
49  	 */
50  	@Override
51  	@Transactional(readOnly = true)
52  	public final PoliticalParty findByShortCode(final String shortCode) {
53          try {
54              return (PoliticalParty) getSession()
55                      .createCriteria(PoliticalParty.class)
56                      .add(Restrictions.eq("shortCode", shortCode)).setCacheable(true).uniqueResult(); //$NON-NLS-1$
57          } catch (final HibernateException hibernateException) {
58              throw getHibernateTemplate().convertHibernateAccessException(
59                      hibernateException);
60          }
61  	}
62  
63  }