Class QuizQuestionDAO
- All Implemented Interfaces:
IQuizQuestionDAO
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 Summary
ConstructorsConstructorDescriptionQuizQuestionDAO
(SQLiteConnection sqliteConnection) Initialises theQuizQuestionDAO
with an SQLite database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createQuizQuestion
(QuizQuestion quizQuestion) Inserts a newQuizQuestion
entity to the database.getAllQuizQuestions
(int messageId) Retrieves allQuizQuestion
entities for a specific quiz.getQuizQuestion
(int messageId, int number) Retrieves aQuizQuestion
entity by its message ID and question number.
-
Constructor Details
-
QuizQuestionDAO
Initialises theQuizQuestionDAO
with an SQLite database connection.- Parameters:
sqliteConnection
- theSQLiteConnection
instance for database access- Throws:
SQLException
- if a database error occurs during initialisationRuntimeException
- if the SQLite connection cannot be established
-
-
Method Details
-
createQuizQuestion
Inserts a newQuizQuestion
entity to the database.This method inserts a
QuizQuestion
entity into thequizQuestions
table, storing its message ID, question number, and question content. The message ID must correspond to an existing quiz in thequizzes
table, and the question number must be unique for that message ID.- Specified by:
createQuizQuestion
in interfaceIQuizQuestionDAO
- Parameters:
quizQuestion
- theQuizQuestion
entity to insert- Throws:
SQLException
- if a database error occurs during insertion
-
getQuizQuestion
public QuizQuestion getQuizQuestion(int messageId, int number) throws IllegalArgumentException, SQLException Retrieves aQuizQuestion
entity by its message ID and question number.This method fetches a single
QuizQuestion
entity from thequizQuestions
table that matches the specified message ID and question number. Returnsnull
if no quiz question is found for the given key.- Specified by:
getQuizQuestion
in interfaceIQuizQuestionDAO
- Parameters:
messageId
- the ID of the associated quiznumber
- the question number within the quiz- Returns:
- the
QuizQuestion
entity, ornull
if none exists - Throws:
IllegalArgumentException
- ifmessageId
ornumber
is negativeSQLException
- if a database error occurs during retrieval
-
getAllQuizQuestions
public List<QuizQuestion> getAllQuizQuestions(int messageId) throws IllegalArgumentException, SQLException Retrieves allQuizQuestion
entities for a specific quiz.This method fetches all quiz questions associated with the specified message ID from the
quizQuestions
table. Returns a list ofQuizQuestion
entities, which may be empty if no questions are found for the quiz.- Specified by:
getAllQuizQuestions
in interfaceIQuizQuestionDAO
- Parameters:
messageId
- the ID of the associated quiz- Returns:
- a
List
ofQuizQuestion
entities for the quiz, or an empty list if none exist - Throws:
IllegalArgumentException
- ifmessageId
is negativeSQLException
- if a database error occurs during retrieval
-