java.lang.Object
ai.tutor.cab302exceptionalhandlers.model.MessageDAO
All Implemented Interfaces:
IMessageDAO

public class MessageDAO extends Object implements IMessageDAO
Conducts DAO operations for the messages table in the SQLite database.

This Data Access Object (DAO) provides methods to perform CRUD operations on the messages table in the SQLite database. Messages represent user inputs or AI responses within a chat session, identified by a chat ID, and support learning features such as quiz delivery and feedback.

Author:
Joshua M.
  • Constructor Details

    • MessageDAO

      public MessageDAO(SQLiteConnection sqliteConnection) throws SQLException, RuntimeException
      Constructs a MessageDAO with an SQLite database connection.
      Parameters:
      sqliteConnection - the SQLiteConnection instance for database access
      Throws:
      SQLException - if a database error occurs during initialisation
      RuntimeException - if the SQLite connection cannot be established
  • Method Details

    • createMessage

      public void createMessage(Message message) throws SQLException
      Inserts a new Message entity into the database.

      This method inserts a Message entity into the messages table, storing its chat ID, content, sender type (user or AI), and quiz flag. The message ID is automatically generated by the SQLite database and set on the Message entity to ensure uniqueness.

      Specified by:
      createMessage in interface IMessageDAO
      Parameters:
      message - the Message entity to insert
      Throws:
      SQLException - if a database error occurs during insertion
    • getAllChatMessages

      public List<Message> getAllChatMessages(int chatId) throws IllegalArgumentException, SQLException
      Retrieves all Message entities for a specific chat session.

      This method fetches all messages associated with a given chat ID from the messages table. It returns a list of messages, which may be empty if no messages exist.

      Specified by:
      getAllChatMessages in interface IMessageDAO
      Parameters:
      chatId - the ID of the chat session
      Returns:
      a List of Message entities for the chat, or an empty list if none exist
      Throws:
      IllegalArgumentException - if chatId is negative
      SQLException - if a database error occurs during retrieval