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   */
18  package org.bejug.javacareers.jobs.dao.hibernate;
19  
20  import org.bejug.javacareers.jobs.dao.CommentDao;
21  import org.bejug.javacareers.jobs.model.Comment;
22  import org.bejug.javacareers.jobs.model.Item;
23  import org.bejug.javacareers.jobs.model.User;
24  import org.springframework.dao.DataAccessException;
25  import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
26  
27  import java.util.List;
28  
29  /***
30   * Comment Hibernate DAO implementation.
31   * 
32   * @author Stephan Janssen (Last modified by $Author: shally $)
33   * @version $Revision: 1.5 $ - $Date: 2005/12/09 10:46:55 $
34   */
35  public class CommentDaoHibernateImpl extends HibernateDaoSupport
36                                       implements CommentDao {
37  
38      /***
39       * {@inheritDoc}
40       */
41      public Comment getCommentBySubject(Integer offerId, String subject) {
42           String parameterNames[] = {"offerId", "subject"};
43           Object parameterValues[] ={offerId, subject};
44  
45          List result = getHibernateTemplate().
46              findByNamedQueryAndNamedParam("getCommentBySubject",
47                      parameterNames,parameterValues);
48  
49         if(result.size() != 0){
50             return (Comment)result.get(0);
51         }
52         return null;
53      }
54  
55     /***
56      * {@inheritDoc}
57      */
58      public List getUserComments(User user) {
59          return getHibernateTemplate().findByNamedQueryAndNamedParam(
60                      "getUserComments","userId", user.getId());
61      }
62  
63      /***
64       * {@inheritDoc}
65       */
66      public int getChildCommentCount(Comment comment) {
67  
68         return ((Integer) getHibernateTemplate().
69                 findByNamedQueryAndNamedParam("getChildCommentCount",
70                               "parentId", comment.getId()).get(0)).intValue();
71      }
72  
73      /***
74       * {@inheritDoc}
75       */
76      public int getCommentCount(Item offer) {
77          return ((Integer) getHibernateTemplate().
78                 findByNamedQueryAndNamedParam("getCommentCount",
79                               "offerId", offer.getId()).get(0)).intValue();
80      }
81  
82      /***
83       * {@inheritDoc}
84       */
85      public void store(Comment comment) throws DataAccessException {
86          getHibernateTemplate().saveOrUpdate(comment);
87      }
88  
89      /***
90       * {@inheritDoc}
91       */
92      public List getComments(Integer offerId, boolean rootOnly)
93              throws DataAccessException {
94          List comments = null;
95  
96         if (rootOnly) {
97              comments = getHibernateTemplate().
98              findByNamedQueryAndNamedParam("findRootCommentByOfferId",
99                      "offerid", offerId);
100         } else {
101 
102             comments = getHibernateTemplate().
103             findByNamedQueryAndNamedParam("findCommentByOfferId",
104                     "offerid", offerId);
105         }
106 
107         return comments;
108     }
109 
110 
111     /***
112      * {@inheritDoc}
113      */
114     public List getChildComments(Integer commentId) throws DataAccessException {
115         return getHibernateTemplate().findByNamedQueryAndNamedParam(
116                 "findCommentByParentId", "parentid", commentId);
117     }
118 
119 
120     /***
121      * {@inheritDoc}
122      */
123     public void deleteComment(Comment comment) throws DataAccessException {
124         getHibernateTemplate().delete(comment);
125     }
126 
127     /***
128      * {@inheritDoc}
129      */
130     public void deleteComment(Integer id) throws DataAccessException {
131         Comment comment = (Comment)getHibernateTemplate().load(Comment.class,
132                                                                id);
133         getHibernateTemplate().delete(comment);
134     }
135 
136     /***
137      * {@inheritDoc}
138      */
139     public Comment getComment(Integer id) throws DataAccessException {
140         Comment comment = (Comment)getHibernateTemplate().load(Comment.class,
141                                                                id);
142         return comment;
143     }
144 }
145 /***
146  * $Log: CommentDaoHibernateImpl.java,v $
147  * Revision 1.5  2005/12/09 10:46:55  shally
148  * Opkuis voor checkstyle en PMD
149  *
150  * Revision 1.4  2005/10/11 08:40:36  stephan_janssen
151  * Code reformat + javadoc.
152  *
153  * Revision 1.3  2005/09/19 14:16:51  bavo_jcs
154  * Refactored comments to use Items
155  *
156  * Revision 1.2  2005/09/13 08:11:17  schauwvliege
157  * organize imports
158  *
159  * Revision 1.1  2005/08/26 07:58:30  ge0ffrey
160  * split up the sources in service, serviceimpl and webclient
161  *
162  * Revision 1.14  2005/08/10 09:04:48  bavo_jcs
163  * Optimized imports according to checkstyle
164  *
165  * Revision 1.13  2005/08/09 12:59:55  bavo_jcs
166  * Optimized imports
167  *
168  * Revision 1.12  2005/08/03 13:14:09  bme_jcs
169  * getDao's removed and storeObject renamed to store
170  *
171  * Revision 1.11  2005/07/08 15:47:26  psong09
172  * modified comment component, removed subject field
173  *
174  * Revision 1.10  2005/07/07 13:12:08  psong09
175  * modified getUserComments
176  *
177  * Revision 1.9  2005/07/04 07:54:00  psong09
178  * update comment component: added count(*) query, user login check, javascript
179  *
180  * Revision 1.8  2005/06/30 13:21:36  bme_jcs
181  * bug concerning childcomments fixed
182  *
183  * Revision 1.7  2005/06/30 12:21:04  psong09
184  * update comment component
185  *
186  * Revision 1.6  2005/06/28 07:38:29  psong09
187  * comment component updated
188  *
189  * Revision 1.5  2005/06/17 11:42:46  schauwvliege
190  * CheckStyle/ PMD
191  *
192  * Revision 1.4  2005/06/16 14:44:33  psong09
193  * added subject to comments
194  *
195  * Revision 1.3  2005/06/14 13:40:04  schauwvliege
196  * Renamed add to store
197  *
198  * Revision 1.2  2005/06/09 08:18:44  bejug_cc
199  * Fix initial import
200  *
201  * Revision 1.14  2005/05/30 09:31:47  bme
202  * updated for the introduction of HQL in the hbm-files
203  *
204  * Revision 1.13  2005/05/25 13:07:05  sja
205  * Added DataAccessException.
206  *
207  * Revision 1.12  2005/05/25 13:03:55  sja
208  * 80 chars per line update.
209  *
210  * Revision 1.11  2005/05/25 11:06:53  ssc
211  * added DBUnit tests and fixed some errors
212  *
213  * Revision 1.10  2005/05/12 08:23:55  ssc
214  * Checkstyle errors
215  *
216  * Revision 1.9  2005/05/11 17:44:15  sja
217  * Moved all dao Hibernate queries variables to HQLConstants.
218  *
219  * Revision 1.8  2005/05/11 12:49:30  ssc
220  * Checstyle errors
221  *
222  * Revision 1.7  2005/05/11 11:29:32  ssc
223  * Checstyle errors
224  *
225  * Revision 1.6  2005/05/11 10:14:52  ssc
226  * Checstyle errors
227  *
228  * Revision 1.5  2005/05/10 09:54:02  ssc
229  * Removed AbstractPersistableObject
230  *
231  * Revision 1.4  2005/05/07 15:44:39  ssc
232  * added child commend and tests
233  *
234  * Revision 1.3  2005/05/04 09:47:56  bme
235  * modified for introduction AOP
236  *
237  * Revision 1.2  2005/05/02 13:26:12  ssc
238  * Organize imports
239  *
240  * Revision 1.1  2005/05/01 21:32:13  sja
241  * First import.
242  *
243  *
244  */