TopicDAO.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 9k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  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.  * This file creating date: Feb 23, 2003 / 2:56:58 PM
  40.  * The JForum Project
  41.  * http://www.jforum.net
  42.  */
  43. package net.jforum.dao;
  44. import java.util.Collection;
  45. import java.util.List;
  46. import java.util.Map;
  47. import net.jforum.entities.Topic;
  48. import net.jforum.entities.User;
  49. import net.jforum.search.SearchArgs;
  50. import net.jforum.search.SearchResult;
  51. /**
  52. * Model interface for {@link net.jforum.entities.Topic}.
  53.  * This interface defines methods which are expected to be
  54.  * implementd by a specific data access driver. The intention is
  55.  * to provide all functionality needed to update, insert, delete and
  56.  * select some specific data.
  57.  *
  58.  * @author Rafael Steil
  59.  * @version $Id: TopicDAO.java,v 1.18 2007/09/09 22:53:36 rafaelsteil Exp $
  60.  */
  61. public interface TopicDAO 
  62. {
  63. /**
  64.  * Fixes the fields <i>topic_first_post_id</i> and 
  65.  * <i>topic_last_post_id</i>.
  66.  * 
  67.  * @param topicId The topic id to fix
  68.  */
  69. public void fixFirstLastPostId(int topicId) ;
  70. /**
  71.  * Gets a specific <code>Topic</code>.
  72.  * 
  73.  * @param topicId The Topic ID to search
  74.  * @return <code>Topic</code>object containing all the information
  75.  * @see #selectAllByForum(int forumId)
  76.  */
  77. public Topic selectById(int topicId) ;
  78. /**
  79.  * Gets a topic's information from the topics table only.
  80.  * No other information, like usernames, are fetched. 
  81.  * 
  82.  * @param topicId The topic id to get
  83.  * @return A topic instance
  84.  */
  85. public Topic selectRaw(int topicId) ;
  86. /**
  87.  * Selects all topics associated to a specific forum
  88.  * 
  89.  * @param forumId The forum id to select the topics
  90.  * @return <code>ArrayList</code> with all topics found. Each entry is a <code>net.jforum.Topic</code> object
  91.  */
  92. public List selectAllByForum(int forumId) ;
  93. public List selectTopicTitlesByIds(Collection idList) ;
  94. /**
  95.  * Selects all topics associated to a specific forum, limiting the total number
  96.  * of records returned.
  97.  * 
  98.  * @param forumId The forum id to select the topics
  99.  * @return <code>ArrayList</code> with all topics found. Each entry is a <code>net.jforum.Topic</code> object
  100.      * @param startFrom int
  101.      * @param count int
  102.  */
  103. public List selectAllByForumByLimit(int forumId, int startFrom, int count) ;
  104.     /**
  105.      * Selects all topics associated to a specific user and belonging to
  106.      * given forums
  107.      * @param userId int User ID.
  108.      * @param startFrom int
  109.      * @param count int
  110.      * @return  List
  111.      */
  112. public List selectByUserByLimit(int userId,int startFrom, int count) ;
  113. /**
  114.  * How many topics were created by a given user
  115.  * @param userId the user id to check
  116.  * @return the number of topics created by the user
  117.  */
  118. public int countUserTopics(int userId) ;
  119. /**
  120.  * Delete a Topic.
  121.  * 
  122.  * @param topic The Topic ID to delete
  123.  * @param fromModeration boolean
  124.  */
  125. public void delete(Topic topic, boolean fromModeration) ;
  126. /**
  127.  * Deletes a set of topics
  128.  * @param topics The topics to delete. Each entry must be
  129.  * an instance of net.jforum.entities.Topic
  130.  * @param fromModeration boolean
  131.  */
  132. public void deleteTopics(List topics, boolean fromModeration) ;
  133. /**
  134.  * Deletes all topics from a forum
  135.  * @param forumId int
  136.  */
  137. public void deleteByForum(int forumId) ;
  138. /**
  139.  * Updates a Topic.
  140.  * 
  141.  * @param topic Reference to a <code>Topic</code> object to update
  142.  */
  143. public void update(Topic topic) ;
  144. /**
  145.  * Adds a new Topic.
  146.  * 
  147.  * @param topic Reference to a valid and configured <code>Topic</code> object
  148.  * @return The new ID
  149.  */
  150. public int addNew(Topic topic) ;
  151. /**
  152.  * Increments the number of times the topic was saw
  153.  * 
  154.  * @param topicId The topic ID to increment the total number of views
  155.  */
  156. public void incrementTotalViews(int topicId) ;
  157. /**
  158.  * Increments the number of replies the topic has
  159.  * 
  160.  * @param topicId The topic ID to increment the total number of replies
  161.  */
  162. public void incrementTotalReplies(int topicId) ;
  163. /**
  164.  * Decrements the number of replies the topic has
  165.  * 
  166.  * @param topicId The topic ID to decrement the total number of replies
  167.  */
  168. public void decrementTotalReplies(int topicId) ;
  169. /**
  170.  * Sets the ID of the last post of the topic
  171.  * 
  172.  * @param topicId Topic ID
  173.  * @param postId Post ID
  174.  */
  175. public void setLastPostId(int topicId, int postId) ;
  176. /**
  177.  * Gets the last post id associated to the topic
  178.  * 
  179.  * @param topicId The topic id
  180.      * @return int
  181.  */
  182. public int getMaxPostId(int topicId) ;
  183. /**
  184.  * Gets the number of posts the topic has.
  185.  * 
  186.  * @param topicId The topic id
  187.  * @return The number of posts
  188.  */
  189. public int getTotalPosts(int topicId) ;
  190. /**
  191.  * Get the users to notify
  192.  * 
  193.  * @param topic The topic 
  194.  * @return <code>ArrayList</code> of <code>User</code> objects. Each
  195.  * entry is an user who will receive the topic anwser notification
  196.  * */
  197. public List notifyUsers(Topic topic) ;
  198. /**
  199.  * Subscribe a set of users for notification of new post in the topic
  200.  * @param topicId the topic id
  201.  * @param users the relation of {@link User} instances to subscribe
  202.  */
  203. public void subscribeUsers(int topicId, List users);
  204. /**
  205.  * Subscribe the user for notification of new post in the topic
  206.  *  
  207.  * @param topicId The topic id
  208.  * @param userId The user id
  209.  */
  210. public void subscribeUser(int topicId, int userId) ;
  211. /**
  212.  * Return the subscrition status of the user on the topic.
  213.  * 
  214.  * @param topicId The topic id
  215.  * @param userId The user id
  216.  * @return true if the user is waiting notification on the topic
  217.  */
  218. public boolean isUserSubscribed(int topicId, int userId) ;
  219. /**
  220.  * Remove the user's subscription of the topic
  221.  * 
  222.  * @param topicId The topic id
  223.  * @param userId the User id
  224.  */
  225. public void removeSubscription(int topicId, int userId) ;
  226. /**
  227.  * Clean all subscriptions of some topic
  228.  * 
  229.  * @param topicId The topic id
  230.  */
  231. public void removeSubscriptionByTopic(int topicId) ;
  232. /**
  233.  * Change the topic read status 
  234.  * 
  235.  * @param topicId The topic id
  236.  * @param userId The user id
  237.  * @param read <code>true</code> or <code>false</code>
  238.  */
  239. public void updateReadStatus(int topicId, int userId, boolean read) ;
  240. /**
  241.  * Lock or unlock a topic. 
  242.  * 
  243.  * @param topicId The topic id to perform the action on
  244.  * @param status Use <code>Topic.STATUS_LOCKED</code> to lock the topic, or
  245.  * <code>Topic.STATUS_UNLOCKED</code> to unlock. 
  246.  */
  247. public void lockUnlock(int[] topicId, int status) ;
  248. /**
  249.  * Selects recent topics 
  250.  *
  251.  * @param limit The number of topics to retrieve
  252.      * @return List
  253.  */
  254. public List selectRecentTopics (int limit) ;
  255. /**
  256.  * Selects hottest topics
  257.  *
  258.  * @param limit The number of topics to retrieve
  259.     * @return List
  260.  */
  261. public List selectHottestTopics (int limit) ;
  262. /**
  263.  * Sets the ID of the first post of the topic
  264.  * 
  265.  * @param topicId Topic ID
  266.  * @param postId Post ID
  267.  */
  268. public void setFirstPostId(int topicId, int postId) ;
  269. /**
  270.  * Gets the first post id associated to the topic
  271.  * 
  272.  * @param topicId The topic id
  273.      * @return int
  274.  */
  275. public int getMinPostId(int topicId) ;
  276. /**
  277.  * Sets the moderatation flag for all topics of a given forum.
  278.  * 
  279.  * @param forumId The forum id
  280.  * @param status boolean
  281.  */
  282. public void setModerationStatus(int forumId, boolean status) ;
  283. /**
  284.  * Sets the moderatation flag for a given topic.
  285.  * 
  286.  * @param topicId The topic id
  287.  * @param status boolean
  288.  */
  289. public void setModerationStatusByTopic(int topicId, boolean status) ;
  290. /**
  291.  * Get all unique posters of some topic
  292.  * @param topicId int
  293.  * @return A Map instance with all topic posts. Key is the userid, 
  294.  * value is an {@link net.jforum.entities.User} instance with minimum
  295.  * data filled
  296.  */
  297. public Map topicPosters(int topicId) ;
  298. /**
  299.  * @param args
  300.  * @return
  301.  */
  302. public SearchResult findTopicsByDateRange(SearchArgs args);
  303. }