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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMoodDAO()Constructs a MoodDAO object and initializes the database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts a newMoodEntryinto the database.voidDeletes 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.voidUpdates 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 newMoodEntryinto the database.
Upon successful insertion, the ID generated by the database will be set back to the providedMoodEntryobject.- Specified by:
Createin interfaceIMoodDAO- Parameters:
entry- theMoodEntryobject 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:
getEntryByIdin interfaceIMoodDAO- Parameters:
id- The ID of the mood entry to retrieve.- Returns:
- The mood entry with the specified ID, or
nullif not found.
-
getAllEntries
Retrieves all mood entries from the database.- Specified by:
getAllEntriesin interfaceIMoodDAO- Parameters:
sorted- Indicates whether the entries should be sorted, when sorted returns order by DESC, otherwise ASC- Returns:
- A list of mood entries.
-