1 25 26 29 package net.killingar.forum.internal.managers; 30 31 import net.killingar.forum.internal.*; 32 33 import java.sql.Connection ; 34 import java.sql.ResultSet ; 35 import java.sql.SQLException ; 36 import java.sql.Statement ; 37 import java.util.ArrayList ; 38 39 public class FAQManager extends AbstractManager implements java.io.Serializable 40 { 41 44 public FAQTopic getFAQTopic(long ID) throws SQLException 45 { 46 Connection c = null; 47 Statement statement = null; 48 ResultSet result = null; 49 50 try 51 { 52 c = getNewConnection(); 53 statement = c.createStatement(); 54 55 result = statement.executeQuery("select User, Topic, Time, Priority from FAQTopics where ID = "+ID); 56 FAQTopic r = null; 57 if (result.next()) 58 { 59 r = new FAQTopic( 60 ID, 61 result.getLong(1), 62 result.getString(2), 63 result.getDate(3), 64 result.getInt(4)); 65 } 66 67 return r; 68 } 69 finally { closeAll(c, statement, result); } 70 } 71 72 75 public FAQTopic getFAQTopic(String topic) throws SQLException 76 { 77 Connection c = null; 78 Statement statement = null; 79 ResultSet result = null; 80 81 try 82 { 83 c = getNewConnection(); 84 statement = c.createStatement(); 85 86 result = statement.executeQuery("select ID, User, Topic, Time, Priority from FAQTopics where Topic = '"+Utils.disableSQL(topic)+"'"); 87 FAQTopic r = null; 88 if (result.next()) 89 { 90 r = new FAQTopic( 91 result.getLong(1), 92 result.getLong(2), 93 result.getString(3), 94 result.getDate(4), 95 result.getInt(5)); 96 } 97 98 return r; 99 } 100 finally { closeAll(c, statement, result); } 101 } 102 103 106 public FAQTopic[] getFAQTopics() throws SQLException 107 { 108 Connection c = null; 109 Statement statement = null; 110 ResultSet result = null; 111 112 try 113 { 114 c = getNewConnection(); 115 statement = c.createStatement(); 116 117 result = statement.executeQuery("select ID, User, Topic, Time, Priority from FAQTopics"); 118 ArrayList l = new ArrayList (); 119 while (result.next()) 120 { 121 l.add(new FAQTopic( 122 result.getLong(1), 123 result.getLong(2), 124 result.getString(3), 125 result.getDate(4), 126 result.getInt(5))); 127 } 128 129 FAQTopic r[] = new FAQTopic[l.size()]; 130 l.toArray(r); 131 return r; 132 } 133 finally { closeAll(c, statement, result); } 134 } 135 136 139 public void addFAQTopic(FAQTopic topic) throws SQLException , AccessDeniedException 140 { 141 manager.checkMyAccess(AccessLevel.addFAQTopic); 142 143 Connection c = null; 144 Statement statement = null; 145 ResultSet result = null; 146 147 try 148 { 149 c = getNewConnection(); 150 statement = c.createStatement(); 151 152 statement.executeUpdate("insert into FAQTopics (User, Topic, Priority) values("+ 153 manager.getUserID()+", '"+ 154 Utils.disableSQL(topic.topic)+"', "+ 155 topic.priority+")"); 156 } 157 finally { closeAll(c, statement, result); } 158 } 159 160 163 public void removeFAQTopic(long ID) throws SQLException , AccessDeniedException 164 { 165 manager.checkMyAccess(AccessLevel.removeFAQTopic); 166 167 Connection c = null; 168 Statement statement = null; 169 ResultSet result = null; 170 171 try 172 { 173 c = getNewConnection(); 174 statement = c.createStatement(); 175 176 statement.executeUpdate("delete from FAQTopics where ID = "+ID); 177 } 178 finally { closeAll(c, statement, result); } 179 } 180 181 184 public void changeFAQTopic(FAQTopic topic) throws SQLException , AccessDeniedException 185 { 186 manager.checkMyAccess(AccessLevel.changeFAQ); 187 188 Connection c = null; 189 Statement statement = null; 190 ResultSet result = null; 191 192 try 193 { 194 c = getNewConnection(); 195 statement = c.createStatement(); 196 197 statement.executeUpdate("update FAQTopics set User = "+manager.getUserID()+", Topic = '"+Utils.disableSQL(topic.topic)+", Priority = "+topic.priority); 198 } 199 finally { closeAll(c, statement, result); } 200 } 201 202 205 public FAQ getFAQ(long ID) throws SQLException 206 { 207 Connection c = null; 208 Statement statement = null; 209 ResultSet result = null; 210 211 try 212 { 213 c = getNewConnection(); 214 statement = c.createStatement(); 215 216 result = statement.executeQuery("select User, Topic, Question, Answer, Time, Priority from FAQs where ID = "+ID); 217 FAQ r = null; 218 if (result.next()) 219 { 220 r = new FAQ( 221 ID, 222 result.getLong(1), 223 result.getLong(2), 224 result.getString(3), 225 result.getString(4), 226 result.getDate(5), 227 result.getInt(6)); 228 } 229 230 return r; 231 } 232 finally { closeAll(c, statement, result); } 233 } 234 235 238 public FAQ[] getFAQs(long topicID) throws SQLException 239 { 240 Connection c = null; 241 Statement statement = null; 242 ResultSet result = null; 243 244 try 245 { 246 c = getNewConnection(); 247 statement = c.createStatement(); 248 249 result = statement.executeQuery("select ID, User, Question, Answer, Time, Priority from FAQs where Topic = "+topicID); 250 ArrayList l = new ArrayList (); 251 while (result.next()) 252 { 253 l.add(new FAQ( 254 result.getLong(1), 255 result.getLong(2), 256 topicID, 257 result.getString(3), 258 result.getString(4), 259 result.getDate(5), 260 result.getInt(6))); 261 } 262 263 FAQ r[] = new FAQ[l.size()]; 264 l.toArray(r); 265 return r; 266 } 267 finally { closeAll(c, statement, result); } 268 } 269 270 273 public void addFAQ(FAQ faq) throws SQLException , AccessDeniedException 274 { 275 manager.checkMyAccess(AccessLevel.addFAQ); 276 if (getFAQTopic(faq.topicID) == null) 277 throw new AccessDeniedException("no such topic id ("+faq.topicID+")"); 278 279 Connection c = null; 280 Statement statement = null; 281 ResultSet result = null; 282 283 try 284 { 285 c = getNewConnection(); 286 statement = c.createStatement(); 287 288 statement.executeUpdate("insert into FAQs (User, Topic, Question, Answer, Priority) values("+ 289 manager.getUserID()+", "+ 290 faq.topicID+", '"+ 291 Utils.disableSQL(faq.question)+"', '"+ 292 Utils.disableSQL(faq.answer)+"', "+ 293 faq.priority+")"); 294 } 295 finally { closeAll(c, statement, result); } 296 } 297 298 301 public void removeFAQ(long ID) throws SQLException , AccessDeniedException 302 { 303 manager.checkMyAccess(AccessLevel.removeFAQ); 304 305 Connection c = null; 306 Statement statement = null; 307 ResultSet result = null; 308 309 try 310 { 311 c = getNewConnection(); 312 statement = c.createStatement(); 313 314 statement.executeUpdate("delete from FAQs where ID = "+ID); 315 } 316 finally { closeAll(c, statement, result); } 317 } 318 319 322 public void changeFAQ(FAQ faq) throws SQLException , AccessDeniedException 323 { 324 manager.checkMyAccess(AccessLevel.changeFAQ); 325 326 Connection c = null; 327 Statement statement = null; 328 ResultSet result = null; 329 330 try 331 { 332 c = getNewConnection(); 333 statement = c.createStatement(); 334 335 statement.executeUpdate("update FAQs set User = "+manager.getUserID()+", Topic = "+faq.topicID+", Question = '"+Utils.disableSQL(faq.question)+"', Answer = '"+Utils.disableSQL(faq.answer)+"', Priority = "+faq.priority+" where ID = "+faq.getId()); 336 } 337 finally { closeAll(c, statement, result); } 338 } 339 } 340 | Popular Tags |