1 2 23 package com.geinuke.bizlogic; 24 25 import java.sql.SQLException ; 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 30 import com.geinuke.dao.UserDAO; 31 32 import com.geinuke.middle.ICommentBL; 33 import com.geinuke.middle.ITopicBL; 34 import com.geinuke.middle.IUserBL; 35 import com.geinuke.middle.MiddleFactory; 36 import com.geinuke.servlet.GeiServlet; 37 import com.geinuke.util.collection.CachedBL; 38 import com.geinuke.util.collection.SimpleCache; 39 import com.geinuke.vo.CommentVO; 40 import com.geinuke.vo.RoleVO; 41 import com.geinuke.vo.UserVO; 42 import com.geinuke.util.log.*; 43 44 public class UserBL extends CachedBL implements IUserBL { 45 46 47 48 49 public UserBL(){ 50 51 super(); 52 } 53 54 55 56 public ArrayList getUsersByForumID(int fid) throws BLException { 57 ArrayList ll=null; 58 59 60 try{ 61 UserDAO dao=new UserDAO(); 62 List list=dao.getUsersByForumID(fid); 63 64 ll=new ArrayList (list); 65 }catch(SQLException sqle){ 66 throw new DBException(sqle.getMessage()); 67 }catch(Throwable t){ 68 throw new BLException(t.getMessage()); 69 } 70 71 return ll; 72 } 73 74 public UserVO getDefUser()throws BLException{ 75 BizLogger.intLog("USerBL.getDefUser(...), START"); 76 UserVO user=null; 77 user=new UserVO(); 78 user.setUName(UserVO.ANONYMOUS); 79 user=this.getUserByUName(user); 80 BizLogger.intLog("USerBL.getDefUser(...), style "+user.getDefStyle()); 81 RoleVO role=null; 82 role=new RoleVO(); 83 role.setRoleName(UserVO.ANONYMOUS); 84 role.setId(1); 85 role.setLevela(10); 86 user.setRole(role); 87 return user; 88 } 89 90 public UserVO getUserToByPID(int pid)throws BLException{ 91 UserVO user=null; 92 93 try{ 94 UserDAO dao=new UserDAO(); 95 user=dao.getUserToByPID(pid); 96 }catch(SQLException sqle){ 97 throw new DBException(sqle.getMessage()); 98 }catch(Throwable t){ 99 throw new BLException(t.getMessage()); 100 } 101 102 return user; 103 } 104 105 public UserVO getUserFromByPID(int pid)throws BLException{ 106 UserVO user=null; 107 108 try{ 109 UserDAO dao=new UserDAO(); 110 user=dao.getUserFromByPID(pid); 111 }catch(SQLException sqle){ 112 throw new DBException(sqle.getMessage()); 113 }catch(Throwable t){ 114 throw new BLException(t.getMessage()); 115 } 116 117 return user; 118 } 119 120 121 public UserVO getUUserByID(UserVO u)throws BLException{ 122 UserVO user=null; 123 if(userCache.containsKey("UserBL.getUUserByID-"+u.getId())){ 124 user=(UserVO)userCache.get("UserBL.getUUserByID-"+u.getId()); 125 return user; 126 } 127 user=new UserVO(); 128 try{ 129 UserDAO dao=new UserDAO(); 130 user=dao.getUserByID(u); 131 }catch(SQLException sqle){ 132 throw new DBException(sqle.getMessage()); 133 }catch(Throwable t){ 134 throw new BLException(t.getMessage()); 135 } 136 if(user!=null) 137 userCache.put("UserBL.getUUserByID-"+u.getId(),user,7200); 138 return user; 139 } 140 141 public UserVO getUserByID(int id)throws BLException{ 142 UserVO user=null; 143 user=new UserVO(); 144 user.setId(id); 145 return getUUserByID(user); 146 } 147 148 public UserVO getLastTopicAuthorByTId(int tid)throws BLException{ 149 UserVO user=null; 150 int id=-1; 151 CommentVO co=null; 152 153 ICommentBL coBL=(ICommentBL)MiddleFactory.getBL("ICommentBL"); 154 155 156 co=coBL.getLastForumCommentByTId(tid); 157 if(co==null){ 158 ITopicBL tBL=(ITopicBL)MiddleFactory.getBL("ITopicBL"); 159 user=tBL.getForumTopicByTId(tid).getAuthor(); 160 return user; 161 }else{ 162 id=co.getUId(); 163 user=new UserVO(); 164 user.setId(id); 165 return getUUserByID(user); 166 } 167 168 } 169 170 public HashMap getLastTopicsAuthorByTIdArray(ArrayList tv)throws BLException{ 171 HashMap map=new HashMap (); 172 int j=-1; 173 for(int i=0;i<tv.size();i++){ 174 j=((Integer )tv.get(i)).intValue(); 175 map.put(""+j,this.getLastTopicAuthorByTId(j)); 176 } 177 return map; 178 } 179 180 181 public void insUser(UserVO u)throws BLException{ 182 userCache.clear(); 183 try{ 184 UserDAO dao=new UserDAO(); 185 dao.insertUser(u); 186 187 }catch(SQLException sqle){ 188 throw new DBException(sqle.getMessage()); 189 }catch(Throwable t){ 190 throw new BLException(t.getMessage()); 191 } 192 193 } 194 195 public void insRole(RoleVO u)throws BLException{ 196 197 try{ 198 UserDAO dao=new UserDAO(); 199 dao.insertRole(u); 200 201 }catch(SQLException sqle){ 202 throw new DBException(sqle.getMessage()); 203 }catch(Throwable t){ 204 throw new BLException(t.getMessage()); 205 } 206 207 } 208 209 public void updateUser(UserVO u)throws BLException{ 210 userCache.clear(); 211 try{ 212 UserDAO dao=new UserDAO(); 213 dao.updateUser(u); 214 215 }catch(SQLException sqle){ 216 throw new DBException(sqle.getMessage()); 217 }catch(Throwable t){ 218 throw new BLException(t.getMessage()); 219 } 220 221 } 222 223 public void updateAllDefStyle(String style)throws BLException{ 224 userCache.clear(); 225 try{ 226 UserDAO dao=new UserDAO(); 227 dao.updateAllDefStyle(style); 228 229 }catch(SQLException sqle){ 230 throw new DBException(sqle.getMessage()); 231 }catch(Throwable t){ 232 throw new BLException(t.getMessage()); 233 } 234 235 } 236 237 public ArrayList getAllRoles() throws BLException{ 238 ArrayList list=null; 239 try{ 240 UserDAO dao=new UserDAO(); 241 list=dao.getAllRoles(); 242 243 }catch(SQLException sqle){ 244 throw new DBException(sqle.getMessage()); 245 }catch(Throwable t){ 246 throw new BLException(t.getMessage()); 247 } 248 return list; 249 } 250 251 public ArrayList getAllUsers() throws BLException{ 252 ArrayList list=null; 253 BizLogger.intLog("UserBL.getAllUsers(), simple trace ..."); 254 if(userCache.containsKey("UserBL.getAllUsers-")){ 255 list=(ArrayList )userCache.get("UserBL.getAllUsers-"); 256 return list; 257 } 258 try{ 259 UserDAO dao=new UserDAO(); 260 list=dao.getAllUsers(); 261 262 }catch(SQLException sqle){ 263 throw new DBException(sqle.getMessage()); 264 }catch(Throwable t){ 265 throw new BLException(t.getMessage()); 266 } 267 userCache.put("UserBL.getAllUsers-",list,7200); 268 return list; 269 } 270 271 public void updateUserRole(UserVO u)throws BLException{ 272 userCache.clear(); 273 try{ 274 UserDAO dao=new UserDAO(); 275 dao.updateUserRole(u); 276 277 }catch(SQLException sqle){ 278 throw new DBException(sqle.getMessage()); 279 }catch(Throwable t){ 280 throw new BLException(t.getMessage()); 281 } 282 283 } 284 285 public UserVO getUserByAuth(UserVO u)throws BLException{ 286 UserVO user=null; 287 288 user=new UserVO(); 289 try{ 290 UserDAO dao=new UserDAO(); 291 user=dao.getUserByAuth(u); 292 293 }catch(SQLException sqle){ 294 throw new DBException(sqle.getMessage()); 295 }catch(Throwable t){ 296 throw new BLException(t.getMessage()); 297 } 298 299 return user; 300 } 301 302 public UserVO getUserByUName(UserVO u)throws BLException{ 303 BizLogger.intLog("USerBL.getUserByUName(...), START"); 304 UserVO user=null; 305 if(userCache.containsKey("UserBL.getUserByUName-"+u.getUName())){ 306 user=(UserVO)userCache.get("UserBL.getUserByUName-"+u.getUName()); 307 return user; 308 } 309 if(u.getRole()==null){ 310 RoleVO r=new RoleVO(); 311 u.setRole(r); 312 } 313 user=new UserVO(); 314 try{ 315 UserDAO dao=new UserDAO(); 316 user=dao.getUserByUName(u); 317 }catch(SQLException sqle){ 318 throw new DBException(sqle.getMessage()); 319 }catch(Throwable t){ 320 throw new BLException(t.getMessage()); 321 } 322 if(user!=null) 323 userCache.put("UserBL.getUserByUName-"+u.getUName(),user,7200); 324 return user; 325 } 326 327 328 } 329 | Popular Tags |