1 2 23 package com.geinuke.dao; 24 25 import java.sql.SQLException ; 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.List ; 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 { 38 super(); 39 40 } 41 42 public void insertTopic(TopicVO t) throws Exception { 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 { 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 { 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 { 79 80 try{ 81 HashMap map=new HashMap (); 82 map.put("tid",new Integer (tid)); 83 map.put("fid",new Integer (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 { 95 96 try{ 97 this.sqlMap().startTransaction(); 98 this.sqlMap().delete("delForumTopicByTId",new Integer (tid)); 99 this.sqlMap().commitTransaction(); 100 }finally{ 101 this.sqlMap().endTransaction(); 102 } 103 104 } 105 106 public void delForumTopicsByFId(int fid) throws Exception { 107 108 try{ 109 this.sqlMap().startTransaction(); 110 this.sqlMap().delete("delForumTopicsByFId",new Integer (fid)); 111 this.sqlMap().commitTransaction(); 112 }finally{ 113 this.sqlMap().endTransaction(); 114 } 115 116 } 117 118 119 120 121 126 public ArrayList getAllTopics(String type)throws SQLException { 127 ArrayList list=null; 128 List 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 (llist); 137 return list; 138 } 139 140 public ArrayList getTopicsByNews(NewsVO n)throws SQLException { 141 ArrayList list=null; 142 List 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 (llist); 151 return list; 152 } 153 154 public CountArrayList getTopicsByFId(int fid)throws Exception { 155 CountArrayList list=null; 156 List llist=null; 157 try{ 158 sqlMap().startTransaction(); 159 llist=sqlMap().queryForList("getTopicsByFId",new Integer (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 text)throws Exception { 175 CountArrayList list=null; 176 text="%"+text+"%"; 177 List llist=null; 178 try{ 179 sqlMap().startTransaction(); 180 llist=sqlMap().queryForList("getForumTopicsByText",text); 181 this.sqlMap().commitTransaction(); 182 }finally{ 183 sqlMap().endTransaction(); 184 } 185 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 return list; 197 } 198 199 public TopicVO getTopicById(int id)throws SQLException { 200 TopicVO res=null; 201 202 try{ 203 sqlMap().startTransaction(); 204 res=(TopicVO)sqlMap().queryForObject("getTopicById",new Integer (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 { 214 TopicVO res=null; 215 216 try{ 217 sqlMap().startTransaction(); 218 res=(TopicVO)sqlMap().queryForObject("getLastTopicByFId",new Integer (id)); 219 this.sqlMap().commitTransaction(); 220 }finally{ 221 sqlMap().endTransaction(); 222 } 223 224 return res; 225 } 226 227 public TopicVO getTopicByName(String name)throws SQLException { 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 name)throws SQLException { 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 |