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 */
18 package org.bejug.javacareers.jobs.dao.hibernate;
19
20 import java.util.List;
21
22 import org.bejug.javacareers.jobs.dao.OfferDao;
23 import org.bejug.javacareers.jobs.model.Offer;
24 import org.springframework.dao.DataAccessException;
25 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
26
27 /***
28 * This class contains the common methods for all the Offer-classes.
29 *
30 * @author Bart Meyers (last modified by $Author: shally $)
31 * @version $Revision: 1.3 $ - $Date: 2005/12/20 15:36:46 $
32 */
33 public abstract class OfferDaoHibernateImpl
34 extends HibernateDaoSupport
35 implements OfferDao {
36
37 /***
38 * Todo: look for a way to implement this method???
39 * {@inheritDoc}
40 */
41 public List getOffers() throws DataAccessException {
42
43 return null;
44 }
45
46 /***
47 * {@inheritDoc}
48 */
49 public void store(Offer offer) throws DataAccessException {
50 getHibernateTemplate().saveOrUpdate(offer);
51 }
52
53 /***
54 * {@inheritDoc}
55 */
56 public Offer getOffer(Integer id) throws DataAccessException {
57 return (Offer) getHibernateTemplate().load(Offer.class, id);
58 }
59
60 /***
61 * {@inheritDoc}
62 */
63 public void deleteOffer(Offer offer) throws DataAccessException {
64 getHibernateTemplate().delete(offer);
65 }
66
67 /***
68 * {@inheritDoc}
69 */
70 public void deleteOffer(Integer id) throws DataAccessException {
71 Offer offer = (Offer) getHibernateTemplate().load(Offer.class, id);
72 getHibernateTemplate().delete(offer);
73 }
74
75 /***
76 * {@inheritDoc}
77 */
78 public int deleteOffersByUrl(final String url) throws DataAccessException {
79 List items = getHibernateTemplate().
80 findByNamedQueryAndNamedParam("findOfferByUrl","feed_url", url);
81 int size = items.size();
82 getHibernateTemplate().deleteAll(items);
83 return size;
84 }
85
86 /***
87 * conveniant method for retrieving the count of offers.
88 *
89 * @param namedQuery the namedQuery to execute.
90 * @return an int indicating the number of offers in the database.
91 * @throws DataAccessException when something goes wrong.
92 */
93 protected int getOfferCount(String namedQuery) throws DataAccessException {
94 int count = ((Integer) getHibernateTemplate().
95 findByNamedQuery(namedQuery).get(0)).intValue();
96
97 return count;
98 }
99
100 }
101
102 /***
103 * $Log: OfferDaoHibernateImpl.java,v $
104 * Revision 1.3 2005/12/20 15:36:46 shally
105 * CheckStyle and PMD changes.
106 *
107 * Revision 1.2 2005/09/30 14:38:08 bavo_jcs
108 * Fixed URL
109 *
110 * Revision 1.1 2005/08/26 07:58:30 ge0ffrey
111 * split up the sources in service, serviceimpl and webclient
112 *
113 * Revision 1.12 2005/08/19 14:15:56 bme_jcs
114 * checkstyle errors resolved
115 *
116 * Revision 1.11 2005/08/19 14:13:05 bme_jcs
117 * checkstyle errors resolved
118 *
119 * Revision 1.10 2005/08/19 08:42:14 psong09
120 * outcommented debug statement
121 *
122 * Revision 1.9 2005/08/10 09:04:48 bavo_jcs
123 * Optimized imports according to checkstyle
124 *
125 * Revision 1.8 2005/08/09 12:59:55 bavo_jcs
126 * Optimized imports
127 *
128 * Revision 1.7 2005/08/03 13:14:09 bme_jcs
129 * getDao's removed and storeObject renamed to store
130 *
131 * Revision 1.6 2005/07/29 15:43:38 bavo_jcs
132 * Fix comments who werent deleted
133 *
134 * Revision 1.5 2005/06/14 13:40:04 schauwvliege
135 * Renamed add to store
136 *
137 * Revision 1.4 2005/06/13 13:05:09 bavo_jcs
138 * delete by URL fix
139 *
140 * Revision 1.3 2005/06/10 15:37:34 bavo_jcs
141 * int returned on delete
142 *
143 * Revision 1.2 2005/06/09 08:18:44 bejug_cc
144 * Fix initial import
145 *
146 * Revision 1.13 2005/05/30 14:56:58 bme
147 * added count-methods
148 *
149 * Revision 1.12 2005/05/30 09:31:47 bme
150 * updated for the introduction of HQL in the hbm-files
151 *
152 * Revision 1.11 2005/05/25 11:06:53 ssc
153 * added DBUnit tests and fixed some errors
154 *
155 * Revision 1.10 2005/05/13 07:45:32 ssc
156 * delete by url fixed
157 *
158 * Revision 1.9 2005/05/12 08:23:55 ssc
159 * Checkstyle errors
160 *
161 * Revision 1.8 2005/05/11 11:29:32 ssc
162 * Checstyle errors
163 *
164 * Revision 1.7 2005/05/11 10:14:52 ssc
165 * Checstyle errors
166 *
167 * Revision 1.6 2005/05/10 13:31:52 bbr
168 * Added deleteOffersByUrl()
169 *
170 * Revision 1.5 2005/05/10 09:54:02 ssc
171 * Removed AbstractPersistableObject
172 *
173 * Revision 1.4 2005/05/04 09:47:56 bme
174 * modified for introduction AOP
175 *
176 * Revision 1.3 2005/04/29 22:15:50 ssc
177 * added abstract Dao class
178 *
179 * Revision 1.2 2005/04/29 18:17:34 sja
180 * General cleanup (naming conv., javadoc and CVS tags)
181 *
182 * Revision 1.1 2005/04/29 12:18:21 bme
183 * first release
184 *
185 * Revision 1.1 2005/04/29 05:49:52 bme
186 * first release
187 *
188 */