KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > dao > generic > GenericModerationDAO


1 /*
2  * Copyright (c) Rafael Steil
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms,
6  * with or without modification, are permitted provided
7  * that the following conditions are met:
8  *
9  * 1) Redistributions of source code must retain the above
10  * copyright notice, this list of conditions and the
11  * following disclaimer.
12  * 2) Redistributions in binary form must reproduce the
13  * above copyright notice, this list of conditions and
14  * the following disclaimer in the documentation and/or
15  * other materials provided with the distribution.
16  * 3) Neither the name of "Rafael Steil" nor
17  * the names of its contributors may be used to endorse
18  * or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
34  * IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
38  *
39  * Created on Jan 30, 2005 11:38:30 AM
40  * The JForum Project
41  * http://www.jforum.net
42  */

43 package net.jforum.dao.generic;
44
45 import java.sql.PreparedStatement JavaDoc;
46 import java.sql.ResultSet JavaDoc;
47 import java.sql.Statement JavaDoc;
48 import java.sql.Timestamp JavaDoc;
49 import java.util.ArrayList JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Map JavaDoc;
53
54 import net.jforum.JForumExecutionContext;
55 import net.jforum.dao.ModerationDAO;
56 import net.jforum.entities.ModerationPendingInfo;
57 import net.jforum.entities.Post;
58 import net.jforum.entities.TopicModerationInfo;
59 import net.jforum.util.preferences.SystemGlobals;
60
61 /**
62  * @author Rafael Steil
63  * @version $Id: GenericModerationDAO.java,v 1.5 2006/01/29 15:06:21 rafaelsteil Exp $
64  */

65 public class GenericModerationDAO implements ModerationDAO
66 {
67     /**
68      * @see net.jforum.dao.ModerationDAO#aprovePost(int)
69      */

70     public void aprovePost(int postId) throws Exception JavaDoc
71     {
72         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(
73                 SystemGlobals.getSql("ModerationModel.aprovePost"));
74         p.setTimestamp(1, new Timestamp JavaDoc(System.currentTimeMillis()));
75         p.setInt(2, postId);
76         p.executeUpdate();
77         p.close();
78     }
79     
80     /**
81      * @see net.jforum.dao.ModerationDAO#topicsByForum(int)
82      */

83     public Map JavaDoc topicsByForum(int forumId) throws Exception JavaDoc
84     {
85         Map JavaDoc m = new HashMap JavaDoc();
86         
87         PreparedStatement JavaDoc p = JForumExecutionContext.getConnection().prepareStatement(
88                 SystemGlobals.getSql("ModerationModel.topicsByForum"));
89         p.setInt(1, forumId);
90         
91         int lastId = 0;
92         TopicModerationInfo info = null;
93         
94         ResultSet JavaDoc rs = p.executeQuery();
95         while (rs.next()) {
96             int id = rs.getInt("topic_id");
97             if (id != lastId) {
98                 lastId = id;
99                 
100                 if (info != null) {
101                     m.put(new Integer JavaDoc(info.getTopicId()), info);
102                 }
103                 
104                 info = new TopicModerationInfo();
105                 info.setTopicId(id);
106                 info.setTopicReplies(rs.getInt("topic_replies"));
107                 info.setTopicTitle(rs.getString("topic_title"));
108             }
109             
110             info.addPost(this.getPost(rs));
111         }
112         
113         if (info != null) {
114             m.put(new Integer JavaDoc(info.getTopicId()), info);
115         }
116         
117         rs.close();
118         p.close();
119         
120         return m;
121     }
122     
123     protected Post getPost(ResultSet JavaDoc rs) throws Exception JavaDoc
124     {
125         Post p = new Post();
126         p.setPostUsername(rs.getString("username"));
127         p.setId(rs.getInt("post_id"));
128         p.setUserId(rs.getInt("user_id"));
129         p.setBbCodeEnabled(rs.getInt("enable_bbcode") == 1);
130         p.setHtmlEnabled(rs.getInt("enable_html") == 1);
131         p.setSmiliesEnabled(rs.getInt("enable_smilies") == 1);
132         p.setSubject(rs.getString("post_subject"));
133         p.setText(this.getPostTextFromResultSet(rs));
134         
135         return p;
136     }
137     
138     protected String JavaDoc getPostTextFromResultSet(ResultSet JavaDoc rs) throws Exception JavaDoc
139     {
140         return rs.getString("post_text");
141     }
142     
143     /**
144      * @see net.jforum.dao.ModerationDAO#categoryPendingModeration()
145      */

146     public List JavaDoc categoryPendingModeration() throws Exception JavaDoc
147     {
148         List JavaDoc l = new ArrayList JavaDoc();
149         int lastId = 0;
150         ModerationPendingInfo info = null;
151         Statement JavaDoc s = JForumExecutionContext.getConnection().createStatement();
152         
153         ResultSet JavaDoc rs = s.executeQuery(SystemGlobals.getSql("ModerationModel.categoryPendingModeration"));
154         while (rs.next()) {
155             int id = rs.getInt("categories_id");
156             if (id != lastId) {
157                 lastId = id;
158                 
159                 if (info != null) {
160                     l.add(info);
161                 }
162                 
163                 info = new ModerationPendingInfo();
164                 info.setCategoryName(rs.getString("title"));
165                 info.setCategoryId(id);
166             }
167             
168             info.addInfo(rs.getString("forum_name"),
169                     rs.getInt("forum_id"),
170                     rs.getInt("total"));
171         }
172         
173         if (info != null) {
174             l.add(info);
175         }
176         
177         rs.close();
178         s.close();
179         
180         return l;
181     }
182     
183 }
184
Popular Tags