KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > bizlogic > CommentBL


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.bizlogic;
24
25 import java.sql.SQLException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29
30 import com.geinuke.dao.CommentDAO;
31 import com.geinuke.middle.IBlogBL;
32 import com.geinuke.middle.ICommentBL;
33 import com.geinuke.middle.INewsBL;
34 import com.geinuke.middle.IUserBL;
35 import com.geinuke.middle.MiddleFactory;
36 import com.geinuke.util.collection.CachedBL;
37 import com.geinuke.util.collection.TreeArrayList;
38 import com.geinuke.util.collection.TreeFactory;
39 import com.geinuke.vo.CommentVO;
40 import com.geinuke.vo.UserVO;
41
42
43
44 public class CommentBL extends CachedBL implements ICommentBL {
45         
46     public CommentBL(){
47         super();
48     }
49     
50
51     public void insComment(CommentVO c)throws BLException{
52         if(c.getComType()==CommentVO.CAT_FORUMS)
53             fcommentCache.clear();
54         try{
55             CommentDAO dao=new CommentDAO();
56             dao.insertComment(c);
57             
58         }catch(SQLException JavaDoc sqle){
59             throw new DBException(sqle.getMessage());
60         }catch(Throwable JavaDoc t){
61             throw new BLException(t.getMessage());
62         }
63         
64     }
65     
66     
67     public void delTree(CommentDAO dao,TreeArrayList tree) throws Exception JavaDoc{
68         ArrayList JavaDoc list=tree.getChilds();
69         TreeArrayList aux=null;
70         for(int i=0;list!=null && i<list.size();i++){
71             aux=(TreeArrayList)list.get(i);
72             delTree(dao,aux);
73         }
74         dao.delCommentByCId( ((CommentVO)tree.getNode()).getCId() );
75     }
76     
77     
78     public void delCommentsTreeByCId(int cid)throws BLException{
79         
80         try{
81             CommentDAO dao=new CommentDAO();
82             INewsBL nbl=(INewsBL)MiddleFactory.getBL("INewsBL");
83             int nid=nbl.getNewsByCommentCId(cid).getNId();
84             TreeArrayList tree= TreeFactory.getCommentsTree( dao.getNewsCommentsByXId(nid),dao.getNewsCommentByCId(cid));
85             this.delTree(dao,tree);
86         }catch(SQLException JavaDoc sqle){
87             throw new DBException(sqle.getMessage());
88         }catch(Throwable JavaDoc t){
89             throw new BLException(t.getMessage());
90         }
91     
92     }
93     
94     public void delCommentsBlogTreeByCId(int cid)throws BLException{
95         
96         try{
97             CommentDAO dao=new CommentDAO();
98             IBlogBL bbl=(IBlogBL)MiddleFactory.getBL("IBlogBL");
99             int bid=bbl.getBlogPostByCommentCId(cid).getBid();
100             TreeArrayList tree= TreeFactory.getCommentsTree( dao.getBlogCommentsByXId(bid),
101                     dao.getBlogCommentByCId(cid));
102             this.delTree(dao,tree);
103         }catch(SQLException JavaDoc sqle){
104             throw new DBException(sqle.getMessage());
105         }catch(Throwable JavaDoc t){
106             throw new BLException(t.getMessage());
107         }
108     
109     }
110     
111     public void delCommentByCId(int cid)throws BLException{
112         fcommentCache.clear();
113         try{
114             CommentDAO dao=new CommentDAO();
115             dao.delCommentByCId(cid);
116         }catch(SQLException JavaDoc sqle){
117             throw new DBException(sqle.getMessage());
118         }catch(Throwable JavaDoc t){
119             throw new BLException(t.getMessage());
120         }
121     
122     }
123     
124     public void delForumCommentsByXId(int xid)throws BLException{
125         fcommentCache.clear();
126         try{
127             CommentDAO dao=new CommentDAO();
128             dao.delForumCommentsByXId(xid);
129         }catch(SQLException JavaDoc sqle){
130             throw new DBException(sqle.getMessage());
131         }catch(Throwable JavaDoc t){
132             throw new BLException(t.getMessage());
133         }
134     
135     }
136     
137     public void delForumCommentsByFId(int fid)throws BLException{
138         fcommentCache.clear();
139         try{
140             CommentDAO dao=new CommentDAO();
141             dao.delForumCommentsByFId(fid);
142         }catch(SQLException JavaDoc sqle){
143             throw new DBException(sqle.getMessage());
144         }catch(Throwable JavaDoc t){
145             throw new BLException(t.getMessage());
146         }
147     
148     }
149     
150     
151     
152     public void delBlogCommentsTreeByCId(int cid)throws BLException{
153     
154         try{
155             CommentDAO dao=new CommentDAO();
156             IBlogBL bbl=(IBlogBL)MiddleFactory.getBL("IBlogBL");
157             int bid=bbl.getBlogPostByCommentCId(cid).getBid();
158             TreeArrayList tree= TreeFactory.getCommentsTree( dao.getBlogCommentsByXId(bid),dao.getBlogCommentByCId(cid));
159             this.delTree(dao,tree);
160         }catch(SQLException JavaDoc sqle){
161             throw new DBException(sqle.getMessage());
162         }catch(Throwable JavaDoc t){
163             throw new BLException(t.getMessage());
164         }
165     
166     }
167     
168     
169     
170     
171     
172     public CommentVO getNewsCommentByCId(int cid)throws BLException{
173         
174         CommentVO c=null;
175     
176         try{
177             CommentDAO dao=new CommentDAO();
178             c=dao.getNewsCommentByCId(cid);
179         }catch(SQLException JavaDoc sqle){
180             throw new DBException(sqle.getMessage());
181         }catch(Throwable JavaDoc t){
182             throw new BLException(t.getMessage());
183         }
184     
185         return c;
186     }
187     
188     public CommentVO getForumCommentByCId(int cid)throws BLException{
189         
190         CommentVO c=null;
191     
192         try{
193             CommentDAO dao=new CommentDAO();
194             c=dao.getForumCommentByCId(cid);
195         }catch(SQLException JavaDoc sqle){
196             throw new DBException(sqle.getMessage());
197         }catch(Throwable JavaDoc t){
198             throw new BLException(t.getMessage());
199         }
200     
201         return c;
202     }
203     
204     public ArrayList JavaDoc getNewsCommentsByXId(int xid) throws BLException{
205         ArrayList JavaDoc list=null;
206     
207         try{
208             CommentDAO dao=new CommentDAO();
209             list=dao.getNewsCommentsByXId(xid);
210             
211         }catch(SQLException JavaDoc sqle){
212             throw new DBException(sqle.getMessage());
213         }catch(Throwable JavaDoc t){
214             throw new BLException(t.getMessage());
215         }
216         
217         return list;
218     }
219     
220     public int getBlogCommentsCountByXId(int xid) throws BLException{
221         int res=0;
222         try{
223             CommentDAO dao=new CommentDAO();
224             res=dao.getBlogCommentsCountByXId(xid);
225             
226         }catch(SQLException JavaDoc sqle){
227             throw new DBException(sqle.getMessage());
228         }catch(Throwable JavaDoc t){
229             throw new BLException(t.getMessage());
230         }
231         return res;
232     }
233     
234     public CommentVO getBlogCommentByCId(int cid)throws BLException{
235         CommentVO c=null;
236         
237         try{
238             CommentDAO dao=new CommentDAO();
239             c=dao.getBlogCommentByCId(cid);
240         }catch(SQLException JavaDoc sqle){
241             throw new DBException(sqle.getMessage());
242         }catch(Throwable JavaDoc t){
243             throw new BLException(t.getMessage());
244         }
245         return c;
246     }
247     
248     
249     public ArrayList JavaDoc getBlogCommentsByXId(int xid) throws BLException{
250         ArrayList JavaDoc res=null;
251         List JavaDoc list=null;
252         try{
253             CommentDAO dao=new CommentDAO();
254             list=dao.getBlogCommentsByXId(xid);
255             
256         }catch(SQLException JavaDoc sqle){
257             throw new DBException(sqle.getMessage());
258         }catch(Throwable JavaDoc t){
259             throw new BLException(t.getMessage());
260         }
261         res=new ArrayList JavaDoc(list);
262         return res;
263     }
264     
265     
266     public int getForumCommentsCountByXId(int xid) throws BLException{
267         int res=0;
268         if(fcommentCache.containsKey("CommentBL.getForumCommentsCountByXId-"+xid)){
269             res= ( (Integer JavaDoc)fcommentCache.get("CommentBL.getForumCommentsCountByXId-"+xid) ).intValue();
270             return res;
271         }
272         try{
273             CommentDAO dao=new CommentDAO();
274             res=dao.getForumCommentsCountByXId(xid);
275             
276         }catch(SQLException JavaDoc sqle){
277             throw new DBException(sqle.getMessage());
278         }catch(Throwable JavaDoc t){
279             throw new BLException(t.getMessage());
280         }
281         fcommentCache.put("CommentBL.getForumCommentsCountByXId-"+xid,new Integer JavaDoc(res),7200);
282         return res;
283     }
284     
285     public ArrayList JavaDoc getForumCommentsByXId(int xid) throws BLException{
286         ArrayList JavaDoc res=null;
287         if(fcommentCache.containsKey("CommentBL.getForumCommentsByXId-"+xid)){
288             res= (ArrayList JavaDoc)fcommentCache.get("CommentBL.getForumCommentsByXId-"+xid);
289             return res;
290         }
291         List JavaDoc list=null;
292         try{
293             CommentDAO dao=new CommentDAO();
294             list=dao.getForumCommentsByXId(xid);
295             
296         }catch(SQLException JavaDoc sqle){
297             throw new DBException(sqle.getMessage());
298         }catch(Throwable JavaDoc t){
299             throw new BLException(t.getMessage());
300         }
301         res=new ArrayList JavaDoc(list);
302         fcommentCache.put("CommentBL.getForumCommentsByXId-"+xid,res,7200);
303         return res;
304     }
305     
306     public CommentVO getLastForumCommentByFId(int fid) throws BLException{
307         CommentVO res=null;
308         if(fcommentCache.containsKey("CommentBL.getLastForumCommentByFId-"+fid)){
309             res= (CommentVO)fcommentCache.get("CommentBL.getLastForumCommentByFId-"+fid);
310             return res;
311         }
312         try{
313             CommentDAO dao=new CommentDAO();
314             res=dao.getLastForumCommentByFId(fid);
315             
316         }catch(SQLException JavaDoc sqle){
317             throw new DBException(sqle.getMessage());
318         }catch(Throwable JavaDoc t){
319             throw new BLException(t.getMessage());
320         }
321         if(res!=null)
322             fcommentCache.put("CommentBL.getLastForumCommentByFId-"+fid,res,7200);
323         return res;
324     }
325     
326     public CommentVO getLastForumCommentByTId(int tid) throws BLException{
327         CommentVO res=null;
328         if(fcommentCache.containsKey("CommentBL.getLastForumCommentByTId-"+tid)){
329             res= (CommentVO)fcommentCache.get("CommentBL.getLastForumCommentByTId-"+tid);
330             return res;
331         }
332         try{
333             CommentDAO dao=new CommentDAO();
334             res=dao.getLastForumCommentByTId(tid);
335             
336         }catch(SQLException JavaDoc sqle){
337             throw new DBException(sqle.getMessage());
338         }catch(Throwable JavaDoc t){
339             throw new BLException(t.getMessage());
340         }
341         if(res!=null)
342             fcommentCache.put("CommentBL.getLastForumCommentByTId-"+tid,res,7200);;
343         return res;
344     }
345     
346     public TreeArrayList getNewsCommentsTreeByXId(int xid) throws BLException{
347         TreeArrayList tree=null;
348         ArrayList JavaDoc list=null;
349         CommentVO c=new CommentVO();
350         c.setCId(0);
351         list=this.getNewsCommentsByXId(xid);
352         tree=TreeFactory.getCommentsTree(list,c);
353         return tree;
354     }
355     
356     public TreeArrayList getBlogCommentsTreeByXId(int xid) throws BLException{
357         TreeArrayList tree=null;
358         ArrayList JavaDoc list=null;
359         CommentVO c=new CommentVO();
360         c.setCId(0);
361         list=this.getBlogCommentsByXId(xid);
362         tree=TreeFactory.getCommentsTree(list,c);
363         return tree;
364     }
365     
366     public HashMap JavaDoc getUsersByCommentXId(int xid) throws BLException{
367         HashMap JavaDoc res=new HashMap JavaDoc();
368         ArrayList JavaDoc list=null;
369         list=this.getNewsCommentsByXId(xid);
370         CommentVO c=null;
371         UserVO u=null;
372         for(int i=0;i<list.size();i++){
373             c=(CommentVO)list.get(i);
374             IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL");
375             u=ubl.getUserByID(c.getUId());
376             res.put(u.getId()+"",u.getUName());
377         }
378         return res;
379     }
380     
381     public HashMap JavaDoc getUsersByBlogPostXId(int xid) throws BLException{
382         HashMap JavaDoc res=new HashMap JavaDoc();
383         ArrayList JavaDoc list=null;
384         list=this.getBlogCommentsByXId(xid);
385         CommentVO c=null;
386         UserVO u=null;
387         for(int i=0;i<list.size();i++){
388             c=(CommentVO)list.get(i);
389             IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL");
390             u=ubl.getUserByID(c.getUId());
391             res.put(u.getId()+"",u.getUName());
392         }
393         return res;
394     }
395     
396     public HashMap JavaDoc getUsersByForumCommentXId(int xid) throws BLException{
397         HashMap JavaDoc res=new HashMap JavaDoc();
398         ArrayList JavaDoc list=null;
399         list=this.getForumCommentsByXId(xid);
400         CommentVO c=null;
401         UserVO u=null;
402         for(int i=0;i<list.size();i++){
403             c=(CommentVO)list.get(i);
404             IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL");
405             u=ubl.getUserByID(c.getUId());
406             res.put(u.getId()+"",u);
407         }
408         return res;
409     }
410     
411     
412 }
413
Popular Tags