View Javadoc

1   /***
2   Copyright (C) 2005 The Java Community
3   
4   This program is free software; you can redistribute it and/or modify  it under
5   the terms of the GNU General Public License as published by  the Free Software
6   Foundation; either version 2 of the License, or  (at your option) any later
7   version.
8   
9   This program is distributed in the hope that it will be useful,  but WITHOUT
10  ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License  along with
14  this program; if not, write to the Free Software  Foundation, Inc., 59 Temple
15  Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17  package org.bejug.javacareers.jobs.dao.hibernate;
18  
19  import org.bejug.javacareers.jobs.dao.CountryDao;
20  import org.bejug.javacareers.jobs.model.Country;
21  import org.bejug.javacareers.jobs.model.Region;
22  import org.springframework.dao.DataAccessException;
23  import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
24  
25  import java.util.Iterator;
26  import java.util.List;
27  
28  /***
29   * Country Hibernate DAO implementation.
30   *
31   * @author Sven Schauwvliege (Last modified by $Author: stephan_janssen $)
32   * @version $Revision: 1.3 $ - $Date: 2005/10/11 08:43:10 $
33   */
34  public class CountryDaoHibernateImpl extends HibernateDaoSupport
35                                       implements CountryDao {
36  
37      /*** 
38       * {@inheritDoc}
39       */
40      public void store(Country country) throws DataAccessException {
41          for (Iterator i = country.getRegion().iterator(); i.hasNext();) {
42              ((Region) i.next()).setModificationDate(
43                                              country.getModificationDate());
44          }
45          getHibernateTemplate().save(country);
46      }
47  
48      /*** 
49       * {@inheritDoc}
50       */
51      public List getCountries() throws DataAccessException {
52          return getHibernateTemplate().loadAll(Country.class);
53      }
54  
55      /*** 
56       * {@inheritDoc}
57       */
58      public void deleteCountry(Country country) throws DataAccessException {
59          getHibernateTemplate().delete( country); 
60  
61      }
62  
63      /*** 
64       * {@inheritDoc}
65       */
66      public void deleteCountry(Integer id) throws DataAccessException {
67          Country country = (Country)getHibernateTemplate().load(Country.class,
68                                                                 id);
69          getHibernateTemplate().delete(country);
70      }
71  
72      /*** 
73       * {@inheritDoc}
74       */
75      public Country getCountry(Integer id) throws DataAccessException {
76          return (Country) getHibernateTemplate().load(Country.class, id);
77      }
78  
79      /***
80       * {@inheritDoc}
81       */
82      public Country getCountryByName(String country) {
83          List countrys = getHibernateTemplate().findByNamedQueryAndNamedParam(
84                  "findCountryByName", "name", country);
85  
86          Country countr = null;
87          if (countrys.size() != 0) {
88              countr = (Country) countrys.get(0);
89          }
90          return countr;
91      }
92  }
93  /*** 
94   * $Log: CountryDaoHibernateImpl.java,v $
95   * Revision 1.3  2005/10/11 08:43:10  stephan_janssen
96   * Reformat code.
97   *
98   * Revision 1.2  2005/09/13 08:11:17  schauwvliege
99   * organize imports
100  *
101  * Revision 1.1  2005/08/26 07:58:30  ge0ffrey
102  * split up the sources in service, serviceimpl and webclient
103  *
104  * Revision 1.5  2005/08/10 09:04:48  bavo_jcs
105  * Optimized imports according to checkstyle
106  *
107  * Revision 1.4  2005/08/09 12:59:55  bavo_jcs
108  * Optimized imports
109  *
110  * Revision 1.3  2005/08/04 11:52:11  bme_jcs
111  * resolved checkstyle errors
112  *
113  * Revision 1.2  2005/08/03 13:14:09  bme_jcs
114  * getDao's removed and storeObject renamed to store
115  *
116  * Revision 1.1  2005/07/05 15:13:21  schauwvliege
117  * added person/contact and location to model
118  * 
119  **/