Class MoodDAO

java.lang.Object
com.wellnessapp.model.mood.MoodDAO
All Implemented Interfaces:
IMoodDAO

public class MoodDAO extends Object implements IMoodDAO
Implementation of the Mood Database Access Object (DAO) interface. Provides methods to interact with mood entries stored in the database.
  • Field Details

  • Constructor Details

    • MoodDAO

      public MoodDAO()
      Constructs a MoodDAO object and initializes the database connection.
  • Method Details

    • Create

      public void Create(MoodEntry entry) throws SQLException
      Inserts a new MoodEntry into the database.

      Upon successful insertion, the ID generated by the database will be set back to the provided MoodEntry object.
      Specified by:
      Create in interface IMoodDAO
      Parameters:
      entry - the MoodEntry object containing the mood details to be inserted into the database. This object must not be null.
      Throws:
      SQLException - Any issues executing is caught within the method and the stack trace will be printed.
    • Delete

      public void Delete(MoodEntry entry)
      Deletes a mood entry from the database.
      Specified by:
      Delete in interface IMoodDAO
      Parameters:
      entry - The mood entry to delete.
    • Update

      public void Update(MoodEntry entry)
      Updates an existing mood entry in the database.
      Specified by:
      Update in interface IMoodDAO
      Parameters:
      entry - The mood entry to update.
    • getEntryById

      public MoodEntry getEntryById(int id)
      Retrieves a mood entry from the database by its ID.
      Specified by:
      getEntryById in interface IMoodDAO
      Parameters:
      id - The ID of the mood entry to retrieve.
      Returns:
      The mood entry with the specified ID, or null if not found.
    • getAllEntries

      public List<MoodEntry> getAllEntries(boolean sorted)
      Retrieves all mood entries from the database.
      Specified by:
      getAllEntries in interface IMoodDAO
      Parameters:
      sorted - Indicates whether the entries should be sorted, when sorted returns order by DESC, otherwise ASC
      Returns:
      A list of mood entries.