| 1 2 23 package com.geinuke.bizlogic; 24 25 import java.sql.SQLException ; 26 import java.util.ArrayList ; 27 import com.geinuke.dao.TopicDAO; 28 import com.geinuke.middle.ICommentBL; 29 import com.geinuke.middle.ITopicBL; 30 import com.geinuke.middle.IUserBL; 31 import com.geinuke.middle.MiddleFactory; 32 import com.geinuke.util.CountArrayList; 33 import com.geinuke.util.TextUtil; 34 import com.geinuke.util.collection.CachedBL; 35 import com.geinuke.util.collection.ForumTopicComparator; 36 import com.geinuke.util.collection.MagicCollections; 37 import com.geinuke.vo.CommentVO; 38 import com.geinuke.vo.NewsVO; 39 import com.geinuke.vo.TopicVO; 40 41 42 public class TopicBL extends CachedBL implements ITopicBL { 43 44 protected static ITopicBL instance=null; 45 46 public TopicBL(){ 47 super(); 48 } 49 50 public void delForumTopicByTId(int tid)throws BLException{ 51 ftopicCache.clear(); 52 try{ 53 54 ICommentBL cbl=(ICommentBL)MiddleFactory.getBL("ICommentBL"); 55 56 cbl.delForumCommentsByXId(tid); 57 TopicDAO dao=new TopicDAO(); 58 dao.delForumTopicByTId(tid); 59 }catch(SQLException sqle){ 60 throw new DBException(sqle.getMessage()); 61 }catch(Throwable t){ 62 throw new BLException(t.getMessage()); 63 } 64 65 } 66 67 public void delForumTopicsByFid(int fid)throws BLException{ 68 ftopicCache.clear(); 69 try{ 70 ICommentBL cbl=(ICommentBL)MiddleFactory.getBL("ICommentBL"); 71 72 cbl.delForumCommentsByFId(fid); 73 74 TopicDAO dao=new TopicDAO(); 75 dao.delForumTopicsByFId(fid); 76 }catch(SQLException sqle){ 77 throw new DBException(sqle.getMessage()); 78 }catch(Throwable t){ 79 throw new BLException(t.getMessage()); 80 } 81 82 } 83 84 85 public void insTopic(TopicVO to)throws BLException{ 86 87 try{ 88 TopicDAO dao=new TopicDAO(); 89 dao.insertTopic(to); 90 91 }catch(SQLException sqle){ 92 throw new DBException(sqle.getMessage()); 93 }catch(Throwable t){ 94 throw new BLException(t.getMessage()); 95 } 96 97 } 98 99 public void insForumTopic(TopicVO to,int fid)throws BLException{ 100 ftopicCache.clear(); 101 try{ 102 TopicDAO dao=new TopicDAO(); 103 dao.insertForumTopic(to); 104 dao.insertTopics_Forums(to.getTId(),fid); 105 }catch(SQLException sqle){ 106 throw new DBException(sqle.getMessage()); 107 }catch(Throwable t){ 108 throw new BLException(t.getMessage()); 109 } 110 111 } 112 113 public void updateForumTopic(TopicVO to)throws BLException{ 114 ftopicCache.clear(); 115 try{ 116 TopicDAO dao=new TopicDAO(); 117 dao.updateForumTopic(to); 118 119 }catch(SQLException sqle){ 120 throw new DBException(sqle.getMessage()); 121 }catch(Throwable t){ 122 throw new BLException(t.getMessage()); 123 } 124 125 } 126 127 128 129 public TopicVO getTopic(int id) throws BLException{ 130 TopicVO mod=null; 132 try{ 133 TopicDAO dao=new TopicDAO(); 134 mod=dao.getTopicById(id); 135 }catch(SQLException sqle){ 136 throw new DBException(sqle.getMessage()); 137 }catch(Throwable t){ 138 throw new BLException(t.getMessage()); 139 } 140 return mod; 141 } 142 public TopicVO getLastTopicByFId(int id) throws BLException{ 143 TopicVO mod=null; 144 if(ftopicCache.containsKey("TopicBL.getLastTopicByFId-"+id)){ 145 mod=(TopicVO)ftopicCache.get("TopicBL.getLastTopicByFId-"+id); 146 return mod; 147 } 148 149 try{ 150 TopicDAO dao=new TopicDAO(); 151 mod=dao.getLastTopicByFId(id); 152 this.fillTopic(mod); 153 }catch(SQLException sqle){ 154 throw new DBException(sqle.getMessage()); 155 }catch(Throwable t){ 156 throw new BLException(t.getMessage()); 157 } 158 if(mod!=null) 159 ftopicCache.put("TopicBL.getLastTopicByFId-"+id,mod,7200); 160 return mod; 161 } 162 163 public TopicVO getForumTopicByTId(int id) throws BLException{ 164 TopicVO mod=null; 165 if(ftopicCache.containsKey("TopicBL.getForumTopicByTId-"+id)){ 166 mod=(TopicVO)ftopicCache.get("TopicBL.getForumTopicByTId-"+id); 167 return mod; 168 } 169 try{ 170 TopicDAO dao=new TopicDAO(); 171 mod=dao.getTopicById(id); 172 this.fillTopic(mod); 173 }catch(SQLException sqle){ 174 throw new DBException(sqle.getMessage()); 175 }catch(Throwable t){ 176 throw new BLException(t.getMessage()); 177 } 178 if(mod!=null) 179 ftopicCache.put("TopicBL.getForumTopicByTId-"+id,mod,7200); 180 return mod; 181 } 182 183 public void setLastModTime(TopicVO t)throws BLException{ 184 ICommentBL cbl=(ICommentBL)MiddleFactory.getBL("ICommentBL"); 185 186 CommentVO com=null; 187 com=cbl.getLastForumCommentByTId(t.getTId()); 188 if(com==null){ 189 t.setLastModTime(t.getCreationTime()); 190 }else{ 191 t.setLastModTime(com.getTime() ); 192 } 193 } 194 195 public TopicVO fillTopic(TopicVO t) throws BLException{ 196 if(t==null) 197 return t; 198 204 IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL"); 205 ICommentBL cbl=(ICommentBL)MiddleFactory.getBL("ICommentBL"); 206 t.setComments(cbl.getForumCommentsByXId(t.getTId())); 207 t.setAuthor(ubl.getUserByID(t.getELink())); 208 this.setLastModTime(t); 209 return t; 211 } 212 213 public TopicVO getTopicByName(String name) throws BLException{ 214 TopicVO mod=null; 216 try{ 217 TopicDAO dao=new TopicDAO(); 218 mod=dao.getTopicByName(name); 219 }catch(SQLException sqle){ 220 throw new DBException(sqle.getMessage()); 221 }catch(Throwable t){ 222 throw new BLException(t.getMessage()); 223 } 224 return mod; 225 } 226 227 public TopicVO getTopicByImage(String name) throws BLException{ 228 TopicVO mod=null; 229 try{ 230 TopicDAO dao=new TopicDAO(); 231 mod=dao.getTopicByImage(name); 232 }catch(SQLException sqle){ 233 throw new DBException(sqle.getMessage()); 234 }catch(Throwable t){ 235 throw new BLException(t.getMessage()); 236 } 237 return mod; 238 } 239 240 public ArrayList getAllTopics(String type) throws BLException{ 241 ArrayList list=null; 242 try{ 243 TopicDAO dao=new TopicDAO(); 244 list=dao.getAllTopics(type); 245 246 }catch(SQLException sqle){ 247 throw new DBException(sqle.getMessage()); 248 }catch(Throwable t){ 249 throw new BLException(t.getMessage()); 250 } 251 return list; 252 } 253 254 public ArrayList getTopicsByNews(NewsVO n) throws BLException{ 255 ArrayList list=null; 256 try{ 257 TopicDAO dao=new TopicDAO(); 258 list=dao.getTopicsByNews(n); 259 260 }catch(SQLException sqle){ 261 throw new DBException(sqle.getMessage()); 262 }catch(Throwable t){ 263 throw new BLException(t.getMessage()); 264 } 265 return list; 266 } 267 268 public CountArrayList getTopicsByFId(int fid) throws BLException{ 269 CountArrayList list=null; 270 if(ftopicCache.containsKey("TopicBL.getTopicsByFId-"+fid)){ 271 list=(CountArrayList)ftopicCache.get("TopicBL.getTopicsByFId-"+fid); 272 return list; 273 } 274 try{ 275 TopicDAO dao=new TopicDAO(); 276 list=dao.getTopicsByFId(fid); 277 278 }catch(SQLException sqle){ 279 throw new DBException(sqle.getMessage()); 280 }catch(Throwable t){ 281 throw new BLException(t.getMessage()); 282 } 283 if(list!=null) 284 ftopicCache.put("TopicBL.getTopicsByFId-"+fid,list,7200); 285 return list; 286 } 287 288 public CountArrayList getForumTopicsByText(String text) throws BLException{ 289 CountArrayList list=null; 290 if(ftopicCache.containsKey("TopicBL.getForumTopicsByTex-"+text)){ 291 list=(CountArrayList)ftopicCache.get("TopicBL.getForumTopicsByTex-"+text); 292 return list; 293 } 294 ArrayList ll=null,aux=null; 295 ll=new ArrayList (); 296 String [] wordsA=TextUtil.tokenize(text,",-;. "); 297 298 try{ 299 TopicDAO dao=new TopicDAO(); 300 for(int i=0;i<wordsA.length;i++){ 301 list=dao.getForumTopicsByText(wordsA[i]); 302 aux=new ArrayList (list); 303 ll.addAll(aux); 304 305 } 306 307 ll=MagicCollections.semplifyAndSort(ll,new ForumTopicComparator()); 308 309 }catch(SQLException sqle){ 310 throw new DBException(sqle.getMessage()); 311 }catch(Throwable t){ 312 throw new BLException(t.getMessage()); 313 } 314 list=new CountArrayList(ll); 315 316 if(list!=null) 317 ftopicCache.put("TopicBL.getForumTopicsByTex-"+text,list,7200); 318 return list; 319 } 320 321 } | Popular Tags |