Class AnswerOptionDAO
- All Implemented Interfaces:
IAnswerOptionDAO
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 Summary
ConstructorsConstructorDescriptionAnswerOptionDAO
(SQLiteConnection sqliteConnection) Constructor forAnswerOptionDAO
initializing answerOptions table. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createAnswerOption
(AnswerOption answerOption) Inserts anAnswerOption
into the database.getAllQuestionAnswerOptions
(int messageId, int questionNumber) Retrieves allAnswerOption
entities for a specific quiz question.getQuestionAnswerOption
(int messageId, int questionNumber, String option) Retrieves a specificAnswerOption
for a quiz question.
-
Constructor Details
-
AnswerOptionDAO
Constructor forAnswerOptionDAO
initializing answerOptions table.- Parameters:
sqliteConnection
- theSQLiteConnection
instance for database access- Throws:
SQLException
- if a database error occurs when creating answerOptions tableRuntimeException
- if the SQLite connection cannot be established- See Also:
-
-
Method Details
-
createAnswerOption
Inserts anAnswerOption
into the database.This method inserts an
AnswerOption
into theanswerOptions
table, storing its message ID, question number, option identifier, value, and whether it is the correct answer.- Specified by:
createAnswerOption
in interfaceIAnswerOptionDAO
- Parameters:
answerOption
- theAnswerOption
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 specificAnswerOption
for a quiz question.This method fetches an
AnswerOption
from theanswerOptions
table using the provided message ID, question number, and option identifier. It returns the matching answer option ornull
if no such option exists.- Specified by:
getQuestionAnswerOption
in interfaceIAnswerOptionDAO
- Parameters:
messageId
- the ID of the quiz messagequestionNumber
- the number of the question within the quizoption
- the identifier of the answer option- Returns:
- the
AnswerOption
object if found, ornull
if no matching option exists - Throws:
IllegalArgumentException
- ifmessageId
orquestionNumber
is negative, oroption
isnull
or emptySQLException
- if a database error occurs during retrieval
-
getAllQuestionAnswerOptions
public List<AnswerOption> getAllQuestionAnswerOptions(int messageId, int questionNumber) throws IllegalArgumentException, SQLException Retrieves allAnswerOption
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 interfaceIAnswerOptionDAO
- Parameters:
messageId
- the ID of the quiz messagequestionNumber
- the number of the question within the quiz- Returns:
- a
List
ofAnswerOption
objects for the question, or an empty list if none exist - Throws:
IllegalArgumentException
- ifmessageId
orquestionNumber
is negativeSQLException
- if a database error occurs during fetching
-