Class AnswerDAO
DAO for com.ubs.backend.classes.database.Answer
- Since:
- 17.07.2021
- Author:
- Marc, Tim Irmler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncountAskedAmount(long answerID)counts how often an answer has been sent, but without providing an EntityManager.countAskedAmount(long answerID, javax.persistence.EntityManager em)counts how often an answer has been sent, while providing an EntityManager.intcountByType(AnswerType type, javax.persistence.EntityManager em)Count how many answers there are per typeintcountByTypeAndTag(long tagID, AnswerType type, javax.persistence.EntityManager em)counts how many answers there are per type and tagfloatgetAverageUsefulness(long id, javax.persistence.EntityManager em)calculate average usefulness of an answer by looking at all of its connected tags and their rating.getSingleTempAnswer(long answerID, javax.persistence.EntityManager em)creates a singleTempAnswerfrom anAnswerselected from the DB.Inserts an answer into the Databasevoidremove(long id)Removes an object from the database by idvoidremove(long id, javax.persistence.EntityManager em)removes anAnswerfrom the db, including its results and files.selectByTag(long id, javax.persistence.EntityManager em)selectByType(AnswerType type)Select all answers with a set TypeselectByType(AnswerType type, javax.persistence.EntityManager em)Select all answers with a set Type with a preset EntityManagerselectByTypeAndTag(long tagID, AnswerType type, javax.persistence.EntityManager em)Method to select a List of everyAnswerwith a certain type and tagselectRandomByType(AnswerType type, int max)selectRandomByType(AnswerType type, int max, javax.persistence.EntityManager em)selectStatistikByTime(boolean createIfNotExists, long answerID, StatistikTimes statistikTimes, javax.persistence.EntityManager em)voidsetFile(long answerID, long fileID)Sets the files of a questionvoidAdds a view to an answervoidincreases the view count of an answer
-
Constructor Details
-
AnswerDAO
public AnswerDAO()the default constructor
-
-
Method Details
-
view
Adds a view to an answer- Parameters:
answer- the answer which should receive a view
-
view
increases the view count of an answer- Parameters:
answer- the answer which should receive a viewem- the entity manager- Since:
- 02.09.2021
-
selectStatistikByTime
public AnswerStatistik selectStatistikByTime(boolean createIfNotExists, long answerID, StatistikTimes statistikTimes, javax.persistence.EntityManager em)selects the currentAnswerStatistikof the specifiedAnswerin the specifiedStatistikTimes. If the answer has no Statistics for the specifiedStatistikTimes, the method can, if wanted, create it.- Parameters:
createIfNotExists- defines if anAnswerStatistikshould be created if it does not exist.answerID- the id of theAnswerwhere we want to find aAnswerStatistikstatistikTimes- the specified time in which we want to have the statisticsem- the entity manager- Returns:
- the found
AnswerStatistik. Returns null if nothing was found. - Since:
- 29.08.2021
-
selectByTag
-
selectRandomByType
Selects a list ofAnswers containing randomAnswers from the DB that all have a specific type, but without specifying an EntityManager.- Parameters:
type- theAnswerTypeof the Answermax- defines how manyAnswers 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)- Parameters:
type- theAnswerTypeof the Answermax- defines how manyAnswers the list can contain maximumem- the entity manager- Returns:
- the list of
Answers - Since:
- 20.07.2021
-
getSingleTempAnswer
creates a singleTempAnswerfrom anAnswerselected from the DB.- Parameters:
answerID- the id of the answer from which theTempAnswerwill be createdem- 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 answerem- 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 everyAnswerwith a certain type and tag- Parameters:
tagID- the id of the tag we're looking fortype- the type of the answer we're looking forem- the entity manager- Returns:
- a List of every
Answerwith a certain type and tag - Since:
- 28.07.2021
-
selectByType
Select all answers with a set Type with a preset EntityManager- Parameters:
type- the type which we want to answers to containem- the EntityManager which we will use- Returns:
- a list of all answers with the set type
-
selectByType
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
Count how many answers there are per type- Parameters:
type- the type we want to know how many answers haveem- the entity manager- Returns:
- the amount of answers as an int
-
countByTypeAndTag
counts how many answers there are per type and tag- Parameters:
tagID- the id of the tag we want to look fortype- the type we want to look forem- the entity manager- Returns:
- the amount of answers per type and tag as int
- Since:
- 27.07.2021
-
insert
Inserts an answer into the Database -
remove
public void remove(long id)Removes an object from the database by id -
remove
public void remove(long id, javax.persistence.EntityManager em)removes anAnswerfrom the db, including its results and files.AnsweredQuestions that would return this answer will be marked asUnansweredQuestion -
setFile
public void setFile(long answerID, long fileID)Sets the files of a question- Parameters:
answerID- the ID of the answerfileID- the ID of the file
-
countAskedAmount
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
counts how often an answer has been sent, while providing an EntityManager.- Parameters:
answerID- the id of the answerem- the EntityManager- Returns:
- the amount of how often the answer has been sent as a Long.
- Since:
- 29.08.2021
-