001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creating date: Feb 23, 2003 / 2:56:58 PM
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.dao;
044:
045: import java.util.Collection;
046: import java.util.List;
047: import java.util.Map;
048:
049: import net.jforum.entities.Topic;
050: import net.jforum.entities.User;
051: import net.jforum.search.SearchArgs;
052: import net.jforum.search.SearchResult;
053:
054: /**
055: * Model interface for {@link net.jforum.entities.Topic}.
056: * This interface defines methods which are expected to be
057: * implementd by a specific data access driver. The intention is
058: * to provide all functionality needed to update, insert, delete and
059: * select some specific data.
060: *
061: * @author Rafael Steil
062: * @version $Id: TopicDAO.java,v 1.18 2007/09/09 22:53:36 rafaelsteil Exp $
063: */
064: public interface TopicDAO {
065: /**
066: * Fixes the fields <i>topic_first_post_id</i> and
067: * <i>topic_last_post_id</i>.
068: *
069: * @param topicId The topic id to fix
070: */
071: public void fixFirstLastPostId(int topicId);
072:
073: /**
074: * Gets a specific <code>Topic</code>.
075: *
076: * @param topicId The Topic ID to search
077: * @return <code>Topic</code>object containing all the information
078: * @see #selectAllByForum(int forumId)
079: */
080: public Topic selectById(int topicId);
081:
082: /**
083: * Gets a topic's information from the topics table only.
084: * No other information, like usernames, are fetched.
085: *
086: * @param topicId The topic id to get
087: * @return A topic instance
088: */
089: public Topic selectRaw(int topicId);
090:
091: /**
092: * Selects all topics associated to a specific forum
093: *
094: * @param forumId The forum id to select the topics
095: * @return <code>ArrayList</code> with all topics found. Each entry is a <code>net.jforum.Topic</code> object
096: */
097: public List selectAllByForum(int forumId);
098:
099: public List selectTopicTitlesByIds(Collection idList);
100:
101: /**
102: * Selects all topics associated to a specific forum, limiting the total number
103: * of records returned.
104: *
105: * @param forumId The forum id to select the topics
106: * @return <code>ArrayList</code> with all topics found. Each entry is a <code>net.jforum.Topic</code> object
107: * @param startFrom int
108: * @param count int
109: */
110: public List selectAllByForumByLimit(int forumId, int startFrom,
111: int count);
112:
113: /**
114: * Selects all topics associated to a specific user and belonging to
115: * given forums
116: * @param userId int User ID.
117: * @param startFrom int
118: * @param count int
119: * @return List
120: */
121: public List selectByUserByLimit(int userId, int startFrom, int count);
122:
123: /**
124: * How many topics were created by a given user
125: * @param userId the user id to check
126: * @return the number of topics created by the user
127: */
128: public int countUserTopics(int userId);
129:
130: /**
131: * Delete a Topic.
132: *
133: * @param topic The Topic ID to delete
134: * @param fromModeration boolean
135: */
136: public void delete(Topic topic, boolean fromModeration);
137:
138: /**
139: * Deletes a set of topics
140: * @param topics The topics to delete. Each entry must be
141: * an instance of net.jforum.entities.Topic
142: * @param fromModeration boolean
143: */
144: public void deleteTopics(List topics, boolean fromModeration);
145:
146: /**
147: * Deletes all topics from a forum
148: * @param forumId int
149: */
150: public void deleteByForum(int forumId);
151:
152: /**
153: * Updates a Topic.
154: *
155: * @param topic Reference to a <code>Topic</code> object to update
156: */
157: public void update(Topic topic);
158:
159: /**
160: * Adds a new Topic.
161: *
162: * @param topic Reference to a valid and configured <code>Topic</code> object
163: * @return The new ID
164: */
165: public int addNew(Topic topic);
166:
167: /**
168: * Increments the number of times the topic was saw
169: *
170: * @param topicId The topic ID to increment the total number of views
171: */
172: public void incrementTotalViews(int topicId);
173:
174: /**
175: * Increments the number of replies the topic has
176: *
177: * @param topicId The topic ID to increment the total number of replies
178: */
179: public void incrementTotalReplies(int topicId);
180:
181: /**
182: * Decrements the number of replies the topic has
183: *
184: * @param topicId The topic ID to decrement the total number of replies
185: */
186: public void decrementTotalReplies(int topicId);
187:
188: /**
189: * Sets the ID of the last post of the topic
190: *
191: * @param topicId Topic ID
192: * @param postId Post ID
193: */
194: public void setLastPostId(int topicId, int postId);
195:
196: /**
197: * Gets the last post id associated to the topic
198: *
199: * @param topicId The topic id
200: * @return int
201: */
202: public int getMaxPostId(int topicId);
203:
204: /**
205: * Gets the number of posts the topic has.
206: *
207: * @param topicId The topic id
208: * @return The number of posts
209: */
210: public int getTotalPosts(int topicId);
211:
212: /**
213: * Get the users to notify
214: *
215: * @param topic The topic
216: * @return <code>ArrayList</code> of <code>User</code> objects. Each
217: * entry is an user who will receive the topic anwser notification
218: * */
219: public List notifyUsers(Topic topic);
220:
221: /**
222: * Subscribe a set of users for notification of new post in the topic
223: * @param topicId the topic id
224: * @param users the relation of {@link User} instances to subscribe
225: */
226: public void subscribeUsers(int topicId, List users);
227:
228: /**
229: * Subscribe the user for notification of new post in the topic
230: *
231: * @param topicId The topic id
232: * @param userId The user id
233: */
234: public void subscribeUser(int topicId, int userId);
235:
236: /**
237: * Return the subscrition status of the user on the topic.
238: *
239: * @param topicId The topic id
240: * @param userId The user id
241: * @return true if the user is waiting notification on the topic
242: */
243: public boolean isUserSubscribed(int topicId, int userId);
244:
245: /**
246: * Remove the user's subscription of the topic
247: *
248: * @param topicId The topic id
249: * @param userId the User id
250: */
251: public void removeSubscription(int topicId, int userId);
252:
253: /**
254: * Clean all subscriptions of some topic
255: *
256: * @param topicId The topic id
257: */
258: public void removeSubscriptionByTopic(int topicId);
259:
260: /**
261: * Change the topic read status
262: *
263: * @param topicId The topic id
264: * @param userId The user id
265: * @param read <code>true</code> or <code>false</code>
266: */
267: public void updateReadStatus(int topicId, int userId, boolean read);
268:
269: /**
270: * Lock or unlock a topic.
271: *
272: * @param topicId The topic id to perform the action on
273: * @param status Use <code>Topic.STATUS_LOCKED</code> to lock the topic, or
274: * <code>Topic.STATUS_UNLOCKED</code> to unlock.
275: */
276: public void lockUnlock(int[] topicId, int status);
277:
278: /**
279: * Selects recent topics
280: *
281: * @param limit The number of topics to retrieve
282: * @return List
283: */
284: public List selectRecentTopics(int limit);
285:
286: /**
287: * Selects hottest topics
288: *
289: * @param limit The number of topics to retrieve
290: * @return List
291: */
292: public List selectHottestTopics(int limit);
293:
294: /**
295: * Sets the ID of the first post of the topic
296: *
297: * @param topicId Topic ID
298: * @param postId Post ID
299: */
300: public void setFirstPostId(int topicId, int postId);
301:
302: /**
303: * Gets the first post id associated to the topic
304: *
305: * @param topicId The topic id
306: * @return int
307: */
308: public int getMinPostId(int topicId);
309:
310: /**
311: * Sets the moderatation flag for all topics of a given forum.
312: *
313: * @param forumId The forum id
314: * @param status boolean
315: */
316: public void setModerationStatus(int forumId, boolean status);
317:
318: /**
319: * Sets the moderatation flag for a given topic.
320: *
321: * @param topicId The topic id
322: * @param status boolean
323: */
324: public void setModerationStatusByTopic(int topicId, boolean status);
325:
326: /**
327: * Get all unique posters of some topic
328: * @param topicId int
329: * @return A Map instance with all topic posts. Key is the userid,
330: * value is an {@link net.jforum.entities.User} instance with minimum
331: * data filled
332: */
333: public Map topicPosters(int topicId);
334:
335: /**
336: * @param args
337: * @return
338: */
339: public SearchResult findTopicsByDateRange(SearchArgs args);
340: }
|