java.lang.Object
ai.tutor.cab302exceptionalhandlers.model.AnswerOptionDAO
All Implemented Interfaces:
IAnswerOptionDAO

public class AnswerOptionDAO extends Object implements IAnswerOptionDAO
Responsible for conducting database CRUD operations for quiz answer options.

This Data Access Object (DAO) provides methods to create and retrieve answer options for quiz questions in the SQLite database. It manages the `answerOptions` table, which stores answer options associated with quiz questions.

Author:
Joshua M.
  • Constructor Details

  • Method Details

    • createAnswerOption

      public void createAnswerOption(AnswerOption answerOption) throws SQLException
      Inserts an AnswerOption into the database.

      This method inserts an AnswerOption into the answerOptions table, storing its message ID, question number, option identifier, value, and whether it is the correct answer.

      Specified by:
      createAnswerOption in interface IAnswerOptionDAO
      Parameters:
      answerOption - the AnswerOption object to insert
      Throws:
      SQLException - if a database error occurs during insertion
    • getQuestionAnswerOption

      public AnswerOption getQuestionAnswerOption(int messageId, int questionNumber, String option) throws IllegalArgumentException, SQLException
      Retrieves a specific AnswerOption for a quiz question.

      This method fetches an AnswerOption from the answerOptions table using the provided message ID, question number, and option identifier. It returns the matching answer option or null if no such option exists.

      Specified by:
      getQuestionAnswerOption in interface IAnswerOptionDAO
      Parameters:
      messageId - the ID of the quiz message
      questionNumber - the number of the question within the quiz
      option - the identifier of the answer option
      Returns:
      the AnswerOption object if found, or null if no matching option exists
      Throws:
      IllegalArgumentException - if messageId or questionNumber is negative, or option is null or empty
      SQLException - if a database error occurs during retrieval
    • getAllQuestionAnswerOptions

      public List<AnswerOption> getAllQuestionAnswerOptions(int messageId, int questionNumber) throws IllegalArgumentException, SQLException
      Retrieves all AnswerOption entities for a specific quiz question.

      This method fetches all answer options associated with a quiz question identified by message ID and question number. It returns a list of answer options, which may be empty if no options exist.

      Specified by:
      getAllQuestionAnswerOptions in interface IAnswerOptionDAO
      Parameters:
      messageId - the ID of the quiz message
      questionNumber - the number of the question within the quiz
      Returns:
      a List of AnswerOption objects for the question, or an empty list if none exist
      Throws:
      IllegalArgumentException - if messageId or questionNumber is negative
      SQLException - if a database error occurs during fetching