Class ForumsDAO


  • public class ForumsDAO
    extends Object
    Class managing database accesses for forums.
    • Method Detail

      • getForumsByKeys

        public static Collection<Forum> getForumsByKeys​(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 (Forum).
        Throws:
        SQLException - An SQL exception.
      • getMessagesByKeys

        public static Collection<Message> getMessagesByKeys​(Connection con,
                                                            Collection<MessagePK> messagePKs)
                                                     throws SQLException
        Parameters:
        con - The connection to the database.
        messagePKs - The list of messages primary keys.
        Returns:
        The list of messages corresponding to the primary keys (Message).
        Throws:
        SQLException - An SQL exception.
      • getThreadsByKeys

        public static Collection<Message> getThreadsByKeys​(Connection con,
                                                           Collection<MessagePK> messagePKs)
                                                    throws SQLException
        Parameters:
        con - The connection to the database.
        messagePKs - The list of messages primary keys.
        Returns:
        The list of threads corresponding to the primary keys (Message).
        Throws:
        SQLException - An SQL exception.
      • getForumsList

        public static 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.
      • getForumsIds

        public static List<String> getForumsIds​(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 corresponding to the primary key.
        Throws:
        SQLException - An SQL exception.
      • getForumsListByCategory

        public static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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:
        Throws:
        SQLException - An SQL exception.
      • createForum

        public static 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 static 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 static 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.
      • getMessagesList

        public static 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 static 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.
      • getMessagesIds

        public static List<String> getMessagesIds​(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 messages of the forum corresponding to the primary key.
        Throws:
        SQLException - An SQL exception.
      • getSubjectsIds

        public static 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 static 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 static 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 static 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 static 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.
      • getLastThreads

        public static List<Message> getLastThreads​(Connection con,
                                                   ForumPK[] forumPKs,
                                                   int count)
                                            throws SQLException
        Parameters:
        con - The connection to the database.
        forumPKs - The list of forums primary keys.
        count - The maximum number of returned threads.
        Returns:
        The last 'count' threads from the forums corresponding to the primary keys.
        Throws:
        SQLException - An SQL exception.
      • getNotAnsweredLastThreads

        public static Collection<Message> getNotAnsweredLastThreads​(Connection con,
                                                                    ForumPK[] forumPKs,
                                                                    int count)
                                                             throws SQLException
        Parameters:
        con - The connection to the database.
        forumPKs - The list of forums primary keys.
        count - The maximum number of returned threads.
        Returns:
        The last not answered 'count' threads from the forums corresponding to the primary keys.
        Throws:
        SQLException - An SQL exception.
      • getLastMessageRSS

        public static 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 static 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.
      • getMessageInfos

        public static List getMessageInfos​(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 (Vector).
        Throws:
        SQLException - An SQL exception.
      • getMessage

        public static 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 static 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 static 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.
      • getThread

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

        public static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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.
      • moveMessage

        public static 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.
      • getAllMessageSons

        public static Collection<String> getAllMessageSons​(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 messages which parent is the message corresponding to the primary key.
        Throws:
        SQLException - An SQL exception.
      • getForumDetail

        public static 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 static Date getLastVisit​(Connection con,
                                        String userId,
                                        int messageId)
                                 throws SQLException
        Parameters:
        con - The connection to the database.
        userId - The user's id.
        messageId - The id of the message.
        Returns:
        The last access date to the message corresponding to the message id.
        Throws:
        SQLException - An SQL exception.
      • getLastVisit

        public static 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 static 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 static 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.