java.lang.Object
com.wellnessapp.model.mood.MoodDAO
- All Implemented Interfaces:
IMoodDAO
Implementation of the Mood Database Access Object (DAO) interface.
Provides methods to interact with mood entries stored in the database.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMoodDAO()
Constructs a MoodDAO object and initializes the database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts a newMoodEntry
into the database.void
Deletes a mood entry from the database.getAllEntries
(boolean sorted) Retrieves all mood entries from the database.getEntryById
(int id) Retrieves a mood entry from the database by its ID.void
Updates an existing mood entry in the database.
-
Field Details
-
connection
-
-
Constructor Details
-
MoodDAO
public MoodDAO()Constructs a MoodDAO object and initializes the database connection.
-
-
Method Details
-
Create
Inserts a newMoodEntry
into the database.
Upon successful insertion, the ID generated by the database will be set back to the providedMoodEntry
object.- Specified by:
Create
in interfaceIMoodDAO
- Parameters:
entry
- theMoodEntry
object containing the mood details to be inserted into the database. This object must not benull
.- Throws:
SQLException
- Any issues executing is caught within the method and the stack trace will be printed.
-
Delete
Deletes a mood entry from the database. -
Update
Updates an existing mood entry in the database. -
getEntryById
Retrieves a mood entry from the database by its ID.- Specified by:
getEntryById
in interfaceIMoodDAO
- Parameters:
id
- The ID of the mood entry to retrieve.- Returns:
- The mood entry with the specified ID, or
null
if not found.
-
getAllEntries
Retrieves all mood entries from the database.- Specified by:
getAllEntries
in interfaceIMoodDAO
- Parameters:
sorted
- Indicates whether the entries should be sorted, when sorted returns order by DESC, otherwise ASC- Returns:
- A list of mood entries.
-