KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > dao > ForumDAO


1 /*
2  * $$Id: ForumDAO.java,v 1.6 2005/06/09 07:15:12 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 08.05.2003
27  *
28  */

29 package org.jresearch.gossip.dao;
30
31 import java.lang.reflect.InvocationTargetException JavaDoc;
32 import java.sql.Connection JavaDoc;
33 import java.sql.PreparedStatement JavaDoc;
34 import java.sql.ResultSet JavaDoc;
35 import java.sql.SQLException JavaDoc;
36 import java.sql.Timestamp JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.Date JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.Iterator JavaDoc;
42 import java.util.List JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.Set JavaDoc;
45 import java.util.StringTokenizer JavaDoc;
46
47 import org.apache.struts.util.MessageResources;
48 import org.jresearch.gossip.IConst;
49 import org.jresearch.gossip.beans.LogEntry;
50 import org.jresearch.gossip.beans.LogSearchCriteria;
51 import org.jresearch.gossip.beans.RankInfoDTO;
52 import org.jresearch.gossip.beans.forum.Forum;
53 import org.jresearch.gossip.beans.forum.Group;
54 import org.jresearch.gossip.beans.forum.LastTopic;
55 import org.jresearch.gossip.beans.forum.Message;
56 import org.jresearch.gossip.beans.forum.NewTopic;
57 import org.jresearch.gossip.beans.forum.SearchResult;
58 import org.jresearch.gossip.beans.forum.Topic;
59 import org.jresearch.gossip.beans.forum.attachment.FileData;
60 import org.jresearch.gossip.beans.forum.attachment.FileDataInfo;
61 import org.jresearch.gossip.beans.subscription.Subscriber;
62 import org.jresearch.gossip.beans.user.Entry;
63 import org.jresearch.gossip.beans.user.EntryList;
64 import org.jresearch.gossip.beans.user.User;
65 import org.jresearch.gossip.configuration.Configurator;
66 import org.jresearch.gossip.dao.drivers.DbDriver;
67 import org.jresearch.gossip.dao.drivers.keygen.IKeyGenConst;
68 import org.jresearch.gossip.dao.drivers.keygen.KeyGenerator;
69 import org.jresearch.gossip.dao.drivers.keygen.KeyGeneratorFactory;
70 import org.jresearch.gossip.dao.file.FileProcessorFactory;
71 import org.jresearch.gossip.dao.file.IFileProcConst;
72 import org.jresearch.gossip.dao.file.IFileProcessor;
73 import org.jresearch.gossip.exception.ConfiguratorException;
74 import org.jresearch.gossip.exception.SystemException;
75 import org.jresearch.gossip.forms.ForumForm;
76 import org.jresearch.gossip.forms.GroupForm;
77 import org.jresearch.gossip.forms.MessageForm;
78 import org.jresearch.gossip.forms.ProcessForumForm;
79 import org.jresearch.gossip.forms.ProcessMessageForm;
80 import org.jresearch.gossip.forms.ProcessTopicForm;
81 import org.jresearch.gossip.forms.SearchForm;
82 import org.jresearch.gossip.forms.StylesForm;
83 import org.jresearch.gossip.list.Mapping;
84 import org.jresearch.gossip.list.RecordsData;
85 import org.jresearch.gossip.util.MySQLCodec;
86
87 /**
88  * DOCUMENT ME!
89  *
90  * @author Bel
91  */

92 public class ForumDAO extends DAO {
93
94     private static ForumDAO instance;
95
96     private final DbDriver dbDriver;
97
98     private final KeyGenerator keyGen;
99
100     private static Object JavaDoc lock = new Object JavaDoc();
101
102     private Map JavaDoc fileProcessors = Collections.synchronizedMap(new HashMap JavaDoc());
103
104     private ForumDAO() {
105         try {
106             this.dbDriver = DbDriver.getInstance();
107             this.keyGen = KeyGeneratorFactory
108                     .getKeyGenerator(IKeyGenConst.DEFAULT_KEYGEN);
109         } catch (SQLException JavaDoc ex) {
110             throw new RuntimeException JavaDoc("ForumDAO not initialized", ex);
111         }
112     }
113
114     /**
115      * DOCUMENT ME!
116      *
117      * @return DOCUMENT ME!
118      */

119     public static ForumDAO getInstance() {
120         if (instance == null) {
121             synchronized (lock) {
122                 if (instance == null) {
123                     instance = new ForumDAO();
124                 }
125             }
126         }
127         return instance;
128     }
129
130     private IFileProcessor getFileProcessor(String JavaDoc fileProcessorName)
131             throws SystemException {
132         IFileProcessor fileProcessor = (IFileProcessor) fileProcessors
133                 .get(fileProcessorName);
134         if (fileProcessor == null) {
135             synchronized (fileProcessors) {
136                 if (fileProcessor == null) {
137                     fileProcessor = FileProcessorFactory.getInstance()
138                             .getFileProcessor(fileProcessorName);
139                     fileProcessors.put(fileProcessorName, fileProcessor);
140                 }
141             }
142         }
143         return fileProcessor;
144     }
145
146     /**
147      * DOCUMENT ME!
148      *
149      * @param form
150      *
151      * @throws SQLException
152      * DOCUMENT ME!
153      */

154     public void addForum(ForumForm form) throws SQLException JavaDoc {
155         Connection JavaDoc connection = this.dataSource.getConnection();
156         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
157                 .getQueries().getForumQueries().getSql_ADD_FORUM());
158
159         try {
160             int fid = ((Integer JavaDoc) keyGen.generateKey(
161                     IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_FORUM], connection))
162                     .intValue();
163             ;
164             st.setString(1, form.getForum_name());
165             st.setString(2, form.getForum_desc());
166             st.setInt(3, Integer.parseInt(form.getGroupid()));
167             st.setString(4, form.getForum_sort());
168             st.setInt(5, fid);
169             st.execute();
170         } finally {
171             st.close();
172             connection.close();
173         }
174     }
175
176     /**
177      * DOCUMENT ME!
178      *
179      * @param form
180      *
181      * @throws SQLException
182      * DOCUMENT ME!
183      */

184     public void addGroup(GroupForm form) throws SQLException JavaDoc {
185         Connection JavaDoc connection = this.dataSource.getConnection();
186
187         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
188                 .getQueries().getForumQueries().getSql_ADD_GROUP());
189
190         int gid = ((Integer JavaDoc) keyGen.generateKey(
191                 IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_GROUP], connection))
192                 .intValue();
193         try {
194             st.setString(1, form.getGroup_name());
195             st.setString(2, form.getGroup_sort());
196             st.setInt(3, gid);
197             st.execute();
198         } finally {
199             st.close();
200             connection.close();
201         }
202     }
203
204     /**
205      * DOCUMENT ME!
206      *
207      * @param form
208      * @param ip
209      * DOCUMENT ME!
210      * @param announce
211      * DOCUMENT ME!
212      *
213      * @return DOCUMENT ME!
214      *
215      * @throws SQLException
216      * DOCUMENT ME!
217      */

218     public int addMessage(MessageForm form, String JavaDoc ip, boolean announce)
219             throws SQLException JavaDoc {
220         Connection JavaDoc connection = this.dataSource.getConnection();
221         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
222                 .getQueries().getForumQueries().getSql_ADD_MESSAGE());
223         int mid = ((Integer JavaDoc) keyGen.generateKey(
224                 IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_MESSAGE], connection))
225                 .intValue();
226
227         try {
228             Timestamp JavaDoc now = new Timestamp JavaDoc(now().getTime());
229             st.setString(1, form.getName());
230             st.setString(2, form.getText());
231             st.setTimestamp(3, now);
232             st.setString(4, form.getTitle());
233             st.setInt(5, Integer.parseInt(form.getTid()));
234             st.setString(6, ip);
235             st.setInt(7, mid);
236             st.execute();
237
238             if (announce) {
239                 setThreadSortBy(form.getTid(), 5);
240             }
241
242             updateThreadIntime(form.getTid(), now);
243         } finally {
244             st.close();
245             connection.close();
246         }
247
248         return mid;
249     }
250
251     /**
252      * DOCUMENT ME!
253      *
254      * @param fid
255      * @param uid
256      *
257      * @throws SQLException
258      * DOCUMENT ME!
259      */

260     public void addMod(String JavaDoc fid, String JavaDoc uid) throws SQLException JavaDoc {
261         Connection JavaDoc connection = this.dataSource.getConnection();
262         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
263                 .getQueries().getForumQueries().getSql_CHECK_USER_MOD());
264         ResultSet JavaDoc rs = null;
265
266         try {
267             st.setString(1, uid);
268             st.setInt(2, Integer.parseInt(fid));
269             rs = st.executeQuery();
270
271             if (!rs.next()) {
272                 st = connection.prepareStatement(dbDriver.getQueries()
273                         .getForumQueries().getSql_ADD_MOD());
274                 st.setString(1, uid);
275                 st.setInt(2, Integer.parseInt(fid));
276                 st.execute();
277             }
278         } finally {
279             if (rs != null) {
280                 rs.close();
281             }
282
283             st.close();
284             connection.close();
285         }
286     }
287
288     /**
289      * DOCUMENT ME!
290      *
291      * @param forumId
292      * DOCUMENT ME!
293      * @param user
294      * DOCUMENT ME!
295      *
296      * @return DOCUMENT ME!
297      *
298      * @throws SQLException
299      * DOCUMENT ME!
300      */

301     public boolean checkMod(int forumId, User user) throws SQLException JavaDoc {
302         boolean mod = false;
303         Connection JavaDoc connection = this.dataSource.getConnection();
304         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
305                 .getQueries().getForumQueries().getSql_CHECK_USER_MOD());
306         ResultSet JavaDoc rs = null;
307
308         try {
309             st.setInt(1, forumId);
310             st.setString(2, user.getName());
311             rs = (ResultSet JavaDoc) st.executeQuery();
312             mod = (rs.next() || (user.getStatus() > 7));
313         } finally {
314             if (rs != null) {
315                 rs.close();
316             }
317
318             st.close();
319             connection.close();
320         }
321
322         return mod;
323     }
324
325     /**
326      * DOCUMENT ME!
327      *
328      * @param forumid
329      * @param st
330      * DOCUMENT ME!
331      *
332      * @return DOCUMENT ME!
333      *
334      * @throws SQLException
335      * DOCUMENT ME!
336      */

337     private int countForumTopics(int forumid, PreparedStatement JavaDoc st)
338             throws SQLException JavaDoc {
339         ResultSet JavaDoc rs = null;
340
341         try {
342             st.setInt(1, forumid);
343             rs = (ResultSet JavaDoc) st.executeQuery();
344             rs.next();
345
346             return rs.getInt(1);
347         } finally {
348             if (rs != null) {
349                 rs.close();
350             }
351         }
352     }
353
354     /**
355      * DOCUMENT ME!
356      *
357      * @param tid
358      *
359      * @return
360      * @throws SQLException
361      * DOCUMENT ME!
362      */

363     public int countForumMessages(int fid) throws SQLException JavaDoc {
364         Connection JavaDoc connection = this.dataSource.getConnection();
365         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
366                 .getQueries().getForumQueries().getSql_COUNT_FORUM_MESSAGES());
367         ResultSet JavaDoc rs = null;
368
369         try {
370             st.setInt(1, fid);
371             rs = st.executeQuery();
372             rs.next();
373
374             return rs.getInt(1);
375         } finally {
376             if (rs != null) {
377                 rs.close();
378             }
379
380             st.close();
381             connection.close();
382         }
383     }
384
385     /**
386      * DOCUMENT ME!
387      *
388      * @param tid
389      *
390      * @return
391      * @throws SQLException
392      * DOCUMENT ME!
393      */

394     public int countThreadMessages(int tid) throws SQLException JavaDoc {
395         Connection JavaDoc connection = this.dataSource.getConnection();
396         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
397                 .getQueries().getForumQueries().getSql_COUNT_THREAD_MESSAGES());
398         ResultSet JavaDoc rs = null;
399
400         try {
401             st.setInt(1, tid);
402             rs = st.executeQuery();
403             rs.next();
404
405             return rs.getInt(1);
406         } finally {
407             if (rs != null) {
408                 rs.close();
409             }
410
411             st.close();
412             connection.close();
413         }
414     }
415
416     private int countLogEntries(LogSearchCriteria criteria) throws SQLException JavaDoc {
417         Connection JavaDoc connection = this.dataSource.getConnection();
418         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
419                 .getQueries().getForumQueries().getSql_COUNT_LOG_ENTRIES());
420         ResultSet JavaDoc rs = null;
421
422         try {
423             st.setTimestamp(1, new Timestamp JavaDoc(criteria.getFrom().getTime()));
424             st.setTimestamp(2, new Timestamp JavaDoc(criteria.getTo().getTime()));
425             if (IConst.VALUES.ALL.equals(criteria.getLogger())) {
426                 st.setString(3, "%");
427             } else {
428                 st.setString(3, criteria.getLogger());
429             }
430             if (IConst.VALUES.ALL.equals(criteria.getLog_level())) {
431                 st.setString(4, "%");
432             } else {
433                 st.setString(4, criteria.getLog_level());
434             }
435             if (IConst.VALUES.ALL.equals(criteria.getRemote_ip())) {
436                 st.setString(5, "%");
437             } else {
438                 st.setString(5, criteria.getRemote_ip());
439             }
440             if (IConst.VALUES.ALL.equals(criteria.getSession_id())) {
441                 st.setString(6, "%");
442             } else {
443                 st.setString(6, criteria.getSession_id());
444             }
445             if (IConst.VALUES.ALL.equals(criteria.getUser_name())) {
446                 st.setString(7, "%");
447             } else {
448                 st.setString(7, criteria.getUser_name());
449             }
450
451             rs = st.executeQuery();
452             rs.next();
453
454             return rs.getInt(1);
455         } finally {
456             if (rs != null) {
457                 rs.close();
458             }
459
460             st.close();
461             connection.close();
462         }
463     }
464
465     /**
466      * DOCUMENT ME!
467      *
468      * @param fid
469      *
470      * @throws SQLException
471      * DOCUMENT ME!
472      */

473     public void deleteForum(String JavaDoc fid) throws SQLException JavaDoc {
474         Connection JavaDoc connection = this.dataSource.getConnection();
475
476         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
477                 .getQueries().getForumQueries().getSql_DELETE_FORUM());
478         ResultSet JavaDoc rs = null;
479
480         try {
481             st.setInt(1, Integer.parseInt(fid));
482             st.execute();
483             st = connection.prepareStatement(dbDriver.getQueries()
484                     .getForumQueries().getSql_GET_THREAD_ID_LIST());
485             st.setInt(1, Integer.parseInt(fid));
486             rs = st.executeQuery();
487
488             while (rs.next()) {
489                 deleteThread(rs.getString(1), true);
490             }
491         } finally {
492             if (rs != null) {
493                 rs.close();
494             }
495
496             st.close();
497             connection.close();
498         }
499     }
500
501     /**
502      * DOCUMENT ME!
503      *
504      * @param gid
505      *
506      * @throws SQLException
507      * DOCUMENT ME!
508      */

509     public void deleteGroup(String JavaDoc gid) throws SQLException JavaDoc {
510         Connection JavaDoc connection = this.dataSource.getConnection();
511
512         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
513                 .getQueries().getForumQueries().getSql_DELETE_GROUP());
514         ResultSet JavaDoc rs = null;
515
516         try {
517             st.setInt(1, Integer.parseInt(gid));
518             st.execute();
519             st = connection.prepareStatement(dbDriver.getQueries()
520                     .getForumQueries().getSql_GET_FORUMS_ID_LIST());
521             st.setInt(1, Integer.parseInt(gid));
522             rs = st.executeQuery();
523
524             while (rs.next()) {
525                 deleteForum(rs.getString(1));
526             }
527         } finally {
528             if (rs != null) {
529                 rs.close();
530             }
531
532             st.close();
533             connection.close();
534         }
535     }
536
537     /**
538      * DOCUMENT ME!
539      *
540      * @param form
541      *
542      * @throws SQLException
543      * DOCUMENT ME!
544      * @throws SystemException
545      */

546     public void deleteMessage(ProcessMessageForm form) throws SQLException JavaDoc,
547             SystemException {
548         Connection JavaDoc connection = this.dataSource.getConnection();
549         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
550                 .getQueries().getForumQueries().getSql_DELETE_MESSAGE());
551         ResultSet JavaDoc rs = null;
552
553         try {
554
555             // remove all attachments if exists
556
Message mes = getMessage(form.getMid());
557             if (mes.isHasAttachment()) {
558                 FileDataInfo[] attach = mes.getAttachments();
559                 for (int i = 0; i < attach.length; i++) {
560                     removeAttachment(attach[i].getId());
561                 }
562             }
563             // delete the message...
564
st.setInt(1, Integer.parseInt(form.getMid()));
565             st.execute();
566
567             st = connection.prepareStatement(dbDriver.getQueries()
568                     .getForumQueries().getSql_GET_THREAD_LAST_INTIME());
569             st.setInt(1, Integer.parseInt(form.getTid()));
570             rs = st.executeQuery();
571
572             if (rs.next()) {
573                 updateThreadIntime(form.getTid(), rs.getTimestamp(1));
574             } else { // erase thread if this is the last message in thread...
575
deleteThread(form.getTid());
576             }
577         } finally {
578             if (rs != null) {
579                 rs.close();
580             }
581
582             st.close();
583             connection.close();
584         }
585     }
586
587     /**
588      * DOCUMENT ME!
589      *
590      * @param tid
591      *
592      * @throws SQLException
593      * DOCUMENT ME!
594      */

595     public void deleteThread(String JavaDoc tid) throws SQLException JavaDoc {
596         deleteThread(tid, false);
597     }
598
599     /**
600      * DOCUMENT ME!
601      *
602      * @param tid
603      * DOCUMENT ME!
604      * @param clear
605      * DOCUMENT ME!
606      *
607      * @throws SQLException
608      * DOCUMENT ME!
609      */

610     public void deleteThread(String JavaDoc tid, boolean clear) throws SQLException JavaDoc {
611         Connection JavaDoc connection = this.dataSource.getConnection();
612         int id = Integer.parseInt(tid);
613         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
614                 .getQueries().getForumQueries().getSql_DELETE_THREAD());
615
616         try {
617             st.setInt(1, id);
618             st.execute();
619
620             if (clear) { // DELETE ALL MESSAGES FROM THREAD
621
st = connection.prepareStatement(dbDriver.getQueries()
622                         .getForumQueries().getSql_DELETE_THREAD_MESSAGES());
623                 st.setInt(1, id);
624                 st.execute();
625             }
626
627             st = connection.prepareStatement(dbDriver.getQueries()
628                     .getForumQueries().getSql_DELETE_THREAD_SUBSCRIPTIONS());
629             st.setInt(1, id);
630             st.execute();
631         } finally {
632             st.close();
633             connection.close();
634         }
635     }
636
637     /**
638      * DOCUMENT ME!
639      *
640      * @param fid
641      * @param uid
642      *
643      * @throws SQLException
644      * DOCUMENT ME!
645      */

646     public void dropMod(String JavaDoc fid, String JavaDoc uid) throws SQLException JavaDoc {
647         Connection JavaDoc connection = this.dataSource.getConnection();
648         String JavaDoc queryString = (dbDriver.getQueries().getForumQueries()
649                 .getSql_DROP_USER_MOD());
650         PreparedStatement JavaDoc st = connection.prepareStatement(queryString);
651
652         try {
653             st.setString(1, uid);
654             st.setInt(2, Integer.parseInt(fid));
655             st.execute();
656         } finally {
657             st.close();
658             connection.close();
659         }
660     }
661
662     /**
663      * Retreive records from audit database according to search criteria.
664      * Support paging of results
665      *
666      * @param criteria
667      * @param recordsData
668      * @param block
669      */

670     public void fillLogEntryList(LogSearchCriteria criteria,
671             RecordsData recordsData, int currBlock)
672             throws InstantiationException JavaDoc, IllegalAccessException JavaDoc,
673             InvocationTargetException JavaDoc, NoSuchMethodException JavaDoc, SQLException JavaDoc {
674         Connection JavaDoc connection = this.dataSource.getConnection();
675         String JavaDoc sqlStatement;
676         if (criteria.isSortOrder()) {
677             sqlStatement = dbDriver.getQueries().getForumQueries()
678                     .getSql_GET_LOG_ENTRIES_DESC();
679         } else {
680             sqlStatement = dbDriver.getQueries().getForumQueries()
681                     .getSql_GET_LOG_ENTRIES_ASC();
682         }
683         PreparedStatement JavaDoc st = connection.prepareStatement(sqlStatement);
684         ResultSet JavaDoc rs = null;
685
686         try {
687             st.setTimestamp(1, new Timestamp JavaDoc(criteria.getFrom().getTime()));
688             st.setTimestamp(2, new Timestamp JavaDoc(criteria.getTo().getTime()));
689             if (IConst.VALUES.ALL.equals(criteria.getLogger())) {
690                 st.setString(3, "%");
691             } else {
692                 st.setString(3, criteria.getLogger());
693             }
694             if (IConst.VALUES.ALL.equals(criteria.getLog_level())) {
695                 st.setString(4, "%");
696             } else {
697                 st.setString(4, criteria.getLog_level());
698             }
699             if (IConst.VALUES.ALL.equals(criteria.getRemote_ip())) {
700                 st.setString(5, "%");
701             } else {
702                 st.setString(5, criteria.getRemote_ip());
703             }
704             if (IConst.VALUES.ALL.equals(criteria.getSession_id())) {
705                 st.setString(6, "%");
706             } else {
707                 st.setString(6, criteria.getSession_id());
708             }
709             if (IConst.VALUES.ALL.equals(criteria.getUser_name())) {
710                 st.setString(7, "%");
711             } else {
712                 st.setString(7, criteria.getUser_name());
713             }
714             st.setInt(8, currBlock);
715             st.setInt(9, dbDriver.getLastRowIdx(currBlock, recordsData
716                     .getBlockSize()));
717             rs = (ResultSet JavaDoc) st.executeQuery();
718             recordsData.fillRecords(rs, Mapping.getInstance().LogEntryMapping,
719                     LogEntry.class);
720             recordsData.setCurrBlock(currBlock);
721             recordsData.setRecordsCount(countLogEntries(criteria));
722         } finally {
723             if (rs != null) {
724                 rs.close();
725             }
726
727             st.close();
728             connection.close();
729         }
730     }
731
732     /**
733      * delete all records in audit database.
734      *
735      * @throws SQLException
736      */

737     public void clearLog() throws SQLException JavaDoc {
738         Connection JavaDoc connection = this.dataSource.getConnection();
739         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
740                 .getQueries().getForumQueries().getSql_DELETE_LOG_ALL());
741
742         try {
743             st.execute();
744         } finally {
745             st.close();
746             connection.close();
747         }
748     }
749
750     /**
751      * DOCUMENT ME!
752      *
753      * @param user
754      * @param recordsData
755      * @param form
756      *
757      * @throws InstantiationException
758      * DOCUMENT ME!
759      * @throws IllegalAccessException
760      * DOCUMENT ME!
761      * @throws InvocationTargetException
762      * DOCUMENT ME!
763      * @throws NoSuchMethodException
764      * DOCUMENT ME!
765      * @throws SQLException
766      * DOCUMENT ME!
767      */

768     public void fillMessagesList(User user, RecordsData recordsData,
769             ProcessTopicForm form) throws InstantiationException JavaDoc,
770             IllegalAccessException JavaDoc, InvocationTargetException JavaDoc,
771             NoSuchMethodException JavaDoc, SQLException JavaDoc {
772         Connection JavaDoc connection = this.dataSource.getConnection();
773         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
774                 .getQueries().getForumQueries().getSql_GET_THREAD_MESSAGES());
775         ResultSet JavaDoc rs = null;
776
777         try {
778             int currBlock = Integer.parseInt(form.getBlock());
779             int tid = Integer.parseInt(form.getTid());
780             st.setInt(1, tid);
781             st.setInt(2, currBlock);
782             st.setInt(3, dbDriver.getLastRowIdx(currBlock, user.getSettings()
783                     .getMes_per_page()));
784             rs = (ResultSet JavaDoc) st.executeQuery();
785             recordsData.fillRecords(rs, Mapping.getInstance().MessageMapping,
786                     Message.class);
787             recordsData.setBlockSize(user.getSettings().getMes_per_page());
788             recordsData.setCurrBlock(currBlock);
789             recordsData.setRecordsCount(countThreadMessages(tid));
790         } finally {
791             if (rs != null) {
792                 rs.close();
793             }
794
795             st.close();
796             connection.close();
797         }
798     }
799
800     /**
801      * DOCUMENT ME!
802      *
803      * @param user
804      * @param recordsData
805      * @param form
806      *
807      * @throws InstantiationException
808      * DOCUMENT ME!
809      * @throws IllegalAccessException
810      * DOCUMENT ME!
811      * @throws InvocationTargetException
812      * DOCUMENT ME!
813      * @throws NoSuchMethodException
814      * DOCUMENT ME!
815      * @throws SQLException
816      * DOCUMENT ME!
817      */

818     public void fillThreadList(User user, RecordsData recordsData,
819             ProcessForumForm form) throws InstantiationException JavaDoc,
820             IllegalAccessException JavaDoc, InvocationTargetException JavaDoc,
821             NoSuchMethodException JavaDoc, SQLException JavaDoc {
822         Connection JavaDoc connection = this.dataSource.getConnection();
823         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
824                 .getQueries().getForumQueries().getSql_GET_THREADS());
825         ResultSet JavaDoc rs = null;
826
827         try {
828             int currBlock = Integer.parseInt(form.getBlock());
829             st.setInt(1, Integer.parseInt(form.getFid()));
830             st.setInt(2, currBlock);
831             st.setInt(3, dbDriver.getLastRowIdx(currBlock, user.getSettings()
832                     .getMes_per_page()));
833             rs = (ResultSet JavaDoc) st.executeQuery();
834             recordsData.fillRecords(rs, Mapping.getInstance().TreadMapping,
835                     Topic.class);
836
837             Iterator JavaDoc it = recordsData.getRecords().iterator();
838             st = connection.prepareStatement(dbDriver.getQueries()
839                     .getForumQueries().getSql_GET_THREAD_LAST_MESS());
840
841             while (it.hasNext()) {
842                 setLastMessage((Topic) it.next(), st);
843             }
844
845             st = connection.prepareStatement(dbDriver.getQueries()
846                     .getForumQueries().getSql_COUNT_THREADS());
847             recordsData.setRecordsCount(countForumTopics(Integer.parseInt(form
848                     .getFid()), st));
849             recordsData.setBlockSize(user.getSettings().getMes_per_page());
850
851             recordsData.setCurrBlock(currBlock);
852         } finally {
853             if (rs != null) {
854                 rs.close();
855             }
856
857             st.close();
858             connection.close();
859         }
860     }
861
862     /**
863      * @param mess_id
864      * @return
865      */

866     public ArrayList JavaDoc getAttachmentsInfo(int mess_id) throws SQLException JavaDoc {
867         ArrayList JavaDoc attachments = new ArrayList JavaDoc();
868         Connection JavaDoc connection = this.dataSource.getConnection();
869         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
870                 .getQueries().getForumQueries().getSql_GET_ATTACHMENTS());
871         ResultSet JavaDoc rs = null;
872         try {
873
874             st.setInt(1, mess_id);
875             rs = (ResultSet JavaDoc) st.executeQuery();
876             while (rs.next()) {
877                 FileDataInfo fileData = new FileDataInfo();
878                 fileData.setId(rs.getInt("id"));
879                 fileData.setName(rs.getString("attach_name"));
880                 fileData.setContentType(rs.getString("attach_content_type"));
881                 fileData.setDescription(rs.getString("attach_description"));
882                 fileData.setMessageId(rs.getInt("message_id"));
883                 fileData.setSize(rs.getInt("attach_size"));
884                 attachments.add(fileData);
885             }
886         } finally {
887             if (rs != null) {
888                 rs.close();
889             }
890
891             st.close();
892             connection.close();
893         }
894         return attachments;
895
896     }
897
898     /**
899      * @param id -
900      * attachment Id
901      * @return
902      * @throws SQLException
903      * @throws SystemException
904      */

905     public FileData getAttachment(int id) throws SQLException JavaDoc, SystemException {
906         FileData fd = new FileData();
907         fd.setInfo(getAttachmentInfo(id));
908         IFileProcessor fProc = getFileProcessor(IFileProcConst.ATTACH_FILE_PROCESSOR);
909         byte[] data = fProc.getFileData(IFileProcConst.ATTACH_KEY_PREFIX + id);
910         if (data == null) {
911             data = new byte[0];
912         }
913         fd.setData(data);
914         return fd;
915
916     }
917
918     /**
919      * @param files
920      * @throws SystemException
921      */

922     public void saveAttachments(FileData[] files) throws SQLException JavaDoc,
923             SystemException {
924         Connection JavaDoc connection = this.dataSource.getConnection();
925         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
926                 .getQueries().getForumQueries().getSql_ADD_ATTACH_INFO());
927         IFileProcessor fProc = getFileProcessor(IFileProcConst.ATTACH_FILE_PROCESSOR);
928         try {
929             for (int i = 0; i < files.length; i++) {
930                 int id = ((Integer JavaDoc) keyGen.generateKey(
931                         IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_ATTACH],
932                         connection)).intValue();
933                 FileData fd = files[i];
934                 st.setInt(1, id);
935                 st.setString(2, fd.getInfo().getContentType());
936                 st.setString(3, fd.getInfo().getName());
937                 st.setString(4, fd.getInfo().getDescription());
938                 st.setInt(5, fd.getInfo().getSize());
939                 st.setInt(6, fd.getInfo().getMessageId());
940                 st.execute();
941
942                 fProc.saveFileData(fd.getData(),
943                         IFileProcConst.ATTACH_KEY_PREFIX + id);
944             }
945         } finally {
946             st.close();
947             connection.close();
948         }
949     }
950
951     /**
952      * @param id
953      * @throws SystemException
954      */

955     public void removeAttachment(int id) throws SQLException JavaDoc, SystemException {
956         Connection JavaDoc connection = this.dataSource.getConnection();
957         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
958                 .getQueries().getForumQueries().getSql_DELETE_ATTACH());
959         IFileProcessor fProc = getFileProcessor(IFileProcConst.ATTACH_FILE_PROCESSOR);
960         try {
961             st.setInt(1, id);
962             st.execute();
963             fProc.removeFileData(IFileProcConst.ATTACH_KEY_PREFIX + id);
964         } finally {
965             st.close();
966             connection.close();
967         }
968     }
969
970     /**
971      * @param fileInfo
972      */

973     public void updateAttachmentInfo(FileDataInfo fileInfo) throws SQLException JavaDoc {
974         Connection JavaDoc connection = this.dataSource.getConnection();
975         PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
976                 .getQueries().getForumQueries().getSql_UPDATE_ATTACH_INFO());
977         try {
978             st.setInt(3, fileInfo.getId());
979             st.setString(1, fileInfo.getName());
980             st.setString(2, fileInfo.getDescription());
981             st.executeUpdate();
982         } finally {
983             st.close();
984             connection.close();
985         }
986     }
987
988     /**
989      * DOCUMENT ME!
990      *
991      * @param forumid
992      * DOCUMENT ME!
993      *
994      * @return DOCUMENT ME!
995      *
996      * @throws SQLException
997      * DOCUMENT ME!
998      */

999     public Forum getForumInfo(int forumid) throws SQLException JavaDoc {
1000        Connection JavaDoc connection = this.dataSource.getConnection();
1001        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1002                .getQueries().getForumQueries().getSql_FORUM_INFO());
1003        ResultSet JavaDoc rs = null;
1004        Forum _forum = new Forum();
1005
1006        try {
1007            st.setInt(1, forumid);
1008            rs = (ResultSet JavaDoc) st.executeQuery();
1009
1010            if (rs.next()) {
1011                _forum.setLocked(rs.getInt("locked"));
1012                _forum.setTitle(rs.getString("forumtitle"));
1013                _forum.setDescription(rs.getString("forumdesc"));
1014                _forum.setSort(rs.getString("forum_sort"));
1015                _forum.setGroupid(rs.getInt("groupid"));
1016            }
1017
1018            return _forum;
1019        } finally {
1020            if (rs != null) {
1021                rs.close();
1022            }
1023
1024            st.close();
1025            connection.close();
1026        }
1027    }
1028
1029    /**
1030     * DOCUMENT ME!
1031     *
1032     * @param group
1033     * DOCUMENT ME!
1034     * @param userStatus
1035     * DOCUMENT ME!
1036     * @param messages
1037     * DOCUMENT ME!
1038     *
1039     * @throws SQLException
1040     * DOCUMENT ME!
1041     */

1042    public void getForums(Group group, int userStatus)
1043            throws NumberFormatException JavaDoc, SQLException JavaDoc, ConfiguratorException {
1044        getForums(group, userStatus, true);
1045    }
1046
1047    /**
1048     * DOCUMENT ME!
1049     *
1050     * @param group
1051     * DOCUMENT ME!
1052     * @param userStatus
1053     * DOCUMENT ME!
1054     * @param messages
1055     * DOCUMENT ME!
1056     * @param filled
1057     * DOCUMENT ME!
1058     *
1059     * @throws SQLException
1060     * DOCUMENT ME!
1061     */

1062    public void getForums(Group group, int userStatus, boolean filled)
1063            throws SQLException JavaDoc, NumberFormatException JavaDoc, ConfiguratorException {
1064        String JavaDoc queryString = ((userStatus < Integer.parseInt(Configurator
1065                .getInstance().get(IConst.CONFIG.INVADER1))) ? dbDriver
1066                .getQueries().getForumQueries().getSql_GET_FORUMS() : dbDriver
1067                .getQueries().getForumQueries().getSql_GET_ALL_FORUMS());
1068        Connection JavaDoc connection = this.dataSource.getConnection();
1069        PreparedStatement JavaDoc st = connection.prepareStatement(queryString);
1070        PreparedStatement JavaDoc st2 = connection.prepareStatement(dbDriver
1071                .getQueries().getForumQueries().getSql_GET_LAST_MESS());
1072        PreparedStatement JavaDoc st3 = connection.prepareStatement(dbDriver
1073                .getQueries().getForumQueries().getSql_COUNT_THREADS());
1074        ResultSet JavaDoc rs = null;
1075
1076        try {
1077            st.setInt(1, group.getGroupid());
1078            rs = (ResultSet JavaDoc) st.executeQuery();
1079
1080            while (rs.next()) {
1081                Forum forum = new Forum();
1082                forum.setDescription(rs.getString("forumdesc"));
1083                forum.setForumid(rs.getInt("forumid"));
1084                forum.setLocked(rs.getInt("locked"));
1085                forum.setTitle(rs.getString("forumtitle"));
1086
1087                if (filled) {
1088
1089                    forum.setThreadsCount(countForumTopics(forum.getForumid(),
1090                            st3));
1091                    forum.setMessCount(this.countForumMessages(forum
1092                            .getForumid()));
1093                    setLastMessage(forum, st2);
1094                }
1095
1096                group.addForum(forum);
1097            }
1098        } finally {
1099            if (rs != null) {
1100                rs.close();
1101            }
1102
1103            st3.close();
1104            st2.close();
1105            st.close();
1106            connection.close();
1107        }
1108    }
1109
1110    /**
1111     * DOCUMENT ME!
1112     *
1113     * @return
1114     * @throws SQLException
1115     * DOCUMENT ME!
1116     */

1117    public ArrayList JavaDoc getForumsForMod() throws SQLException JavaDoc {
1118        Connection JavaDoc connection = this.dataSource.getConnection();
1119        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1120                .getQueries().getForumQueries().getSql_GET_FORUMS_FOR_MOD());
1121        ResultSet JavaDoc rs = null;
1122        ArrayList JavaDoc forumsForMod = new ArrayList JavaDoc();
1123
1124        try {
1125            rs = st.executeQuery();
1126
1127            int gid = -1;
1128
1129            while (rs.next()) {
1130                if (rs.getInt("gid") != gid) {
1131                    gid = rs.getInt("gid");
1132
1133                    Forum f = new Forum();
1134                    f.setTitle(IConst.JSP.OPTIONS_SEPERATOR);
1135                    forumsForMod.add(f);
1136                }
1137
1138                Forum f = new Forum();
1139                f.setForumid(rs.getInt("fid"));
1140                f.setTitle(rs.getString("forumtitle"));
1141                forumsForMod.add(f);
1142            }
1143        } finally {
1144            if (rs != null) {
1145                rs.close();
1146            }
1147
1148            st.close();
1149            connection.close();
1150        }
1151
1152        return forumsForMod;
1153    }
1154
1155    /**
1156     * DOCUMENT ME!
1157     *
1158     * @param recordsData
1159     *
1160     * @throws InstantiationException
1161     * DOCUMENT ME!
1162     * @throws IllegalAccessException
1163     * DOCUMENT ME!
1164     * @throws InvocationTargetException
1165     * DOCUMENT ME!
1166     * @throws NoSuchMethodException
1167     * DOCUMENT ME!
1168     * @throws SQLException
1169     * DOCUMENT ME!
1170     */

1171    public void getGroupList(RecordsData recordsData)
1172            throws InstantiationException JavaDoc, IllegalAccessException JavaDoc,
1173            InvocationTargetException JavaDoc, NoSuchMethodException JavaDoc, SQLException JavaDoc {
1174        Connection JavaDoc connection = this.dataSource.getConnection();
1175
1176        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1177                .getQueries().getForumQueries().getSql_GET_GROUP_LIST());
1178        ResultSet JavaDoc rs = null;
1179
1180        try {
1181            rs = st.executeQuery();
1182            recordsData.fillRecords(rs, Mapping.getInstance().GroupMapping,
1183                    Group.class);
1184        } finally {
1185            if (rs != null) {
1186                rs.close();
1187            }
1188
1189            st.close();
1190            connection.close();
1191        }
1192    }
1193
1194    /**
1195     * DOCUMENT ME!
1196     *
1197     * @param userStatus
1198     * DOCUMENT ME!
1199     * @param messages
1200     * DOCUMENT ME!
1201     *
1202     * @return DOCUMENT ME!
1203     *
1204     * @throws SQLException
1205     * DOCUMENT ME!
1206     */

1207    public ArrayList JavaDoc getGroups(int userStatus, MessageResources messages)
1208            throws NumberFormatException JavaDoc, SQLException JavaDoc, ConfiguratorException {
1209        return getGroups(userStatus, true);
1210    }
1211
1212    /**
1213     * DOCUMENT ME!
1214     *
1215     * @param userStatus
1216     * DOCUMENT ME!
1217     * @param messages
1218     * DOCUMENT ME!
1219     * @param filled
1220     * DOCUMENT ME!
1221     *
1222     * @return DOCUMENT ME!
1223     *
1224     * @throws SQLException
1225     * DOCUMENT ME!
1226     */

1227    public ArrayList JavaDoc getGroups(int userStatus, boolean filled)
1228            throws NumberFormatException JavaDoc, SQLException JavaDoc, ConfiguratorException {
1229        Connection JavaDoc connection = this.dataSource.getConnection();
1230        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1231                .getQueries().getForumQueries().getSql_GET_GROUPS());
1232        ResultSet JavaDoc rs = null;
1233
1234        try {
1235            ArrayList JavaDoc groups = new ArrayList JavaDoc();
1236            rs = (ResultSet JavaDoc) st.executeQuery();
1237
1238            while (rs.next()) {
1239                Group gr = new Group();
1240                gr.setGroupid(rs.getInt("groupid"));
1241                gr.setName(rs.getString("group_name"));
1242                getForums(gr, userStatus, filled);
1243                groups.add(gr);
1244            }
1245
1246            return groups;
1247        } finally {
1248            if (rs != null) {
1249                rs.close();
1250            }
1251
1252            st.close();
1253            connection.close();
1254        }
1255    }
1256
1257    /**
1258     * Returns java.util.List collection populated with
1259     * org.jresearch.gossip.beans.forum.LastTopic objects.
1260     *
1261     * @param maxCount
1262     * @param since
1263     *
1264     * @return
1265     * @throws SQLException
1266     * @throws IllegalArgumentException
1267     * DOCUMENT ME!
1268     */

1269    public List JavaDoc getLastTopics(int maxCount, Date JavaDoc since) throws SQLException JavaDoc {
1270        if (null == since) {
1271            throw new IllegalArgumentException JavaDoc();
1272        }
1273
1274        java.sql.Date JavaDoc dateSince = new java.sql.Date JavaDoc(since.getTime());
1275        ArrayList JavaDoc topics = new ArrayList JavaDoc();
1276        Connection JavaDoc connection = this.dataSource.getConnection();
1277        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1278                .getQueries().getForumQueries().getSql_GET_LAST_TOPICS());
1279        PreparedStatement JavaDoc st2 = connection.prepareStatement(dbDriver
1280                .getQueries().getForumQueries().getSql_GET_ROOT_MESS());
1281        ResultSet JavaDoc rs = null;
1282
1283        try {
1284            st.setTimestamp(1, new Timestamp JavaDoc(dateSince.getTime()));
1285            st.setInt(2, maxCount);
1286            rs = (ResultSet JavaDoc) st.executeQuery();
1287
1288            while (rs.next()) {
1289                LastTopic topic = new LastTopic();
1290                topic.setForumid(rs.getInt("fid"));
1291                topic.setThreadid(rs.getInt("tid"));
1292                topic.setLocked(rs.getInt("locked"));
1293                topic.setSortby(rs.getInt("sortby"));
1294                topic.setMessagesCount(rs.getLong("tot_mes"));
1295                topic.setForumName(rs.getString("forumtitle"));
1296                setRootMessage(topic, st2);
1297                topics.add(topic);
1298            }
1299        } finally {
1300            if (rs != null) {
1301                try {
1302                    rs.close();
1303                } catch (SQLException JavaDoc e) {
1304                }
1305            }
1306
1307            st2.close();
1308            st.close();
1309            connection.close();
1310        }
1311
1312        return topics;
1313    }
1314
1315    /**
1316     * Returns java.util.List collection populated with
1317     * org.jresearch.gossip.beans.forum.NewTopic objects.
1318     *
1319     * @param fid
1320     * @param maxCount
1321     * @param since
1322     *
1323     * @return DOCUMENT ME!
1324     *
1325     * @throws SQLException
1326     * @throws IllegalArgumentException
1327     * DOCUMENT ME!
1328     */

1329    public List JavaDoc getLastTopics(int fid, int maxCount, Date JavaDoc since)
1330            throws SQLException JavaDoc {
1331        if (null == since) {
1332            throw new IllegalArgumentException JavaDoc();
1333        }
1334
1335        java.sql.Date JavaDoc dateSince = new java.sql.Date JavaDoc(since.getTime());
1336        ArrayList JavaDoc topics = new ArrayList JavaDoc();
1337        Connection JavaDoc connection = this.dataSource.getConnection();
1338        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1339                .getQueries().getForumQueries()
1340                .getSql_GET_LAST_TOPICS_IN_FORUM());
1341        PreparedStatement JavaDoc st2 = connection.prepareStatement(dbDriver
1342                .getQueries().getForumQueries().getSql_GET_ROOT_MESS());
1343        ResultSet JavaDoc rs = null;
1344
1345        try {
1346            st.setInt(1, fid);
1347            st.setTimestamp(2, new Timestamp JavaDoc(dateSince.getTime()));
1348            st.setInt(3, maxCount);
1349            rs = (ResultSet JavaDoc) st.executeQuery();
1350
1351            while (rs.next()) {
1352                LastTopic topic = new LastTopic();
1353                topic.setForumid(rs.getInt("fid"));
1354                topic.setThreadid(rs.getInt("tid"));
1355                topic.setLocked(rs.getInt("locked"));
1356                topic.setMessagesCount(rs.getLong("tot_mes"));
1357                topic.setForumName(rs.getString("forumtitle"));
1358                setRootMessage(topic, st2);
1359                topics.add(topic);
1360            }
1361        } finally {
1362            if (rs != null) {
1363                try {
1364                    rs.close();
1365                } catch (SQLException JavaDoc e) {
1366                }
1367            }
1368
1369            st2.close();
1370            st.close();
1371            connection.close();
1372        }
1373
1374        return topics;
1375    }
1376
1377    /**
1378     * DOCUMENT ME!
1379     *
1380     * @param mid
1381     *
1382     * @return
1383     * @throws SQLException
1384     * DOCUMENT ME!
1385     */

1386    public Message getMessage(String JavaDoc mid) throws SQLException JavaDoc {
1387        Connection JavaDoc connection = this.dataSource.getConnection();
1388        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1389                .getQueries().getForumQueries().getSql_GET_MESSAGE());
1390        Message mess = null;
1391        ResultSet JavaDoc rs = null;
1392
1393        try {
1394            st.setInt(1, Integer.parseInt(mid));
1395            rs = st.executeQuery();
1396
1397            if (rs.next()) {
1398                mess = new Message();
1399                mess.setCentents(rs.getString("centents"));
1400                mess.setHeading(rs.getString("heading"));
1401                mess.setId(rs.getInt("id"));
1402                mess.setIntime(rs.getDate("intime"));
1403                mess.setIp(rs.getString("ip"));
1404                mess.setSender(rs.getString("sender"));
1405            }
1406        } finally {
1407            if (rs != null) {
1408                rs.close();
1409            }
1410
1411            st.close();
1412            connection.close();
1413        }
1414
1415        return mess;
1416    }
1417
1418    /**
1419     * DOCUMENT ME!
1420     *
1421     * @param uid
1422     * DOCUMENT ME!
1423     *
1424     * @return DOCUMENT ME!
1425     *
1426     * @throws SQLException
1427     * DOCUMENT ME!
1428     */

1429    public int getMessCount(String JavaDoc uid) throws SQLException JavaDoc {
1430        Connection JavaDoc connection = this.dataSource.getConnection();
1431        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1432                .getQueries().getForumQueries().getSql_GET_USER_MESS_COUNT());
1433        ResultSet JavaDoc rs = null;
1434        int count = 0;
1435
1436        try {
1437            st.setString(1, uid);
1438            rs = st.executeQuery();
1439
1440            if (rs.next()) {
1441                count = rs.getInt(1);
1442            }
1443        } finally {
1444            if (rs != null) {
1445                rs.close();
1446            }
1447
1448            st.close();
1449            connection.close();
1450        }
1451
1452        return count;
1453    }
1454
1455    /**
1456     * DOCUMENT ME!
1457     *
1458     * @param tid
1459     *
1460     * @return
1461     * @throws SQLException
1462     * DOCUMENT ME!
1463     */

1464    public Topic getThreadInfo(int tid) throws SQLException JavaDoc {
1465        Connection JavaDoc connection = this.dataSource.getConnection();
1466        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1467                .getQueries().getForumQueries().getSql_THREAD_INFO());
1468        ResultSet JavaDoc rs = null;
1469        Topic _thread = new Topic();
1470
1471        try {
1472            st.setInt(1, tid);
1473            rs = (ResultSet JavaDoc) st.executeQuery();
1474
1475            if (rs.next()) {
1476                _thread.setLocked(rs.getInt("locked"));
1477            }
1478            _thread.setSubject(getThreadSubject(Integer.toString(tid)));
1479            return _thread;
1480        } finally {
1481            if (rs != null) {
1482                rs.close();
1483            }
1484
1485            st.close();
1486            connection.close();
1487        }
1488    }
1489
1490    /**
1491     * DOCUMENT ME!
1492     *
1493     * @param tid
1494     *
1495     * @return
1496     * @throws SQLException
1497     * DOCUMENT ME!
1498     */

1499    public String JavaDoc getThreadSubject(String JavaDoc tid) throws SQLException JavaDoc {
1500        Connection JavaDoc connection = this.dataSource.getConnection();
1501        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1502                .getQueries().getForumQueries().getSql_GET_THREAD_SUBJ());
1503        ResultSet JavaDoc rs = null;
1504        String JavaDoc subject = "";
1505
1506        try {
1507            st.setInt(1, Integer.parseInt(tid));
1508            rs = st.executeQuery();
1509
1510            if (rs.next()) {
1511                subject = rs.getString(1);
1512            }
1513        } finally {
1514            if (rs != null) {
1515                rs.close();
1516            }
1517
1518            st.close();
1519            connection.close();
1520        }
1521
1522        return subject;
1523    }
1524
1525    /**
1526     * DOCUMENT ME!
1527     *
1528     * @param login
1529     *
1530     * @return
1531     * @throws SQLException
1532     * DOCUMENT ME!
1533     */

1534    public ArrayList JavaDoc getUserModForums(String JavaDoc login) throws SQLException JavaDoc {
1535        Connection JavaDoc connection = this.dataSource.getConnection();
1536
1537        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1538                .getQueries().getForumQueries().getSql_GET_USER_MOD_FORUMS());
1539        ResultSet JavaDoc rs = null;
1540        ArrayList JavaDoc userModForums = new ArrayList JavaDoc();
1541
1542        try {
1543            st.setString(1, login);
1544            rs = st.executeQuery();
1545
1546            while (rs.next()) {
1547                Forum f = new Forum();
1548                f.setForumid(rs.getInt("forumid"));
1549                f.setTitle(rs.getString("forumtitle"));
1550                userModForums.add(f);
1551            }
1552        } finally {
1553            if (rs != null) {
1554                rs.close();
1555            }
1556
1557            st.close();
1558            connection.close();
1559        }
1560
1561        return userModForums;
1562    }
1563
1564    /**
1565     * DOCUMENT ME!
1566     *
1567     * @param fid
1568     * DOCUMENT ME!
1569     *
1570     * @return
1571     * @throws SQLException
1572     * DOCUMENT ME!
1573     */

1574    public String JavaDoc insertNewThread(String JavaDoc fid) throws SQLException JavaDoc {
1575        Connection JavaDoc connection = this.dataSource.getConnection();
1576        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1577                .getQueries().getForumQueries().getSql_INSERT_THREAD());
1578        try {
1579            int tid = ((Integer JavaDoc) keyGen
1580                    .generateKey(
1581                            IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_THREAD],
1582                            connection)).intValue();
1583            st.setInt(1, Integer.parseInt(fid));
1584            st.setInt(2, tid);
1585            st.execute();
1586            return String.valueOf(tid);
1587        } finally {
1588            st.close();
1589            connection.close();
1590        }
1591    }
1592
1593    /**
1594     * DOCUMENT ME!
1595     *
1596     * @param uid
1597     * DOCUMENT ME!
1598     *
1599     * @return DOCUMENT ME!
1600     *
1601     * @throws SQLException
1602     * DOCUMENT ME!
1603     */

1604    public boolean isUserMod(String JavaDoc uid) throws SQLException JavaDoc {
1605        Connection JavaDoc connection = this.dataSource.getConnection();
1606
1607        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1608                .getQueries().getForumQueries().getSql_IS_USER_MOD());
1609        ResultSet JavaDoc rs = null;
1610        boolean modFlag = false;
1611
1612        try {
1613            st.setString(1, uid);
1614            rs = st.executeQuery();
1615
1616            modFlag = rs.next();
1617        } finally {
1618            if (rs != null) {
1619                rs.close();
1620            }
1621
1622            st.close();
1623            connection.close();
1624        }
1625
1626        return modFlag;
1627    }
1628
1629    /**
1630     * DOCUMENT ME!
1631     *
1632     * @param fid
1633     *
1634     * @throws SQLException
1635     * DOCUMENT ME!
1636     */

1637    public void lockForum(String JavaDoc fid, int locked) throws SQLException JavaDoc {
1638        Connection JavaDoc connection = this.dataSource.getConnection();
1639        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1640                .getQueries().getForumQueries().getSql_GET_FORUM_LOCKED());
1641        ResultSet JavaDoc rs = null;
1642        int id = Integer.parseInt(fid);
1643
1644        try {
1645            st.setInt(1, id);
1646            rs = st.executeQuery();
1647
1648            if (rs.next()) {
1649                st = connection.prepareStatement(dbDriver.getQueries()
1650                        .getForumQueries().getSql_SET_FORUM_LOCKED_STATUS());
1651                st.setInt(1, locked);
1652                st.setInt(2, id);
1653                st.execute();
1654            }
1655        } finally {
1656            if (rs != null) {
1657                rs.close();
1658            }
1659
1660            st.close();
1661            connection.close();
1662        }
1663    }
1664
1665    /**
1666     * DOCUMENT ME!
1667     *
1668     * @param tid
1669     *
1670     * @throws SQLException
1671     * DOCUMENT ME!
1672     */

1673    public void lockThread(String JavaDoc tid) throws SQLException JavaDoc {
1674        Connection JavaDoc connection = this.dataSource.getConnection();
1675        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1676                .getQueries().getForumQueries().getSql_GET_THREAD_LOCKED());
1677        ResultSet JavaDoc rs = null;
1678        int id = Integer.parseInt(tid);
1679
1680        try {
1681            st.setInt(1, id);
1682            rs = st.executeQuery();
1683
1684            if (rs.next() && (rs.getInt(1) < 2)) {
1685                int newStatus = Math.abs(rs.getInt(1) - 1);
1686                st = connection.prepareStatement(dbDriver.getQueries()
1687                        .getForumQueries().getSql_SET_THREAD_LOCKED_STATUS());
1688                st.setInt(1, newStatus);
1689                st.setInt(2, id);
1690                st.execute();
1691            }
1692        } finally {
1693            if (rs != null) {
1694                rs.close();
1695            }
1696
1697            st.close();
1698            connection.close();
1699        }
1700    }
1701
1702    /**
1703     * DOCUMENT ME!
1704     *
1705     * @param tid
1706     * @param nfid
1707     *
1708     * @throws SQLException
1709     * DOCUMENT ME!
1710     */

1711    public void moveThread(String JavaDoc tid, String JavaDoc nfid) throws SQLException JavaDoc {
1712        Connection JavaDoc connection = this.dataSource.getConnection();
1713        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1714                .getQueries().getForumQueries().getSql_MOVE_THREAD());
1715
1716        try {
1717            st.setInt(1, Integer.parseInt(nfid));
1718            st.setInt(2, Integer.parseInt(tid));
1719            st.execute();
1720        } finally {
1721            st.close();
1722            connection.close();
1723        }
1724    }
1725
1726    /**
1727     * DOCUMENT ME!
1728     *
1729     * @param forum
1730     * @param st
1731     * DOCUMENT ME!
1732     *
1733     * @throws SQLException
1734     * DOCUMENT ME!
1735     */

1736    private void setLastMessage(Forum forum, PreparedStatement JavaDoc st)
1737            throws SQLException JavaDoc {
1738        ResultSet JavaDoc rs = null;
1739
1740        try {
1741            st.setInt(1, forum.getForumid());
1742            rs = (ResultSet JavaDoc) st.executeQuery();
1743
1744            Message last = new Message();
1745
1746            if (rs.next()) {
1747                last.setSender(rs.getString("m_from"));
1748                last.setIntime(rs.getTimestamp("t_stamp"));
1749                last.setCentents(rs.getString("cont"));
1750                last.setThreadSort(rs.getInt("sortby"));
1751                last.setId(rs.getInt("id"));
1752                forum.setLastMessThreadId(rs.getInt("tid"));
1753            }
1754
1755            forum.setLastMessage(last);
1756        } finally {
1757            if (rs != null) {
1758                rs.close();
1759            }
1760        }
1761    }
1762
1763    private void setLastMessage(Topic thread, PreparedStatement JavaDoc st)
1764            throws SQLException JavaDoc {
1765        ResultSet JavaDoc rs = null;
1766
1767        try {
1768            st.setInt(1, thread.getThreadid());
1769            rs = (ResultSet JavaDoc) st.executeQuery();
1770
1771            Message last = new Message();
1772
1773            if (rs.next()) {
1774                last.setSender(rs.getString("sender"));
1775                last.setIntime(rs.getTimestamp("intime"));
1776                last.setCentents(rs.getString("centents"));
1777                last.setId(rs.getInt("id"));
1778            }
1779
1780            thread.setLastMessage(last);
1781
1782            // TODO work around bug 863191
1783
thread.setSubject(getThreadSubject(Integer.toString(thread
1784                    .getThreadid())));
1785        } finally {
1786            if (rs != null) {
1787                rs.close();
1788            }
1789        }
1790    }
1791
1792    private void setRootMessage(LastTopic topic, PreparedStatement JavaDoc st)
1793            throws SQLException JavaDoc {
1794        ResultSet JavaDoc rs = null;
1795
1796        try {
1797            st.setInt(1, topic.getThreadid());
1798            rs = (ResultSet JavaDoc) st.executeQuery();
1799
1800            Message root = new Message();
1801
1802            if (rs.next()) {
1803                root.setSender(rs.getString("sender"));
1804                root.setIntime(rs.getTimestamp("t_stamp"));
1805                root.setCentents(rs.getString("centents"));
1806                root.setId(rs.getInt("id"));
1807                root.setHeading(rs.getString("subject"));
1808                root.setIp(rs.getString("ip"));
1809                root.setThreadid(rs.getInt("tid"));
1810                root.setThreadSort(rs.getInt("sortby"));
1811            }
1812
1813            topic.setRootMessage(root);
1814            topic.setSubject(root.getHeading());
1815        } finally {
1816            if (rs != null) {
1817                rs.close();
1818            }
1819        }
1820    }
1821
1822    /**
1823     * DOCUMENT ME!
1824     *
1825     * @param messageForm
1826     *
1827     * @throws SQLException
1828     * DOCUMENT ME!
1829     */

1830    public void updateMessage(MessageForm messageForm) throws SQLException JavaDoc {
1831        Connection JavaDoc connection = this.dataSource.getConnection();
1832        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1833                .getQueries().getForumQueries().getSql_UPDATE_MESSAGE());
1834
1835        try {
1836            st.setString(1, messageForm.getText());
1837            st.setString(2, messageForm.getTitle());
1838            st.setInt(3, Integer.parseInt(messageForm.getMid()));
1839            st.execute();
1840        } finally {
1841            st.close();
1842            connection.close();
1843        }
1844    }
1845
1846    private void updateThreadIntime(String JavaDoc tid, Timestamp JavaDoc intime)
1847            throws SQLException JavaDoc {
1848        Connection JavaDoc connection = this.dataSource.getConnection();
1849        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1850                .getQueries().getForumQueries().getSql_UPDATE_THREAD_LINTIME());
1851
1852        try {
1853            st.setTimestamp(1, intime);
1854            st.setInt(2, Integer.parseInt(tid));
1855            st.execute();
1856        } finally {
1857            st.close();
1858            connection.close();
1859        }
1860    }
1861
1862    /**
1863     * DOCUMENT ME!
1864     *
1865     * @param gid
1866     *
1867     * @return
1868     * @throws SQLException
1869     * DOCUMENT ME!
1870     */

1871    public Group getGroupInfo(String JavaDoc gid) throws SQLException JavaDoc {
1872        Connection JavaDoc connection = this.dataSource.getConnection();
1873        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1874                .getQueries().getForumQueries().getSql_GET_GROUP_INFO());
1875        ResultSet JavaDoc rs = null;
1876        Group group = new Group();
1877
1878        try {
1879            st.setInt(1, Integer.parseInt(gid));
1880            rs = st.executeQuery();
1881
1882            if (rs.next()) {
1883                group.setName(rs.getString("group_name"));
1884                group.setSort(rs.getString("group_sort"));
1885                group.setGroupid(rs.getInt("groupid"));
1886            }
1887        } finally {
1888            if (rs != null) {
1889                rs.close();
1890            }
1891
1892            st.close();
1893            connection.close();
1894        }
1895
1896        return group;
1897    }
1898
1899    /**
1900     * DOCUMENT ME!
1901     *
1902     * @param form
1903     *
1904     * @throws SQLException
1905     * DOCUMENT ME!
1906     */

1907    public void updateGroup(GroupForm form) throws SQLException JavaDoc {
1908        Connection JavaDoc connection = this.dataSource.getConnection();
1909        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1910                .getQueries().getForumQueries().getSql_UPDATE_GROUP());
1911
1912        try {
1913            st.setString(1, form.getGroup_name());
1914            st.setString(2, form.getGroup_sort());
1915            st.setInt(3, Integer.parseInt(form.getGid()));
1916            st.execute();
1917        } finally {
1918            st.close();
1919            connection.close();
1920        }
1921    }
1922
1923    /**
1924     * DOCUMENT ME!
1925     *
1926     * @param form
1927     *
1928     * @throws SQLException
1929     * DOCUMENT ME!
1930     */

1931    public void updateForum(ForumForm form) throws SQLException JavaDoc {
1932        Connection JavaDoc connection = this.dataSource.getConnection();
1933        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
1934                .getQueries().getForumQueries().getSql_UPDATE_FORUM());
1935
1936        try {
1937            st.setString(1, form.getForum_name());
1938            st.setString(2, form.getForum_desc());
1939            st.setInt(3, Integer.parseInt(form.getGroupid()));
1940            st.setString(4, form.getForum_sort());
1941            st.setInt(5, Integer.parseInt(form.getForumid()));
1942            st.execute();
1943        } finally {
1944            st.close();
1945            connection.close();
1946        }
1947    }
1948
1949    /**
1950     * DOCUMENT ME!
1951     *
1952     * @param form
1953     * @param recordsData
1954     * @param showInvisible
1955     *
1956     * @throws InstantiationException
1957     * DOCUMENT ME!
1958     * @throws IllegalAccessException
1959     * DOCUMENT ME!
1960     * @throws InvocationTargetException
1961     * DOCUMENT ME!
1962     * @throws NoSuchMethodException
1963     * DOCUMENT ME!
1964     * @throws SQLException
1965     * DOCUMENT ME!
1966     */

1967    public void processSearch(SearchForm form, RecordsData recordsData,
1968            boolean showInvisible) throws InstantiationException JavaDoc,
1969            IllegalAccessException JavaDoc, InvocationTargetException JavaDoc,
1970            NoSuchMethodException JavaDoc, SQLException JavaDoc {
1971        Connection JavaDoc connection = this.dataSource.getConnection();
1972        StringBuffer JavaDoc queryString = new StringBuffer JavaDoc();
1973
1974        if (showInvisible) {
1975            queryString.append(" WHERE (");
1976        } else {
1977            queryString.append(" WHERE jrf_forum.locked < 3 AND (");
1978        }
1979
1980        String JavaDoc[] fields = { " centents", " heading" };
1981        String JavaDoc searchType = (form.getType());
1982        String JavaDoc search = MySQLCodec.encode(form.getSearch());
1983
1984        if (searchType.equals(IConst.VALUES.WHOLE)) {
1985            queryString.append(fields[0]);
1986            queryString.append(dbDriver.getQueries().getSql_LIKE());
1987            queryString.append("'%");
1988            queryString.append(search);
1989            queryString.append("%'");
1990            queryString.append(dbDriver.getQueries().getSql_OR());
1991            queryString.append(fields[1]);
1992            queryString.append(dbDriver.getQueries().getSql_LIKE());
1993            queryString.append("'%");
1994            queryString.append(search);
1995            queryString.append("%'");
1996        } else {
1997            String JavaDoc term = "";
1998
1999            if (searchType.equals(IConst.VALUES.ALL)) {
2000                term = dbDriver.getQueries().getSql_AND();
2001            } else {
2002                term = dbDriver.getQueries().getSql_OR();
2003            }
2004
2005            for (int i = 0; i < fields.length; i++) {
2006                queryString.append("(");
2007
2008                StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(search, " ");
2009
2010                while (tokens.hasMoreTokens()) {
2011                    String JavaDoc token = tokens.nextToken();
2012                    queryString.append(fields[i]);
2013                    queryString.append(dbDriver.getQueries().getSql_LIKE());
2014                    queryString.append("'%");
2015                    queryString.append(token);
2016                    queryString.append("%'");
2017
2018                    if (tokens.hasMoreTokens()) {
2019                        queryString.append(term);
2020                    }
2021                }
2022
2023                queryString.append(")");
2024
2025                if (i < (fields.length - 1)) {
2026                    queryString.append(dbDriver.getQueries().getSql_OR());
2027                }
2028            }
2029        }
2030
2031        queryString.append(")");
2032        queryString.append(dbDriver.getQueries().getForumQueries()
2033                .getSql_SEARCH_QUERY_END());
2034
2035        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2036                .getQueries().getForumQueries().getSql_SEARCH_QUERY_SUFF()
2037                + queryString.toString());
2038        ResultSet JavaDoc rs = null;
2039
2040        try {
2041            rs = st.executeQuery();
2042            recordsData.fillRecords(rs, Mapping.getInstance().SearchMapping,
2043                    SearchResult.class);
2044            st = connection.prepareStatement(dbDriver.getQueries()
2045                    .getForumQueries().getSql_SEARCH_QUERY_SUFF_COUNT()
2046                    + queryString.toString());
2047            rs = st.executeQuery();
2048
2049            if (rs.next()) {
2050                recordsData.setRecordsCount(rs.getInt(1));
2051            }
2052        } finally {
2053            if (rs != null) {
2054                rs.close();
2055            }
2056
2057            st.close();
2058            connection.close();
2059        }
2060    }
2061
2062    /**
2063     * DOCUMENT ME!
2064     *
2065     * @param tid
2066     * @param i
2067     *
2068     * @throws SQLException
2069     * DOCUMENT ME!
2070     */

2071    public void setThreadSortBy(String JavaDoc tid, int i) throws SQLException JavaDoc {
2072        Connection JavaDoc connection = this.dataSource.getConnection();
2073
2074        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2075                .getQueries().getForumQueries().getSql_SET_THREAD_SORT_BY());
2076
2077        try {
2078            st.setInt(1, i);
2079            st.setInt(2, Integer.parseInt(tid));
2080            st.execute();
2081        } finally {
2082            st.close();
2083            connection.close();
2084        }
2085    }
2086
2087    /**
2088     * DOCUMENT ME!
2089     *
2090     * @param map
2091     *
2092     * @throws SQLException
2093     * DOCUMENT ME!
2094     */

2095    public void updateConstants(Map JavaDoc map) throws SQLException JavaDoc {
2096        Connection JavaDoc connection = this.dataSource.getConnection();
2097        Set JavaDoc keySet = map.keySet();
2098        Iterator JavaDoc it = keySet.iterator();
2099
2100        PreparedStatement JavaDoc st = null;
2101
2102        try {
2103            st = connection.prepareStatement(dbDriver.getQueries()
2104                    .getForumQueries().getSql_UPDATE_CONSTANTS());
2105
2106            while (it.hasNext()) {
2107                String JavaDoc key = (String JavaDoc) it.next();
2108
2109                st.setString(1, (String JavaDoc) map.get(key));
2110                st.setString(2, key);
2111                st.execute();
2112            }
2113        } finally {
2114            if (st != null) {
2115                st.close();
2116            }
2117
2118            connection.close();
2119        }
2120    }
2121
2122    /**
2123     * DOCUMENT ME!
2124     *
2125     * @param tid
2126     * @param uname
2127     * DOCUMENT ME!
2128     *
2129     * @return
2130     * @throws SQLException
2131     * DOCUMENT ME!
2132     */

2133    public ArrayList JavaDoc getSubscribersList(String JavaDoc tid, String JavaDoc uname)
2134            throws SQLException JavaDoc {
2135        ArrayList JavaDoc list = new ArrayList JavaDoc();
2136        Connection JavaDoc connection = this.dataSource.getConnection();
2137        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2138                .getQueries().getForumQueries().getSql_GET_SUBSCRIBERS_LIST());
2139        ResultSet JavaDoc rs = null;
2140
2141        try {
2142            st.setInt(1, Integer.parseInt(tid));
2143            st.setString(2, uname);
2144            rs = st.executeQuery();
2145
2146            while (rs.next()) {
2147                Subscriber s = new Subscriber();
2148                s.setEmail(rs.getString("user_mail"));
2149                s.setName(rs.getString("user_name"));
2150                list.add(s);
2151            }
2152        } finally {
2153            if (rs != null) {
2154                rs.close();
2155            }
2156
2157            st.close();
2158            connection.close();
2159        }
2160
2161        return list;
2162    }
2163
2164    /**
2165     * DOCUMENT ME!
2166     *
2167     * @param tid
2168     * @param email
2169     * @param name
2170     *
2171     * @throws SQLException
2172     * DOCUMENT ME!
2173     */

2174    public void subscribe(String JavaDoc tid, String JavaDoc email, String JavaDoc name)
2175            throws SQLException JavaDoc {
2176        Connection JavaDoc connection = this.dataSource.getConnection();
2177        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2178                .getQueries().getForumQueries().getSql_GET_SUBSCRIPTION());
2179        ResultSet JavaDoc rs = null;
2180
2181        try {
2182            st.setInt(1, Integer.parseInt(tid));
2183            st.setString(2, email);
2184            st.setString(3, name);
2185            rs = st.executeQuery();
2186
2187            if (!rs.next()) {
2188                st = connection.prepareStatement(dbDriver.getQueries()
2189                        .getForumQueries().getSql_ADD_SUBSCRIPTION());
2190                st.setInt(1, Integer.parseInt(tid));
2191                st.setString(2, email);
2192                st.setString(3, name);
2193                st.execute();
2194            }
2195        } finally {
2196            if (rs != null) {
2197                rs.close();
2198            }
2199
2200            st.close();
2201            connection.close();
2202        }
2203    }
2204
2205    /**
2206     * DOCUMENT ME!
2207     *
2208     * @param email
2209     * @param name
2210     * @param tid
2211     *
2212     * @return DOCUMENT ME!
2213     *
2214     * @throws SQLException
2215     * DOCUMENT ME!
2216     */

2217    public boolean unsubscribe(String JavaDoc email, String JavaDoc name, String JavaDoc tid)
2218            throws SQLException JavaDoc {
2219        Connection JavaDoc connection = this.dataSource.getConnection();
2220
2221        PreparedStatement JavaDoc st = null;
2222
2223        if (Integer.parseInt(tid) > 0) {
2224            st = connection.prepareStatement(dbDriver.getQueries()
2225                    .getForumQueries().getSql_GET_SUBSCRIPTION());
2226            st.setInt(1, Integer.parseInt(tid));
2227            st.setString(2, email);
2228            st.setString(3, name);
2229        } else {
2230            st = connection.prepareStatement(dbDriver.getQueries()
2231                    .getForumQueries().getSql_GET_SUBSCRIPTION_ALL());
2232            st.setString(1, email);
2233            st.setString(2, name);
2234        }
2235
2236        ResultSet JavaDoc rs = null;
2237        boolean success = false;
2238
2239        try {
2240            rs = st.executeQuery();
2241
2242            if (rs.next()) {
2243                if (Integer.parseInt(tid) > 0) {
2244                    st = connection.prepareStatement(dbDriver.getQueries()
2245                            .getForumQueries().getSql_DELETE_SUBSCRIPTION());
2246                    st.setInt(1, Integer.parseInt(tid));
2247                    st.setString(2, email);
2248                    st.setString(3, name);
2249                } else {
2250                    st = connection
2251                            .prepareStatement(dbDriver.getQueries()
2252                                    .getForumQueries()
2253                                    .getSql_DELETE_SUBSCRIPTION_ALL());
2254                    st.setString(1, email);
2255                    st.setString(2, name);
2256                }
2257
2258                st.execute();
2259                success = true;
2260            }
2261        } finally {
2262            if (rs != null) {
2263                rs.close();
2264            }
2265
2266            st.close();
2267            connection.close();
2268        }
2269
2270        return success;
2271    }
2272
2273    /**
2274     * DOCUMENT ME!
2275     *
2276     * @param user
2277     * @param recordsData
2278     * @param block
2279     *
2280     * @throws InstantiationException
2281     * DOCUMENT ME!
2282     * @throws IllegalAccessException
2283     * DOCUMENT ME!
2284     * @throws InvocationTargetException
2285     * DOCUMENT ME!
2286     * @throws NoSuchMethodException
2287     * DOCUMENT ME!
2288     * @throws SQLException
2289     * DOCUMENT ME!
2290     */

2291    public void fillSubscriptionList(User user, RecordsData recordsData,
2292            String JavaDoc block) throws InstantiationException JavaDoc,
2293            IllegalAccessException JavaDoc, InvocationTargetException JavaDoc,
2294            NoSuchMethodException JavaDoc, SQLException JavaDoc {
2295        Connection JavaDoc connection = this.dataSource.getConnection();
2296        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2297                .getQueries().getForumQueries().getSql_COUNT_SUBSCRIPTIONS());
2298        ResultSet JavaDoc rs = null;
2299
2300        try {
2301            st.setString(1, user.getName());
2302            rs = (ResultSet JavaDoc) st.executeQuery();
2303
2304            if (rs.next()) {
2305                int blockSize = user.getSettings().getMes_per_page() * 2;
2306                int currBlock = Integer.parseInt(block);
2307
2308                recordsData.setRecordsCount(rs.getInt(1));
2309                recordsData.setBlockSize(blockSize);
2310                recordsData.setCurrBlock(currBlock);
2311                st = connection.prepareStatement(dbDriver.getQueries()
2312                        .getForumQueries().getSql_GET_USER_SUBSCRIPTIONS());
2313                st.setString(1, user.getName());
2314                st.setInt(2, currBlock);
2315                st.setInt(3, dbDriver.getLastRowIdx(currBlock, blockSize));
2316                rs = st.executeQuery();
2317                recordsData.fillRecords(rs,
2318                        Mapping.getInstance().SubscriptionMapping,
2319                        NewTopic.class);
2320            }
2321        } finally {
2322            if (rs != null) {
2323                rs.close();
2324            }
2325
2326            st.close();
2327            connection.close();
2328        }
2329    }
2330
2331    /**
2332     * DOCUMENT ME!
2333     *
2334     * @param period
2335     *
2336     * @return
2337     * @throws SQLException
2338     * DOCUMENT ME!
2339     */

2340    public int[] dropOld(String JavaDoc period) throws SQLException JavaDoc {
2341        Connection JavaDoc connection = this.dataSource.getConnection();
2342        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2343                .getQueries().getForumQueries().getSql_GET_OLD_TOPICS());
2344        ResultSet JavaDoc rs = null;
2345        int[] wasDeleted = new int[2];
2346
2347        try {
2348            st.setInt(1, Integer.parseInt(period));
2349            rs = (ResultSet JavaDoc) st.executeQuery();
2350
2351            while (rs.next()) {
2352                wasDeleted[0]++;
2353                wasDeleted[1] += rs.getInt("cc");
2354                this.deleteThread(rs.getString("threadid"), true);
2355            }
2356        } finally {
2357            if (rs != null) {
2358                rs.close();
2359            }
2360
2361            st.close();
2362            connection.close();
2363        }
2364
2365        return wasDeleted;
2366    }
2367
2368    /**
2369     * DOCUMENT ME!
2370     *
2371     * @param user
2372     * @param recordsData
2373     * @param block
2374     *
2375     * @throws InstantiationException
2376     * DOCUMENT ME!
2377     * @throws IllegalAccessException
2378     * DOCUMENT ME!
2379     * @throws InvocationTargetException
2380     * DOCUMENT ME!
2381     * @throws NoSuchMethodException
2382     * DOCUMENT ME!
2383     * @throws SQLException
2384     * DOCUMENT ME!
2385     */

2386    public void fillLastUpdatedTopicList(User user, RecordsData recordsData,
2387            String JavaDoc block) throws InstantiationException JavaDoc,
2388            IllegalAccessException JavaDoc, InvocationTargetException JavaDoc,
2389            NoSuchMethodException JavaDoc, SQLException JavaDoc {
2390        Connection JavaDoc connection = this.dataSource.getConnection();
2391        PreparedStatement JavaDoc st = null;
2392
2393        if (user.getStatus() < 7) {
2394            st = connection.prepareStatement(dbDriver.getQueries()
2395                    .getForumQueries().getSql_GET_LAST_UPDATED_TOPICS());
2396        } else {
2397            st = connection.prepareStatement(dbDriver.getQueries()
2398                    .getForumQueries().getSql_GET_LAST_UPDATED_TOPICS_ALL());
2399        }
2400
2401        ResultSet JavaDoc rs = null;
2402
2403        try {
2404            int blockSize = user.getSettings().getMes_per_page() * 2;
2405            int currBlock = Integer.parseInt(block);
2406            st.setTimestamp(1, new Timestamp JavaDoc(user.getIntime().getTime()));
2407            st.setInt(2, currBlock);
2408            st.setInt(3, dbDriver.getLastRowIdx(currBlock, blockSize));
2409            rs = (ResultSet JavaDoc) st.executeQuery();
2410            recordsData.fillRecords(rs, Mapping.getInstance().NewTreadMapping,
2411                    NewTopic.class);
2412            recordsData.setBlockSize(blockSize);
2413
2414            recordsData.setCurrBlock(currBlock);
2415            Iterator JavaDoc it = recordsData.getRecords().iterator();
2416            st = connection.prepareStatement(dbDriver.getQueries()
2417                    .getForumQueries().getSql_GET_THREAD_LAST_MESS());
2418
2419            while (it.hasNext()) {
2420                NewTopic nt = (NewTopic) it.next();
2421                setLastMessage(nt, st);
2422                nt.setForumName(getForumInfo(nt.getForumid()).getTitle());
2423            }
2424
2425            if (user.getStatus() < 7) {
2426                st = connection.prepareStatement(dbDriver.getQueries()
2427                        .getForumQueries().getSql_COUNT_NEW_THREADS());
2428            } else {
2429                st = connection.prepareStatement(dbDriver.getQueries()
2430                        .getForumQueries().getSql_COUNT_NEW_THREADS_ALL());
2431            }
2432
2433            st.setTimestamp(1, new Timestamp JavaDoc(user.getIntime().getTime()));
2434            rs = (ResultSet JavaDoc) st.executeQuery();
2435            rs.next();
2436            recordsData.setRecordsCount(rs.getInt(1));
2437        } finally {
2438            if (rs != null) {
2439                rs.close();
2440            }
2441
2442            st.close();
2443            connection.close();
2444        }
2445    }
2446
2447    /**
2448     * DOCUMENT ME!
2449     *
2450     * @param user
2451     * @param form
2452     *
2453     * @return
2454     * @throws SQLException
2455     * DOCUMENT ME!
2456     */

2457    public int getMessBlock(User user, ProcessMessageForm form)
2458            throws SQLException JavaDoc {
2459        int block = 0;
2460        Connection JavaDoc connection = this.dataSource.getConnection();
2461        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2462                .getQueries().getForumQueries().getSql_GET_MESS_INTIME());
2463        ResultSet JavaDoc rs = null;
2464
2465        try {
2466            st.setInt(1, Integer.parseInt(form.getMid()));
2467            rs = st.executeQuery();
2468
2469            int position = 0;
2470            Timestamp JavaDoc intime = null;
2471
2472            if (rs.next()) {
2473                intime = rs.getTimestamp(1);
2474            } else {
2475                return IConst.VALUES.NOT_EXIST;
2476            }
2477
2478            st = connection.prepareStatement(dbDriver.getQueries()
2479                    .getForumQueries().getSql_GET_MESS_POS_BY_INTIME());
2480            st.setInt(1, Integer.parseInt(form.getTid()));
2481            st.setTimestamp(2, intime);
2482            rs = st.executeQuery();
2483
2484            if (rs.next()) {
2485                position = rs.getInt(1);
2486            }
2487            int mpp = user.getSettings().getMes_per_page();
2488            block = (int) (((Math.floor(position / mpp)) * mpp));
2489            block = (block > 0 && (position % mpp == 0)) ? block - mpp : block;
2490        } finally {
2491            if (rs != null) {
2492                rs.close();
2493            }
2494
2495            st.close();
2496            connection.close();
2497        }
2498
2499        return block;
2500    }
2501
2502    /**
2503     * DOCUMENT ME!
2504     *
2505     * @param entrylist
2506     *
2507     * @throws SQLException
2508     * DOCUMENT ME!
2509     */

2510    public void fillEntryList(EntryList entrylist) throws SQLException JavaDoc {
2511        Connection JavaDoc connection = this.dataSource.getConnection();
2512        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2513                .getQueries().getForumQueries().getSql_GET_ENTRY_LIST());
2514        ResultSet JavaDoc rs = null;
2515
2516        try {
2517            rs = st.executeQuery();
2518
2519            while (rs.next()) {
2520                entrylist.put(new Entry(rs.getString("user_name"), rs
2521                        .getString("sessionid"), rs.getString("ip")));
2522            }
2523
2524            st = connection.prepareStatement(dbDriver.getQueries()
2525                    .getForumQueries().getSql_COUNT_ENTRIES());
2526            rs = st.executeQuery();
2527
2528            if (rs.next()) {
2529                entrylist.setTotal(rs.getInt(1));
2530            }
2531        } finally {
2532            if (rs != null) {
2533                rs.close();
2534            }
2535
2536            st.close();
2537            connection.close();
2538        }
2539    }
2540
2541    /**
2542     * DOCUMENT ME!
2543     *
2544     * @param entry
2545     *
2546     * @throws SQLException
2547     * DOCUMENT ME!
2548     */

2549    public void updateEntry(Entry entry) throws SQLException JavaDoc {
2550        Connection JavaDoc connection = this.dataSource.getConnection();
2551        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2552                .getQueries().getForumQueries().getSql_UPDATE_ENTRY());
2553
2554        try {
2555            st.setString(1, entry.getLogin());
2556            st.setString(2, entry.getSessionId());
2557            st.execute();
2558        } finally {
2559            st.close();
2560            connection.close();
2561        }
2562    }
2563
2564    /**
2565     * DOCUMENT ME!
2566     *
2567     * @param entry
2568     *
2569     * @throws SQLException
2570     * DOCUMENT ME!
2571     */

2572    public void addEntry(Entry entry) throws SQLException JavaDoc {
2573        Connection JavaDoc connection = this.dataSource.getConnection();
2574        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2575                .getQueries().getForumQueries().getSql_ADD_ENTRY());
2576
2577        try {
2578            int id = ((Integer JavaDoc) keyGen.generateKey(
2579                    IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_WHOIS], connection))
2580                    .intValue();
2581            ;
2582            st.setString(1, entry.getSessionId());
2583            st.setString(2, entry.getIp());
2584            st.setString(3, entry.getLogin());
2585            st.setInt(4, id);
2586            st.execute();
2587        } finally {
2588            st.close();
2589            connection.close();
2590        }
2591    }
2592
2593    /**
2594     * DOCUMENT ME!
2595     *
2596     * @param string
2597     *
2598     * @throws SQLException
2599     * DOCUMENT ME!
2600     */

2601    public void removeEntry(String JavaDoc string) throws SQLException JavaDoc {
2602        Connection JavaDoc connection = this.dataSource.getConnection();
2603        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2604                .getQueries().getForumQueries().getSql_DELETE_ENTRY());
2605
2606        try {
2607            st.setString(1, string);
2608            st.setString(2, string);
2609            st.execute();
2610        } finally {
2611            st.close();
2612            connection.close();
2613        }
2614    }
2615
2616    /**
2617     * DOCUMENT ME!
2618     *
2619     * @param string
2620     *
2621     * @return
2622     * @throws SQLException
2623     * DOCUMENT ME!
2624     */

2625    public boolean isEntryExist(String JavaDoc string) throws SQLException JavaDoc {
2626        Connection JavaDoc connection = this.dataSource.getConnection();
2627        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2628                .getQueries().getForumQueries().getSql_CHECK_ENTRY());
2629        ResultSet JavaDoc rs = null;
2630        boolean exist = false;
2631
2632        try {
2633            st.setString(1, string);
2634            rs = rs = st.executeQuery();
2635            exist = rs.next();
2636        } finally {
2637            if (null != rs) {
2638                rs.close();
2639            }
2640
2641            st.close();
2642            connection.close();
2643        }
2644
2645        return exist;
2646    }
2647
2648    /**
2649     * DOCUMENT ME!
2650     *
2651     * @return
2652     * @throws SQLException
2653     * DOCUMENT ME!
2654     */

2655    public ArrayList JavaDoc getEntryList() throws SQLException JavaDoc {
2656        Connection JavaDoc connection = this.dataSource.getConnection();
2657        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2658                .getQueries().getForumQueries().getSql_GET_ENTRY_LIST_FULL());
2659        ResultSet JavaDoc rs = null;
2660        ArrayList JavaDoc list = new ArrayList JavaDoc();
2661
2662        try {
2663            rs = st.executeQuery();
2664
2665            while (rs.next()) {
2666                list.add(new Entry(rs.getString("user_name"), rs
2667                        .getString("sessionid"), rs.getString("ip")));
2668            }
2669        } finally {
2670            if (rs != null) {
2671                rs.close();
2672            }
2673
2674            st.close();
2675            connection.close();
2676        }
2677
2678        return list;
2679    }
2680
2681    /**
2682     * DOCUMENT ME!
2683     *
2684     * @param id
2685     * @param SkinParams
2686     *
2687     * @throws SQLException
2688     * DOCUMENT ME!
2689     */

2690    public void loadSkinParams(int id, HashMap JavaDoc SkinParams) throws SQLException JavaDoc {
2691        Connection JavaDoc connection = this.dataSource.getConnection();
2692        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2693                .getQueries().getForumQueries().getSql_GET_SKIN_PARAMS());
2694        ResultSet JavaDoc rs = null;
2695
2696        try {
2697            st.setInt(1, id);
2698            rs = st.executeQuery();
2699
2700            while (rs.next()) {
2701                SkinParams.put(rs.getString("param_name"), rs
2702                        .getString("param_value"));
2703            }
2704        } finally {
2705            if (rs != null) {
2706                rs.close();
2707            }
2708
2709            st.close();
2710            connection.close();
2711        }
2712    }
2713
2714    /**
2715     * DOCUMENT ME!
2716     *
2717     * @param form
2718     *
2719     * @throws SQLException
2720     * DOCUMENT ME!
2721     */

2722    public void updateStyles(StylesForm form) throws SQLException JavaDoc {
2723        Connection JavaDoc connection = this.dataSource.getConnection();
2724        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2725                .getQueries().getForumQueries().getSql_UPDATE_SKIN_PARAM());
2726        Set JavaDoc keys = form.getKeys();
2727
2728        try {
2729            Iterator JavaDoc it = keys.iterator();
2730
2731            while (it.hasNext()) {
2732                String JavaDoc key = (String JavaDoc) it.next();
2733                st.setInt(3, Integer.parseInt(form.getSkinid()));
2734                st.setString(2, key);
2735                st.setString(1, (String JavaDoc) form.getValue(key));
2736                st.executeUpdate();
2737            }
2738        } finally {
2739            st.close();
2740            connection.close();
2741        }
2742    }
2743
2744    /**
2745     * Return List contain UpdatedTopics ids (as String ) for all forums.
2746     *
2747     * @param user
2748     * @return List of (String) id
2749     */

2750    public List JavaDoc getUpdatedTopics(User user) throws SQLException JavaDoc {
2751        if (null == user) {
2752            throw new IllegalArgumentException JavaDoc();
2753        }
2754
2755        ArrayList JavaDoc topics = new ArrayList JavaDoc();
2756        Connection JavaDoc connection = this.dataSource.getConnection();
2757        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2758                .getQueries().getForumQueries().getSql_GET_UPDATED_TOPICS());
2759        ResultSet JavaDoc rs = null;
2760
2761        try {
2762            st.setString(1, user.getName());
2763            rs = (ResultSet JavaDoc) st.executeQuery();
2764
2765            while (rs.next()) {
2766                topics.add(rs.getString("tid"));
2767            }
2768        } finally {
2769            if (rs != null) {
2770                try {
2771                    rs.close();
2772                } catch (SQLException JavaDoc e) {
2773                }
2774            }
2775
2776            st.close();
2777            connection.close();
2778        }
2779
2780        return topics;
2781    }
2782
2783    /**
2784     * Return List contain UpdatedTopics ids (as String ) for specified forum.
2785     *
2786     * @param user
2787     * @param fid
2788     * @return
2789     */

2790    public List JavaDoc getUpdatedTopics(User user, int fid) throws SQLException JavaDoc {
2791        if (null == user) {
2792            throw new IllegalArgumentException JavaDoc();
2793        }
2794
2795        ArrayList JavaDoc topics = new ArrayList JavaDoc();
2796        Connection JavaDoc connection = this.dataSource.getConnection();
2797        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2798                .getQueries().getForumQueries()
2799                .getSql_GET_UPDATED_TOPICS_IN_FORUM());
2800        ResultSet JavaDoc rs = null;
2801
2802        try {
2803            st.setString(1, user.getName());
2804            st.setInt(2, fid);
2805            rs = (ResultSet JavaDoc) st.executeQuery();
2806
2807            while (rs.next()) {
2808                topics.add(rs.getString("tid"));
2809            }
2810        } finally {
2811            if (rs != null) {
2812                try {
2813                    rs.close();
2814                } catch (SQLException JavaDoc e) {
2815                }
2816            }
2817
2818            st.close();
2819            connection.close();
2820        }
2821
2822        return topics;
2823    }
2824
2825    /**
2826     * retrive attachment info bean
2827     *
2828     * @param id
2829     */

2830    public FileDataInfo getAttachmentInfo(int id) throws SQLException JavaDoc {
2831        Connection JavaDoc connection = this.dataSource.getConnection();
2832        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2833                .getQueries().getForumQueries().getSql_GET_ATTACH_INFO());
2834        ResultSet JavaDoc rs = null;
2835        FileDataInfo fileData = new FileDataInfo();
2836
2837        try {
2838            st.setInt(1, id);
2839            rs = (ResultSet JavaDoc) st.executeQuery();
2840
2841            if (rs.next()) {
2842                fileData.setId(rs.getInt("id"));
2843                fileData.setName(rs.getString("attach_name"));
2844                fileData.setContentType(rs.getString("attach_content_type"));
2845                fileData.setDescription(rs.getString("attach_description"));
2846                fileData.setMessageId(rs.getInt("message_id"));
2847                fileData.setSize(rs.getInt("attach_size"));
2848            }
2849
2850            return fileData;
2851        } finally {
2852            if (rs != null) {
2853                rs.close();
2854            }
2855
2856            st.close();
2857            connection.close();
2858        }
2859
2860    }
2861
2862    /**
2863     * @return
2864     */

2865    public List JavaDoc getRankList() throws SQLException JavaDoc {
2866        ArrayList JavaDoc ranks = new ArrayList JavaDoc();
2867        Connection JavaDoc connection = this.dataSource.getConnection();
2868        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2869                .getQueries().getForumQueries().getSql_GET_RANKS());
2870        ResultSet JavaDoc rs = null;
2871
2872        try {
2873            rs = (ResultSet JavaDoc) st.executeQuery();
2874
2875            while (rs.next()) {
2876                ranks.add(new RankInfoDTO(rs.getInt("id"), rs
2877                        .getString("rank_name"), rs.getInt("rank_count")));
2878            }
2879        } finally {
2880            if (rs != null) {
2881                try {
2882                    rs.close();
2883                } catch (SQLException JavaDoc e) {
2884                }
2885            }
2886
2887            st.close();
2888            connection.close();
2889        }
2890
2891        return ranks;
2892    }
2893
2894    /**
2895     *
2896     */

2897    public void removeRank(int id) throws SQLException JavaDoc {
2898        Connection JavaDoc connection = this.dataSource.getConnection();
2899        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2900                .getQueries().getForumQueries().getSql_REMOVE_RANK());
2901
2902        try {
2903            st.setInt(1, id);
2904            st.execute();
2905
2906        } finally {
2907            st.close();
2908            connection.close();
2909        }
2910    }
2911
2912    /**
2913     * @param i
2914     * @return
2915     */

2916    public RankInfoDTO getRankInfo(int id) throws SQLException JavaDoc {
2917        RankInfoDTO rank = null;
2918        Connection JavaDoc connection = this.dataSource.getConnection();
2919        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2920                .getQueries().getForumQueries().getSql_GET_RANK());
2921        ResultSet JavaDoc rs = null;
2922
2923        try {
2924            rs = (ResultSet JavaDoc) st.executeQuery();
2925
2926            if (rs.next()) {
2927                rank = new RankInfoDTO(rs.getInt("id"), rs
2928                        .getString("rank_name"), rs.getInt("rank_count"));
2929            }
2930        } finally {
2931            if (rs != null) {
2932                try {
2933                    rs.close();
2934                } catch (SQLException JavaDoc e) {
2935                }
2936            }
2937            st.close();
2938            connection.close();
2939        }
2940
2941        return rank;
2942    }
2943
2944    /**
2945     * @param rank
2946     */

2947    public void addRank(RankInfoDTO rank) throws SQLException JavaDoc {
2948        if (null == rank) {
2949            throw new IllegalArgumentException JavaDoc("rank can't have null value");
2950        }
2951        Connection JavaDoc connection = this.dataSource.getConnection();
2952        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2953                .getQueries().getForumQueries().getSql_ADD_RANK());
2954
2955        try {
2956            int id = ((Integer JavaDoc) keyGen.generateKey(
2957                    IKeyGenConst.KEY_NAMES[IKeyGenConst.KEY_RANK], connection))
2958                    .intValue();
2959            st.setInt(1, id);
2960            st.setInt(2, rank.getCount());
2961            st.setString(3, rank.getName());
2962            st.execute();
2963
2964        } finally {
2965            st.close();
2966            connection.close();
2967        }
2968
2969    }
2970
2971    /**
2972     * @param rank
2973     */

2974    public void updateRank(RankInfoDTO rank) throws SQLException JavaDoc {
2975        if (null == rank) {
2976            throw new IllegalArgumentException JavaDoc("rank can't have null value");
2977        }
2978        Connection JavaDoc connection = this.dataSource.getConnection();
2979        PreparedStatement JavaDoc st = connection.prepareStatement(dbDriver
2980                .getQueries().getForumQueries().getSql_UPDATE_RANK());
2981
2982        try {
2983            st.setInt(3, rank.getId());
2984            st.setInt(1, rank.getCount());
2985            st.setString(2, rank.getName());
2986            st.execute();
2987
2988        } finally {
2989            st.close();
2990            connection.close();
2991        }
2992
2993    }
2994
2995    /**
2996     * @param user
2997     * @param data
2998     * @throws SystemException
2999     */

3000    public void saveAvatar(User user, byte[] data) throws SystemException {
3001        IFileProcessor fProc = getFileProcessor(IFileProcConst.AVATAR_PROCESSOR);
3002        fProc.saveFileData(data, IFileProcConst.AVATAR_KEY_PREFIX
3003                + user.getName());
3004    }
3005
3006    /**
3007     * @param uid
3008     * @return
3009     * @throws SystemException
3010     */

3011    public byte[] getAvatar(String JavaDoc uid) throws SystemException {
3012        IFileProcessor fProc = getFileProcessor(IFileProcConst.AVATAR_PROCESSOR);
3013        byte[] data = fProc.getFileData(IFileProcConst.AVATAR_KEY_PREFIX + uid);
3014        if (data == null) {
3015            data = IConst.VALUES.BLANK_GIF;
3016        }
3017        return data;
3018    }
3019
3020    /**
3021     * @param uid
3022     * @throws SystemException
3023     */

3024    public void removeAvatar(String JavaDoc uid) throws SystemException {
3025        IFileProcessor fProc = getFileProcessor(IFileProcConst.AVATAR_PROCESSOR);
3026        fProc.removeFileData(IFileProcConst.AVATAR_KEY_PREFIX + uid);
3027    }
3028}
Popular Tags