Class AnswerRepositoryImpl
java.lang.Object
it.unimib.unimibmodules.repository.AnswerRepositoryImpl
- All Implemented Interfaces:
AnswerRepository,UnitOfWork<Answer>
@Component("answerRepository")
public class AnswerRepositoryImpl
extends Object
implements AnswerRepository, UnitOfWork<Answer>
Repository for the Answers. Adds business logic to Answer instances before actually accessing
the database via DAO.
- Version:
- 0.4.1
- Author:
- Davide Costantini
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts an instance of Answer in the databasevoidInserts a list of answers in the databasevoidclean(int surveyId, int userId) Deletes the registered answers made by the user identified byuserIdon the survey identified bysurveyId.voidcommit(int surveyId, int userId) Commits the changes made by the user identified byuserIdon the survey identified bysurveyId.voidcommitDelete(int surveyId, int userId) Deletes the registered answers made by the user identified byuserIdon the survey identified bysurveyId.voidcommitInsert(int surveyId, int userId) Inserts the registered answers made by the user identified byuserIdon the survey identified bysurveyId.voidcommitModify(int surveyId, int userId) Modifies the registered answers made by the user identified byuserIdon the survey identified bysurveyId.get(int id) Finds the answer identified by id in the databasegetAll()Returns all answers in the database.getSurveyAnswersForUser(int surveyId, int userId) Finds all the answers the user created for a survey.voidUpdates an answer in the database using a new instance of Answer.private voidRegistersansweron the specifiedoperation.voidregisterDeleted(Answer answer) Addsanswerto the elements to be deleted.voidregisterModified(Answer answer) Addsanswerto the elements to be modified.voidregisterNew(Answer answer) Addsanswerto the elements to be inserted.voidremove(int id) Deletes from the database the answer identified by id.voidDeletesanswerfrom the database.voidDeletes all answers in the database.
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
answerDAO
The instance of AnswerDAO that will be used to perform actions to the DB -
uofContext
The context of the UnitOfWork
-
-
Constructor Details
-
AnswerRepositoryImpl
-
-
Method Details
-
add
Inserts an instance of Answer in the database- Parameters:
answer- an instance of Answer
-
addAll
Inserts a list of answers in the database- Parameters:
answerList- a list of Answers
-
get
Finds the answer identified by id in the database- Specified by:
getin interfaceAnswerRepository- Parameters:
id- the id of the answer to be found- Returns:
- an instance of Answer if there is an answer identified by id, null otherwise
- Throws:
NotFoundException- if no answer identified byidhas been found- See Also:
-
getSurveyAnswersForUser
Finds all the answers the user created for a survey.- Specified by:
getSurveyAnswersForUserin interfaceAnswerRepository- Parameters:
surveyId- the id of the SurveyuserId- the id of the User- Returns:
- an instance of Answer if there is an answer identified by id, null otherwise
- See Also:
-
getAll
Returns all answers in the database.- Returns:
- a list of Answers
-
remove
Deletes from the database the answer identified by id.- Parameters:
id- the id of the answer to be deleted- Throws:
NotFoundException- if no answer identified byidhas been found
-
remove
Deletesanswerfrom the database.- Parameters:
answer- the answer to be deleted
-
removeAll
public void removeAll()Deletes all answers in the database. -
modify
Updates an answer in the database using a new instance of Answer.- Parameters:
answer- the new instance of Answer
-
register
Registersansweron the specifiedoperation.- Parameters:
answer- the answer to be registeredoperation- the operation to be performed on answer
-
registerNew
Addsanswerto the elements to be inserted.- Specified by:
registerNewin interfaceAnswerRepository- Specified by:
registerNewin interfaceUnitOfWork<Answer>- Parameters:
answer- the new Answer- See Also:
-
registerModified
Addsanswerto the elements to be modified.- Specified by:
registerModifiedin interfaceAnswerRepository- Specified by:
registerModifiedin interfaceUnitOfWork<Answer>- Parameters:
answer- the answer that will replace the Answer with the same id- See Also:
-
registerDeleted
Addsanswerto the elements to be deleted.- Specified by:
registerDeletedin interfaceAnswerRepository- Specified by:
registerDeletedin interfaceUnitOfWork<Answer>- Parameters:
answer- the answer to be deleted- See Also:
-
commit
public void commit(int surveyId, int userId) Commits the changes made by the user identified byuserIdon the survey identified bysurveyId.- Specified by:
commitin interfaceAnswerRepository- Specified by:
commitin interfaceUnitOfWork<Answer>- Parameters:
surveyId- the id of the surveyuserId- the id of the user- See Also:
-
commitInsert
public void commitInsert(int surveyId, int userId) Inserts the registered answers made by the user identified byuserIdon the survey identified bysurveyId.- Specified by:
commitInsertin interfaceAnswerRepository- Parameters:
surveyId- the id of the surveyuserId- the id of the user
-
commitModify
public void commitModify(int surveyId, int userId) Modifies the registered answers made by the user identified byuserIdon the survey identified bysurveyId.- Parameters:
surveyId- the id of the surveyuserId- the id of the user
-
commitDelete
public void commitDelete(int surveyId, int userId) Deletes the registered answers made by the user identified byuserIdon the survey identified bysurveyId.- Parameters:
surveyId- the id of the surveyuserId- the id of the user
-
clean
public void clean(int surveyId, int userId) Deletes the registered answers made by the user identified byuserIdon the survey identified bysurveyId.- Specified by:
cleanin interfaceAnswerRepository- Parameters:
surveyId- the id of the surveyuserId- the id of the user
-