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 TypeMethodDescriptionvoid
Inserts an instance of Answer in the databasevoid
Inserts a list of answers in the databasevoid
clean
(int surveyId, int userId) Deletes the registered answers made by the user identified byuserId
on the survey identified bysurveyId
.void
commit
(int surveyId, int userId) Commits the changes made by the user identified byuserId
on the survey identified bysurveyId
.void
commitDelete
(int surveyId, int userId) Deletes the registered answers made by the user identified byuserId
on the survey identified bysurveyId
.void
commitInsert
(int surveyId, int userId) Inserts the registered answers made by the user identified byuserId
on the survey identified bysurveyId
.void
commitModify
(int surveyId, int userId) Modifies the registered answers made by the user identified byuserId
on 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.void
Updates an answer in the database using a new instance of Answer.private void
Registersanswer
on the specifiedoperation
.void
registerDeleted
(Answer answer) Addsanswer
to the elements to be deleted.void
registerModified
(Answer answer) Addsanswer
to the elements to be modified.void
registerNew
(Answer answer) Addsanswer
to the elements to be inserted.void
remove
(int id) Deletes from the database the answer identified by id.void
Deletesanswer
from the database.void
Deletes 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:
get
in 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 byid
has been found- See Also:
-
getSurveyAnswersForUser
Finds all the answers the user created for a survey.- Specified by:
getSurveyAnswersForUser
in 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 byid
has been found
-
remove
Deletesanswer
from 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
Registersanswer
on the specifiedoperation
.- Parameters:
answer
- the answer to be registeredoperation
- the operation to be performed on answer
-
registerNew
Addsanswer
to the elements to be inserted.- Specified by:
registerNew
in interfaceAnswerRepository
- Specified by:
registerNew
in interfaceUnitOfWork<Answer>
- Parameters:
answer
- the new Answer- See Also:
-
registerModified
Addsanswer
to the elements to be modified.- Specified by:
registerModified
in interfaceAnswerRepository
- Specified by:
registerModified
in interfaceUnitOfWork<Answer>
- Parameters:
answer
- the answer that will replace the Answer with the same id- See Also:
-
registerDeleted
Addsanswer
to the elements to be deleted.- Specified by:
registerDeleted
in interfaceAnswerRepository
- Specified by:
registerDeleted
in 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 byuserId
on the survey identified bysurveyId
.- Specified by:
commit
in interfaceAnswerRepository
- Specified by:
commit
in 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 byuserId
on the survey identified bysurveyId
.- Specified by:
commitInsert
in 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 byuserId
on 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 byuserId
on 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 byuserId
on the survey identified bysurveyId
.- Specified by:
clean
in interfaceAnswerRepository
- Parameters:
surveyId
- the id of the surveyuserId
- the id of the user
-