1 2 23 package com.geinuke.dao; 24 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 import java.util.Hashtable ; 28 import java.util.List ; 29 30 import com.geinuke.vo.CategoryVO; 31 import com.geinuke.vo.NewsVO; 32 import com.geinuke.vo.TopicVO; 33 34 35 public class NewsDAO extends GeiDAO{ 36 37 38 public NewsDAO() throws Exception { 39 super(); 40 41 } 42 43 public void insertNews(NewsVO n) throws Exception { 44 45 try{ 46 this.sqlMap().startTransaction(); 47 this.sqlMap().insert("insNews",n); 48 this.sqlMap().commitTransaction(); 49 50 }finally{ 51 this.sqlMap().endTransaction(); 52 } 53 if(n.getCategories().size()>0){ 54 this.insertNewsCategories(n); 55 } 56 if(n.getTopics().size()>0){ 57 this.insertNewsTopics(n); 58 } 59 60 } 61 62 public void updateNews(NewsVO n) throws Exception { 63 64 try{ 65 this.sqlMap().startTransaction(); 66 this.sqlMap().update("updateNews",n); 67 this.sqlMap().commitTransaction(); 68 }finally{ 69 this.sqlMap().endTransaction(); 70 } 71 72 } 73 74 public void deleteNews(int nid) throws Exception { 75 76 try{ 77 this.sqlMap().startTransaction(); 78 this.sqlMap().delete("deleteNews",new Integer (nid)); 79 this.sqlMap().commitTransaction(); 80 }finally{ 81 this.sqlMap().endTransaction(); 82 } 83 84 } 85 86 public List getAllNews()throws Exception { 87 List list=null; 88 try{ 89 this.sqlMap().startTransaction(); 90 list=this.sqlMap().queryForList("getAllNews",""); 91 this.sqlMap().commitTransaction(); 92 }finally{ 93 this.sqlMap().endTransaction(); 94 } 95 return list; 96 97 } 98 99 public NewsVO getNewsByNId(int nid)throws Exception { 100 NewsVO n=null; 101 try{ 102 this.sqlMap().startTransaction(); 103 n=(NewsVO)this.sqlMap().queryForObject("getNewsByNId",new Integer (nid)); 104 this.sqlMap().commitTransaction(); 105 }finally{ 106 this.sqlMap().endTransaction(); 107 } 108 return n; 109 110 } 111 112 113 114 public List getEnabledNews()throws Exception { 115 List list=null; 116 try{ 117 this.sqlMap().startTransaction(); 118 list=this.sqlMap().queryForList("getEnabledNews",""); 119 this.sqlMap().commitTransaction(); 120 }finally{ 121 this.sqlMap().endTransaction(); 122 } 123 return list; 124 125 } 126 127 public List getNewsByTopic(int tid)throws Exception { 128 List list=null; 129 try{ 130 this.sqlMap().startTransaction(); 131 list=this.sqlMap().queryForList("getNewsByTopic",new Integer (tid)); 132 this.sqlMap().commitTransaction(); 133 }finally{ 134 this.sqlMap().endTransaction(); 135 } 136 return list; 137 138 } 139 140 public List getNewsByTitleOrText(String text)throws Exception { 141 List list=null; 142 text="%"+text+"%"; 143 try{ 144 this.sqlMap().startTransaction(); 145 list=this.sqlMap().queryForList("getNewsByTitleOrText",text); 146 this.sqlMap().commitTransaction(); 147 }finally{ 148 this.sqlMap().endTransaction(); 149 } 150 return list; 153 154 } 155 156 public List getEnabledNewsByPeriod(Long [] bounds)throws Exception { 157 List list=null; 158 HashMap bo=null; 159 try{ 160 bo=new HashMap (); 161 bo.put("lowBound",bounds[0]); 162 bo.put("upBound",bounds[1]); 163 this.sqlMap().startTransaction(); 164 list=this.sqlMap().queryForList("getEnabledNewsByPeriod",bo); 165 this.sqlMap().commitTransaction(); 166 }finally{ 167 this.sqlMap().endTransaction(); 168 } 169 return list; 170 171 } 172 173 public List getDisabledNews()throws Exception { 174 List list=null; 175 try{ 176 this.sqlMap().startTransaction(); 177 list=this.sqlMap().queryForList("getDisabledNews",""); 178 this.sqlMap().commitTransaction(); 179 }finally{ 180 this.sqlMap().endTransaction(); 181 } 182 return list; 183 184 } 185 186 public void updateNewsCategories(NewsVO n) throws Exception { 187 188 try{ 189 ArrayList categories=n.getCategories(); 190 CategoryVO c=null; 191 Hashtable h=new Hashtable (); 192 this.sqlMap().startTransaction(); 193 for(int i=0;i<categories.size();i++){ 194 c=(CategoryVO)categories.get(i); 195 h.put("catId", new Integer ( c.getCatId() ) ); 196 h.put("nId",new Integer ( n.getNId() )); 197 198 this.sqlMap().update("updateNewsCat",h); 199 } 200 this.sqlMap().commitTransaction(); 201 }finally{ 202 this.sqlMap().endTransaction(); 203 } 204 205 } 206 207 public void insertNewsCategories(NewsVO n) throws Exception { 208 209 try{ 210 ArrayList categories=n.getCategories(); 211 CategoryVO c=null; 212 Hashtable h=new Hashtable (); 213 this.sqlMap().startTransaction(); 214 for(int i=0;i<categories.size();i++){ 215 c=(CategoryVO)categories.get(i); 216 h.put("catId", new Integer ( c.getCatId() ) ); 217 h.put("nId",new Integer ( n.getNId() )); 218 219 this.sqlMap().insert("insNewsCat",h); 220 } 221 this.sqlMap().commitTransaction(); 222 }finally{ 223 this.sqlMap().endTransaction(); 224 } 225 226 } 227 228 public void insertNewsTopics(NewsVO n) throws Exception { 229 230 try{ 231 ArrayList topics=n.getTopics(); 232 TopicVO t=null; 233 Hashtable h=new Hashtable (); 234 this.sqlMap().startTransaction(); 235 for(int i=0;i<topics.size();i++){ 236 t=(TopicVO)topics.get(i); 237 h.put("tId", new Integer ( t.getTId() ) ); 238 h.put("nId",new Integer ( n.getNId() )); 239 this.sqlMap().insert("insNewsTop",h); 240 } 241 this.sqlMap().commitTransaction(); 242 }finally{ 243 this.sqlMap().endTransaction(); 244 } 245 246 } 247 248 public void updateNewsTopics(NewsVO n) throws Exception { 249 250 try{ 251 ArrayList topics=n.getTopics(); 252 TopicVO t=null; 253 Hashtable h=new Hashtable (); 254 this.sqlMap().startTransaction(); 255 for(int i=0;i<topics.size();i++){ 256 t=(TopicVO)topics.get(i); 257 h.put("tId", new Integer ( t.getTId() ) ); 258 h.put("nId",new Integer ( n.getNId() )); 259 this.sqlMap().update("updateNewsTop",h); 260 } 261 this.sqlMap().commitTransaction(); 262 }finally{ 263 this.sqlMap().endTransaction(); 264 } 265 266 } 267 268 269 270 271 272 273 } 274 | Popular Tags |