Class QuizDAO
- All Implemented Interfaces:
IQuizDAO
This Data Access Object (DAO) provides methods to perform CRUD operations and queries
on the quizzes
table in the SQLite database. Quizzes are associated with
messages via a message ID, representing AI-generated quiz content within chat sessions.
- Author:
- Joshua M.
-
Constructor Summary
ConstructorsConstructorDescriptionQuizDAO
(SQLiteConnection sqliteConnection) Initialises theQuizDAO
with an SQLite database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createQuiz
(Quiz quiz) Saves a newQuiz
entity to the database.getAllChatQuizzes
(int chatId) Retrieves allQuiz
entities for a specific chat session.getAllUserQuizzes
(int userId) Retrieves allQuiz
entities for a specific user across all their chat sessions.getQuiz
(int messageId) Retrieves aQuiz
entity by its associated message ID.
-
Constructor Details
-
QuizDAO
Initialises theQuizDAO
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
-
createQuiz
Saves a newQuiz
entity to the database.- Specified by:
createQuiz
in interfaceIQuizDAO
- Parameters:
quiz
- theQuiz
entity to save- Throws:
SQLException
- if a database error occurs during insertion
-
getQuiz
Retrieves aQuiz
entity by its associated message ID.This method fetches a single
Quiz
entity from thequizzes
table that matches the specified message ID. Returnsnull
if no quiz is found for the given message ID.- Specified by:
getQuiz
in interfaceIQuizDAO
- Parameters:
messageId
- the ID of the associated message- Returns:
- the
Quiz
entity, ornull
if none exists - Throws:
SQLException
- if a database error occurs during retrieval
-
getAllChatQuizzes
Retrieves allQuiz
entities for a specific chat session.This method fetches all quizzes associated with AI-generated messages marked as quizzes (where
fromUser
is false andisQuiz
is true) within the specified chat session. Returns a list ofQuiz
entities, which may be empty if no quizzes are found for the chat ID.- Specified by:
getAllChatQuizzes
in interfaceIQuizDAO
- Parameters:
chatId
- the ID of the chat session- Returns:
- a
List
ofQuiz
entities for the chat, or an empty list if none exist - Throws:
SQLException
- if a database error occurs during retrieval
-
getAllUserQuizzes
Retrieves allQuiz
entities for a specific user across all their chat sessions.This method fetches all quizzes associated with AI-generated messages marked as quizzes from all chat sessions linked to the given user ID. Returns a list of
Quiz
entities, which may be empty if no quizzes are found for the user.- Specified by:
getAllUserQuizzes
in interfaceIQuizDAO
- Parameters:
userId
- the ID of the user- Returns:
- a
List
ofQuiz
entities for the user, or an empty list if none exist - Throws:
SQLException
- if a database error occurs during retrieval
-