java.lang.Object
ai.tutor.cab302exceptionalhandlers.model.QuizQuestionDAO
All Implemented Interfaces:
IQuizQuestionDAO

public class QuizQuestionDAO extends Object implements IQuizQuestionDAO
Conducts SQL operations for managing quiz questions into the database

This Data Access Object (DAO) provides methods to perform CRUD operations on the quizQuestions table in the SQLite database. Quiz questions are associated with quizzes via a message ID and a question number, representing individual questions within a quiz, and support features such as quiz delivery and evaluation.

Author:
Joshua M.
  • Constructor Details

    • QuizQuestionDAO

      public QuizQuestionDAO(SQLiteConnection sqliteConnection) throws SQLException, RuntimeException
      Initialises the QuizQuestionDAO 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

    • createQuizQuestion

      public void createQuizQuestion(QuizQuestion quizQuestion) throws SQLException
      Inserts a new QuizQuestion entity to the database.

      This method inserts a QuizQuestion entity into the quizQuestions table, storing its message ID, question number, and question content. The message ID must correspond to an existing quiz in the quizzes table, and the question number must be unique for that message ID.

      Specified by:
      createQuizQuestion in interface IQuizQuestionDAO
      Parameters:
      quizQuestion - the QuizQuestion entity to insert
      Throws:
      SQLException - if a database error occurs during insertion
    • getQuizQuestion

      public QuizQuestion getQuizQuestion(int messageId, int number) throws IllegalArgumentException, SQLException
      Retrieves a QuizQuestion entity by its message ID and question number.

      This method fetches a single QuizQuestion entity from the quizQuestions table that matches the specified message ID and question number. Returns null if no quiz question is found for the given key.

      Specified by:
      getQuizQuestion in interface IQuizQuestionDAO
      Parameters:
      messageId - the ID of the associated quiz
      number - the question number within the quiz
      Returns:
      the QuizQuestion entity, or null if none exists
      Throws:
      IllegalArgumentException - if messageId or number is negative
      SQLException - if a database error occurs during retrieval
    • getAllQuizQuestions

      public List<QuizQuestion> getAllQuizQuestions(int messageId) throws IllegalArgumentException, SQLException
      Retrieves all QuizQuestion entities for a specific quiz.

      This method fetches all quiz questions associated with the specified message ID from the quizQuestions table. Returns a list of QuizQuestion entities, which may be empty if no questions are found for the quiz.

      Specified by:
      getAllQuizQuestions in interface IQuizQuestionDAO
      Parameters:
      messageId - the ID of the associated quiz
      Returns:
      a List of QuizQuestion entities for the quiz, or an empty list if none exist
      Throws:
      IllegalArgumentException - if messageId is negative
      SQLException - if a database error occurs during retrieval