KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > dao > TopicDAO


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.dao;
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 import com.geinuke.middle.ICommentBL;
30 import com.geinuke.middle.MiddleFactory;
31 import com.geinuke.util.CountArrayList;
32 import com.geinuke.vo.NewsVO;
33 import com.geinuke.vo.TopicVO;
34
35
36 public class TopicDAO extends GeiDAO{
37     public TopicDAO() throws Exception JavaDoc {
38         super();
39         
40     }
41     
42     public void insertTopic(TopicVO t) throws Exception JavaDoc{
43         
44         try{
45             this.sqlMap().startTransaction();
46             this.sqlMap().insert("insTopic",t);
47             this.sqlMap().commitTransaction();
48         }finally{
49             this.sqlMap().endTransaction();
50         }
51         
52     }
53     
54     public void insertForumTopic(TopicVO t) throws Exception JavaDoc{
55         
56         try{
57             this.sqlMap().startTransaction();
58             this.sqlMap().insert("insForumTopic",t);
59             this.sqlMap().commitTransaction();
60         }finally{
61             this.sqlMap().endTransaction();
62         }
63         
64     }
65     
66     public void updateForumTopic(TopicVO t) throws Exception JavaDoc{
67         
68         try{
69             this.sqlMap().startTransaction();
70             this.sqlMap().update("updateForumTopic",t);
71             this.sqlMap().commitTransaction();
72         }finally{
73             this.sqlMap().endTransaction();
74         }
75         
76     }
77     
78     public void insertTopics_Forums(int tid,int fid) throws Exception JavaDoc{
79         
80         try{
81             HashMap JavaDoc map=new HashMap JavaDoc();
82             map.put("tid",new Integer JavaDoc(tid));
83             map.put("fid",new Integer JavaDoc(fid));
84             
85             this.sqlMap().startTransaction();
86             this.sqlMap().insert("insTopics_Forums",map);
87             this.sqlMap().commitTransaction();
88         }finally{
89             this.sqlMap().endTransaction();
90         }
91         
92     }
93     
94     public void delForumTopicByTId(int tid) throws Exception JavaDoc{
95         
96         try{
97             this.sqlMap().startTransaction();
98             this.sqlMap().delete("delForumTopicByTId",new Integer JavaDoc(tid));
99             this.sqlMap().commitTransaction();
100         }finally{
101             this.sqlMap().endTransaction();
102         }
103         
104     }
105     
106     public void delForumTopicsByFId(int fid) throws Exception JavaDoc{
107         
108         try{
109             this.sqlMap().startTransaction();
110             this.sqlMap().delete("delForumTopicsByFId",new Integer JavaDoc(fid));
111             this.sqlMap().commitTransaction();
112         }finally{
113             this.sqlMap().endTransaction();
114         }
115         
116     }
117     
118     
119     
120     
121     /**
122      *
123      * @return an ArrayList of TopicVO
124      * @throws SQLException
125      */

126     public ArrayList JavaDoc getAllTopics(String JavaDoc type)throws SQLException JavaDoc{
127         ArrayList JavaDoc list=null;
128         List JavaDoc llist=null;
129         try{
130             sqlMap().startTransaction();
131             llist=sqlMap().queryForList("getTopics",type);
132             this.sqlMap().commitTransaction();
133         }finally{
134             sqlMap().endTransaction();
135         }
136         list=new ArrayList JavaDoc(llist);
137         return list;
138     }
139     
140     public ArrayList JavaDoc getTopicsByNews(NewsVO n)throws SQLException JavaDoc{
141         ArrayList JavaDoc list=null;
142         List JavaDoc llist=null;
143         try{
144             sqlMap().startTransaction();
145             llist=sqlMap().queryForList("getTopicsByNews",n);
146             this.sqlMap().commitTransaction();
147         }finally{
148             sqlMap().endTransaction();
149         }
150         list=new ArrayList JavaDoc(llist);
151         return list;
152     }
153     
154     public CountArrayList getTopicsByFId(int fid)throws Exception JavaDoc{
155         CountArrayList list=null;
156         List JavaDoc llist=null;
157         try{
158             sqlMap().startTransaction();
159             llist=sqlMap().queryForList("getTopicsByFId",new Integer JavaDoc(fid));
160             this.sqlMap().commitTransaction();
161         }finally{
162             sqlMap().endTransaction();
163         }
164         list=new CountArrayList(llist);
165         TopicVO t=null;
166         ICommentBL cbl=(ICommentBL)MiddleFactory.getBL("ICommentBL");
167         for(int i=0;i<list.size();i++){
168             t=(TopicVO)list.get(i);
169             list.setCount(1+list.getCount()+cbl.getForumCommentsCountByXId(t.getTId()));
170         }
171         return list;
172     }
173     
174     public CountArrayList getForumTopicsByText(String JavaDoc text)throws Exception JavaDoc{
175         CountArrayList list=null;
176         text="%"+text+"%";
177         List JavaDoc llist=null;
178         try{
179             sqlMap().startTransaction();
180             llist=sqlMap().queryForList("getForumTopicsByText",text);
181             this.sqlMap().commitTransaction();
182         }finally{
183             sqlMap().endTransaction();
184         }
185         //System.out.println(" text "+text);
186
//System.out.println(" getForumTopicsByText "+llist.size());
187

188         list=new CountArrayList(llist);
189         TopicVO t=null;
190         ICommentBL cbl=(ICommentBL)MiddleFactory.getBL("ICommentBL");
191         for(int i=0;i<list.size();i++){
192             t=(TopicVO)list.get(i);
193             list.setCount(1+list.getCount()+cbl.getForumCommentsCountByXId(t.getTId()));
194         }
195         //System.out.println(" getForumTopicsByText "+list.size());
196
return list;
197     }
198     
199     public TopicVO getTopicById(int id)throws SQLException JavaDoc{
200         TopicVO res=null;
201         
202         try{
203             sqlMap().startTransaction();
204             res=(TopicVO)sqlMap().queryForObject("getTopicById",new Integer JavaDoc(id));
205             this.sqlMap().commitTransaction();
206         }finally{
207             sqlMap().endTransaction();
208         }
209         
210         return res;
211     }
212     
213     public TopicVO getLastTopicByFId(int id)throws SQLException JavaDoc{
214         TopicVO res=null;
215         
216         try{
217             sqlMap().startTransaction();
218             res=(TopicVO)sqlMap().queryForObject("getLastTopicByFId",new Integer JavaDoc(id));
219             this.sqlMap().commitTransaction();
220         }finally{
221             sqlMap().endTransaction();
222         }
223         
224         return res;
225     }
226     
227     public TopicVO getTopicByName(String JavaDoc name)throws SQLException JavaDoc{
228         TopicVO res=null;
229         
230         try{
231             sqlMap().startTransaction();
232             res=(TopicVO)sqlMap().queryForObject("getTopicByName",name);
233             this.sqlMap().commitTransaction();
234         }finally{
235             sqlMap().endTransaction();
236         }
237         
238         return res;
239     }
240     
241     public TopicVO getTopicByImage(String JavaDoc name)throws SQLException JavaDoc{
242         TopicVO res=null;
243         
244         try{
245             sqlMap().startTransaction();
246             res=(TopicVO)sqlMap().queryForObject("getTopicByImage",name);
247             this.sqlMap().commitTransaction();
248         }finally{
249             sqlMap().endTransaction();
250         }
251         
252         return res;
253     }
254     
255
256 }
257
Popular Tags