Class MessageDAO
java.lang.Object
ai.tutor.cab302exceptionalhandlers.model.MessageDAO
- All Implemented Interfaces:
IMessageDAO
Conducts DAO operations for the
messages
table in the SQLite database.
This Data Access Object (DAO) provides methods to perform CRUD operations on the
messages
table in the SQLite database. Messages represent user inputs or AI
responses within a chat session, identified by a chat ID, and support learning features
such as quiz delivery and feedback.
- Author:
- Joshua M.
-
Constructor Summary
ConstructorsConstructorDescriptionMessageDAO
(SQLiteConnection sqliteConnection) Constructs aMessageDAO
with an SQLite database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createMessage
(Message message) Inserts a newMessage
entity into the database.getAllChatMessages
(int chatId) Retrieves allMessage
entities for a specific chat session.
-
Constructor Details
-
MessageDAO
Constructs aMessageDAO
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
-
createMessage
Inserts a newMessage
entity into the database.This method inserts a
Message
entity into themessages
table, storing its chat ID, content, sender type (user or AI), and quiz flag. The message ID is automatically generated by the SQLite database and set on theMessage
entity to ensure uniqueness.- Specified by:
createMessage
in interfaceIMessageDAO
- Parameters:
message
- theMessage
entity to insert- Throws:
SQLException
- if a database error occurs during insertion
-
getAllChatMessages
Retrieves allMessage
entities for a specific chat session.This method fetches all messages associated with a given chat ID from the
messages
table. It returns a list of messages, which may be empty if no messages exist.- Specified by:
getAllChatMessages
in interfaceIMessageDAO
- Parameters:
chatId
- the ID of the chat session- Returns:
- a
List
ofMessage
entities for the chat, or an empty list if none exist - Throws:
IllegalArgumentException
- ifchatId
is negativeSQLException
- if a database error occurs during retrieval
-