Class AnswerDAO

java.lang.Object
com.ubs.backend.classes.database.dao.DAO<Answer>
com.ubs.backend.classes.database.dao.AnswerDAO

public class AnswerDAO extends DAO<Answer>
DAO for com.ubs.backend.classes.database.Answer
Since:
17.07.2021
Author:
Marc, Tim Irmler
  • Constructor Details

    • AnswerDAO

      public AnswerDAO()
      the default constructor
  • Method Details

    • view

      public void view(Answer answer)
      Adds a view to an answer
      Parameters:
      answer - the answer which should receive a view
    • view

      public void view(Answer answer, javax.persistence.EntityManager em)
      increases the view count of an answer
      Parameters:
      answer - the answer which should receive a view
      em - the entity manager
      Since:
      02.09.2021
    • selectStatistikByTime

      public AnswerStatistik selectStatistikByTime(boolean createIfNotExists, long answerID, StatistikTimes statistikTimes, javax.persistence.EntityManager em)
      selects the current AnswerStatistik of the specified Answer in the specified StatistikTimes. If the answer has no Statistics for the specified StatistikTimes, the method can, if wanted, create it.
      Parameters:
      createIfNotExists - defines if an AnswerStatistik should be created if it does not exist.
      answerID - the id of the Answer where we want to find a AnswerStatistik
      statistikTimes - the specified time in which we want to have the statistics
      em - the entity manager
      Returns:
      the found AnswerStatistik. Returns null if nothing was found.
      Since:
      29.08.2021
    • selectByTag

      public List<Result> selectByTag(long id, javax.persistence.EntityManager em)
      selects all Results with a specific Tag
      Parameters:
      id - the id of the tag we're looking for
      em - the entity manager
      Returns:
      a list of Results containing the specified Tag
    • selectRandomByType

      public List<Answer> selectRandomByType(AnswerType type, int max)
      Selects a list of Answers containing random Answers from the DB that all have a specific type, but without specifying an EntityManager.
      Parameters:
      type - the AnswerType of the Answer
      max - defines how many Answers the list can contain maximum
      Returns:
      the list of Answers
      Since:
      20.07.2021
      See Also:
      for Method with EntityManager.
    • selectRandomByType

      public List<Answer> selectRandomByType(AnswerType type, int max, javax.persistence.EntityManager em)
      Selects a list of Answers containing random Answers from the DB that all have a specific type.
      Parameters:
      type - the AnswerType of the Answer
      max - defines how many Answers the list can contain maximum
      em - the entity manager
      Returns:
      the list of Answers
      Since:
      20.07.2021
    • getSingleTempAnswer

      public TempAnswer getSingleTempAnswer(long answerID, javax.persistence.EntityManager em)
      creates a single TempAnswer from an Answer selected from the DB.
      Parameters:
      answerID - the id of the answer from which the TempAnswer will be created
      em - the entity manager
      Returns:
      the newly created TempAnswer
      Since:
      21.07.2021
    • getAverageUsefulness

      public float getAverageUsefulness(long id, javax.persistence.EntityManager em)
      calculate average usefulness of an answer by looking at all of its connected tags and their rating. We need to differentiate if the answer has grouped tags or not as we have to check different tables.
      Parameters:
      id - the id of the answer
      em - the entity manager
      Returns:
      the average usefulness of an answer as a float
      Since:
      21.07.2021
    • selectByTypeAndTag

      public List<Answer> selectByTypeAndTag(long tagID, AnswerType type, javax.persistence.EntityManager em)
      Method to select a List of every Answer with a certain type and tag
      Parameters:
      tagID - the id of the tag we're looking for
      type - the type of the answer we're looking for
      em - the entity manager
      Returns:
      a List of every Answer with a certain type and tag
      Since:
      28.07.2021
    • selectByType

      public List<Answer> selectByType(AnswerType type, javax.persistence.EntityManager em)
      Select all answers with a set Type with a preset EntityManager
      Parameters:
      type - the type which we want to answers to contain
      em - the EntityManager which we will use
      Returns:
      a list of all answers with the set type
    • selectByType

      public List<Answer> selectByType(AnswerType type)
      Select all answers with a set Type
      Parameters:
      type - the type which we want to answers to contain
      Returns:
      a list of all answers with the set type
      Since:
      17.07.2021
    • countByType

      public int countByType(AnswerType type, javax.persistence.EntityManager em)
      Count how many answers there are per type
      Parameters:
      type - the type we want to know how many answers have
      em - the entity manager
      Returns:
      the amount of answers as an int
    • countByTypeAndTag

      public int countByTypeAndTag(long tagID, AnswerType type, javax.persistence.EntityManager em)
      counts how many answers there are per type and tag
      Parameters:
      tagID - the id of the tag we want to look for
      type - the type we want to look for
      em - the entity manager
      Returns:
      the amount of answers per type and tag as int
      Since:
      27.07.2021
    • insert

      public Answer insert(Answer answer)
      Inserts an answer into the Database
      Overrides:
      insert in class DAO<Answer>
      Parameters:
      answer - the Answer which should be stored!
    • remove

      public void remove(long id)
      Removes an object from the database by id
      Overrides:
      remove in class DAO<Answer>
      Parameters:
      id - the id of the object which is going to be removed
    • remove

      public void remove(long id, javax.persistence.EntityManager em)
      removes an Answer from the db, including its results and files. AnsweredQuestions that would return this answer will be marked as UnansweredQuestion
      Overrides:
      remove in class DAO<Answer>
      Parameters:
      id - the id of the answer to delete
      em - the entity manager
    • setFile

      public void setFile(long answerID, long fileID)
      Sets the files of a question
      Parameters:
      answerID - the ID of the answer
      fileID - the ID of the file
    • countAskedAmount

      public Long countAskedAmount(long answerID)
      counts how often an answer has been sent, but without providing an EntityManager. countAskedAmount(long, EntityManager) will be called with the newly created EntityManager
      Parameters:
      answerID - the id of the answer to count how often it has been sent
      Returns:
      the amount of how often the answer has been sent as a Long.
      Since:
      29.08.2021
    • countAskedAmount

      public Long countAskedAmount(long answerID, javax.persistence.EntityManager em)
      counts how often an answer has been sent, while providing an EntityManager.
      Parameters:
      answerID - the id of the answer
      em - the EntityManager
      Returns:
      the amount of how often the answer has been sent as a Long.
      Since:
      29.08.2021