Class ForumsDAO

java.lang.Object
org.silverpeas.components.forums.service.ForumsDAO

@Repository public class ForumsDAO extends Object
Class managing database accesses for forums.
  • Constructor Details

    • ForumsDAO

      public ForumsDAO()
  • Method Details

    • selectByForumPKs

      public Collection<ForumDetail> selectByForumPKs(Connection con, Collection<ForumPK> forumPKs) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPKs - The list of forums primary keys.
      Returns:
      The list of forums corresponding to the primary keys (ForumDetail).
      Throws:
      SQLException - An SQL exception.
    • getForumsList

      public List<Forum> getForumsList(Connection con, ForumPK forumPK) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Returns:
      The list of forums corresponding to the primary key (Forum).
      Throws:
      SQLException - An SQL exception.
    • getForumsListByCategory

      public List<Forum> getForumsListByCategory(Connection con, ForumPK forumPK, String categoryId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      categoryId - The id of the category.
      Returns:
      The list of forums corresponding to the primary key and the category id.
      Throws:
      SQLException - An SQL exception.
    • getForumSonsIds

      public List<String> getForumSonsIds(Connection con, ForumPK forumPK) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Returns:
      The list of ids of forums which parent is the forum corresponding to the primary key.
      Throws:
      SQLException - An SQL exception.
    • getForum

      public Forum getForum(Connection con, ForumPK forumPK) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Returns:
      The forum corresponding to the primary key (Forum).
      Throws:
      SQLException - An SQL exception.
    • getForumName

      public String getForumName(Connection con, int forumId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumId - The id of the forum.
      Returns:
      The name corresponding to the forum id.
      Throws:
      SQLException - An SQL exception.
    • isForumActive

      public boolean isForumActive(Connection con, int forumId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumId - The id of the forum.
      Returns:
      True if the forum is active.
      Throws:
      SQLException - An SQL exception.
    • getForumParentId

      public int getForumParentId(Connection con, int forumId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumId - The id of the forum.
      Returns:
      The id of the parent of the forum.
      Throws:
      SQLException - An SQL exception.
    • getForumInstanceId

      public String getForumInstanceId(Connection con, int forumId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumId - The id of the forum.
      Returns:
      The instance id corresponding to the forum id.
      Throws:
      SQLException - An SQL exception.
    • getForumCreatorId

      public String getForumCreatorId(Connection con, int forumId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumId - The id of the forum.
      Returns:
      The id of the creator of the forum.
      Throws:
      SQLException - An SQL exception.
    • lockForum

      public void lockForum(Connection con, ForumPK forumPK, int level) throws SQLException
      Locks the forum corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      level - The lock level.
      Throws:
      SQLException - An SQL exception.
    • unlockForum

      public int unlockForum(Connection con, ForumPK forumPK, int level) throws SQLException
      Unlocks the forum corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      level - The lock level.
      Returns:
      the operation status. 0 is ok, any other values are an error code.
      Throws:
      SQLException - An SQL exception.
    • createForum

      public int createForum(Connection con, ForumPK forumPK, String forumName, String forumDescription, String forumCreator, int forumParent, String categoryId) throws SQLException
      Creates a forum.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      forumName - The name of the forum.
      forumDescription - The description of the forum.
      forumCreator - The creator of the forum.
      forumParent - The id of the forum's parent forum.
      categoryId - The id of the category.
      Returns:
      The id of the newly created forum.
      Throws:
      SQLException - An SQL exception.
    • updateForum

      public void updateForum(Connection con, ForumPK forumPK, String forumName, String forumDescription, int forumParent, String categoryId) throws SQLException
      Updates the forum corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      forumName - The name of the forum.
      forumDescription - The description of the forum.
      forumParent - The id of the forum's parent forum.
      categoryId - The id of the category.
      Throws:
      SQLException - An SQL exception.
    • deleteForum

      public void deleteForum(Connection con, ForumPK forumPK) throws SQLException
      Deletes the forum corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Throws:
      SQLException - An SQL exception.
    • deleteAllForums

      public void deleteAllForums(Connection con, String instanceId) throws SQLException
      Throws:
      SQLException
    • getMessagesList

      public List<Message> getMessagesList(Connection con, ForumPK forumPK) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Returns:
      The list of messages of the forum corresponding to the primary key (Message).
      Throws:
      SQLException - An SQL exception.
    • getMessagesIds

      public List<String> getMessagesIds(Connection con, ForumPK forumPK, int messageParentId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      messageParentId - The id of the message's parent message.
      Returns:
      The list of ids of messages of the forum corresponding to the primary key and which parent message corresponds to the message id (if it is valued).
      Throws:
      SQLException - An SQL exception.
    • getSubjectsIds

      public List<String> getSubjectsIds(Connection con, ForumPK forumPK) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Returns:
      The list of ids of threads of the forum corresponding to the primary key.
      Throws:
      SQLException - An SQL exception.
    • getNbMessages

      public int getNbMessages(Connection con, int forumId, String type, String status) throws SQLException
      Parameters:
      con - The connection to the database.
      forumId - The id of the forum.
      type - The type of the searched messages.
      Returns:
      The number of messages corresponding to the forum id and the type (threads or not).
      Throws:
      SQLException - An SQL exception.
    • getAuthorNbMessages

      public int getAuthorNbMessages(Connection con, String userId, String status) throws SQLException
      Parameters:
      con - The connection to the database.
      userId - The user's id.
      Returns:
      The number of messages written by the author corresponding to the user id.
      Throws:
      SQLException - An SQL exception.
    • getNbResponses

      public int getNbResponses(Connection con, int forumId, int messageId, String status)
      Parameters:
      con - The connection to the database.
      forumId - The id of the forum.
      messageId - The id of the message.
      Returns:
      The number of responses to the message corresponding to the message id and the forum id.
    • getLastMessage

      public Message getLastMessage(Connection con, ForumPK forumPK, String status) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Returns:
      The last message of the forum corresponding to the forum id.
      Throws:
      SQLException - An SQL exception.
    • getLastMessageRSS

      public Collection<String> getLastMessageRSS(Connection con, String instanceId) throws SQLException
      Parameters:
      con - The connection to the database.
      instanceId - The id of the forums instance.
      Returns:
      The list of ids of messages from the forums corresponding to the instance id.
      Throws:
      SQLException - An SQL exception.
    • getLastMessage

      public Message getLastMessage(Connection con, ForumPK forumPK, List<String> messageParentIds, String status) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      messageParentIds - The ids of the parent messages.
      Returns:
      The last message from the forum corresponding to the primary key among the messages which id or parent message id belong to the list.
      Throws:
      SQLException - An SQL exception.
    • getMessage

      public Message getMessage(Connection con, MessagePK messagePK) throws SQLException
      Parameters:
      con - The connection to the database.
      messagePK - The primary key of the message.
      Returns:
      The message corresponding to the primary key (Message).
      Throws:
      SQLException - An SQL exception.
    • getMessageTitle

      public String getMessageTitle(Connection con, int messageId) throws SQLException
      Parameters:
      con - The connection to the database.
      messageId - The id of the message.
      Returns:
      The title of the message.
      Throws:
      SQLException - An SQL exception.
    • getMessageParentId

      public int getMessageParentId(Connection con, int messageId) throws SQLException
      Parameters:
      con - The connection to the database.
      messageId - The id of the message.
      Returns:
      The id of the parent of the message.
      Throws:
      SQLException - An SQL exception.
    • createMessage

      public int createMessage(Connection con, String messageTitle, String messageAuthor, Date messageDate, int forumId, int messageParent, String status) throws SQLException
      Creates a message.
      Parameters:
      con - The connection to the database.
      messageTitle - The title of the message.
      messageAuthor - The author of the message.
      messageDate - The date of creation of the message.
      forumId - The id of the parent forum.
      messageParent - The id of the parent message.
      Returns:
      The id of the newly created message.
      Throws:
      SQLException - An SQL exception.
    • updateMessage

      public void updateMessage(Connection con, MessagePK messagePK, String title, String status) throws SQLException
      Updates the message corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      messagePK - The primary key of the message.
      title - The title of the message.
      Throws:
      SQLException - An SQL exception.
    • deleteMessage

      public void deleteMessage(Connection con, MessagePK messagePK) throws SQLException
      Deletes the message corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      messagePK - The primary key of the message.
      Throws:
      SQLException - An SQL exception.
    • getMessageSons

      public Collection<String> getMessageSons(Connection con, MessagePK messagePK) throws SQLException
      Parameters:
      con - The connection to the database.
      messagePK - The primary key of the message.
      Returns:
      The list of ids of the messages which parent is the message corresponding to the primary key.
      Throws:
      SQLException - An SQL exception.
    • isModerator

      public boolean isModerator(Connection con, ForumPK forumPK, String userId) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      userId - The user's id.
      Returns:
      True if the user owns the role of moderator on the forum corresponding to the primary key, else false.
      Throws:
      SQLException - An SQL exception.
    • addModerator

      public void addModerator(Connection con, ForumPK forumPK, String userId) throws SQLException
      Adds the role of moderator to the user on the forum corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      userId - The user's id.
      Throws:
      SQLException - An SQL exception.
    • removeModerator

      public void removeModerator(Connection con, ForumPK forumPK, String userId) throws SQLException
      Removes the role of moderator to the user on the forum corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      userId - The user's id.
      Throws:
      SQLException - An SQL exception.
    • removeAllModerators

      public void removeAllModerators(Connection con, ForumPK forumPK) throws SQLException
      Removes the role of moderator to all users on the forum corresponding to the primary key.
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Throws:
      SQLException - An SQL exception.
    • getModerators

      public List<Moderator> getModerators(Connection con, int forumId) throws SQLException
      Throws:
      SQLException
    • moveMessage

      public void moveMessage(Connection con, MessagePK messagePK, ForumPK forumPK) throws SQLException
      Moves the message corresponding to the message primary key from a previous forum to the one corresponding to the forum primary key.
      Parameters:
      con - The connection to the database.
      messagePK - The primary key of the message.
      forumPK - The primary key of the forum.
      Throws:
      SQLException - An SQL exception.
    • getForumDetail

      public ForumDetail getForumDetail(Connection con, ForumPK forumPK) throws SQLException
      Parameters:
      con - The connection to the database.
      forumPK - The primary key of the forum.
      Returns:
      The forum corresponding to the primary key (ForumDetail).
      Throws:
      SQLException - An SQL exception.
    • getLastVisit

      public Date getLastVisit(Connection con, String userId, List<String> messageIds) throws SQLException
      Parameters:
      con - The connection to the database.
      userId - The user's id.
      messageIds - The list of ids of the messages.
      Returns:
      The last access date of the user to the messages corresponding to the list of primary keys.
      Throws:
      SQLException - An SQL exception.
    • addLastVisit

      public void addLastVisit(Connection con, String userId, int messageId) throws SQLException
      Adds an access date to the message corresponding to the message id by the user.
      Parameters:
      con - The connection to the database.
      userId - The user's id.
      messageId - The id of the message.
      Throws:
      SQLException - An SQL exception.
    • deleteVisit

      public void deleteVisit(Connection con, String userId, int messageId) throws SQLException
      Deletes the access date of the user to the message corresponding to the message id.
      Parameters:
      con - The connection to the database.
      userId - The user's id.
      messageId - The id of the message.
      Throws:
      SQLException - An SQL exception.