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
    Modifier and Type
    Field
    Description
    private final AnswerDAO
    The instance of AnswerDAO that will be used to perform actions to the DB
    private static final org.apache.logging.log4j.Logger
     
    private final Map<String,List<Answer>>
    The context of the UnitOfWork
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Answer answer)
    Inserts an instance of Answer in the database
    void
    addAll(List<Answer> answerList)
    Inserts a list of answers in the database
    void
    clean(int surveyId, int userId)
    Deletes the registered answers made by the user identified by userId on the survey identified by surveyId.
    void
    commit(int surveyId, int userId)
    Commits the changes made by the user identified by userId on the survey identified by surveyId.
    void
    commitDelete(int surveyId, int userId)
    Deletes the registered answers made by the user identified by userId on the survey identified by surveyId.
    void
    commitInsert(int surveyId, int userId)
    Inserts the registered answers made by the user identified by userId on the survey identified by surveyId.
    void
    commitModify(int surveyId, int userId)
    Modifies the registered answers made by the user identified by userId on the survey identified by surveyId.
    get(int id)
    Finds the answer identified by id in the database
    Returns all answers in the database.
    getSurveyAnswersForUser(int surveyId, int userId)
    Finds all the answers the user created for a survey.
    void
    modify(Answer answer)
    Updates an answer in the database using a new instance of Answer.
    private void
    register(Answer answer, String operation)
    Registers answer on the specified operation.
    void
    Adds answer to the elements to be deleted.
    void
    Adds answer to the elements to be modified.
    void
    Adds answer to the elements to be inserted.
    void
    remove(int id)
    Deletes from the database the answer identified by id.
    void
    remove(Answer answer)
    Deletes answer from the database.
    void
    Deletes all answers in the database.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
    • answerDAO

      private final AnswerDAO answerDAO
      The instance of AnswerDAO that will be used to perform actions to the DB
    • uofContext

      private final Map<String,List<Answer>> uofContext
      The context of the UnitOfWork
  • Constructor Details

    • AnswerRepositoryImpl

      @Autowired public AnswerRepositoryImpl(AnswerDAO answerDAO)
  • Method Details

    • add

      public void add(Answer answer)
      Inserts an instance of Answer in the database
      Parameters:
      answer - an instance of Answer
    • addAll

      public void addAll(List<Answer> answerList)
      Inserts a list of answers in the database
      Parameters:
      answerList - a list of Answers
    • get

      public Answer get(int id) throws NotFoundException
      Finds the answer identified by id in the database
      Specified by:
      get in interface AnswerRepository
      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 by id has been found
      See Also:
    • getSurveyAnswersForUser

      public Iterable<Answer> getSurveyAnswersForUser(int surveyId, int userId)
      Finds all the answers the user created for a survey.
      Specified by:
      getSurveyAnswersForUser in interface AnswerRepository
      Parameters:
      surveyId - the id of the Survey
      userId - the id of the User
      Returns:
      an instance of Answer if there is an answer identified by id, null otherwise
      See Also:
    • getAll

      public Iterable<Answer> getAll()
      Returns all answers in the database.
      Returns:
      a list of Answers
    • remove

      public void remove(int id) throws NotFoundException
      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 by id has been found
    • remove

      public void remove(Answer answer)
      Deletes answer from the database.
      Parameters:
      answer - the answer to be deleted
    • removeAll

      public void removeAll()
      Deletes all answers in the database.
    • modify

      public void modify(Answer answer)
      Updates an answer in the database using a new instance of Answer.
      Parameters:
      answer - the new instance of Answer
    • register

      private void register(Answer answer, String operation)
      Registers answer on the specified operation.
      Parameters:
      answer - the answer to be registered
      operation - the operation to be performed on answer
    • registerNew

      public void registerNew(Answer answer)
      Adds answer to the elements to be inserted.
      Specified by:
      registerNew in interface AnswerRepository
      Specified by:
      registerNew in interface UnitOfWork<Answer>
      Parameters:
      answer - the new Answer
      See Also:
    • registerModified

      public void registerModified(Answer answer)
      Adds answer to the elements to be modified.
      Specified by:
      registerModified in interface AnswerRepository
      Specified by:
      registerModified in interface UnitOfWork<Answer>
      Parameters:
      answer - the answer that will replace the Answer with the same id
      See Also:
    • registerDeleted

      public void registerDeleted(Answer answer)
      Adds answer to the elements to be deleted.
      Specified by:
      registerDeleted in interface AnswerRepository
      Specified by:
      registerDeleted in interface UnitOfWork<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 by userId on the survey identified by surveyId.
      Specified by:
      commit in interface AnswerRepository
      Specified by:
      commit in interface UnitOfWork<Answer>
      Parameters:
      surveyId - the id of the survey
      userId - the id of the user
      See Also:
    • commitInsert

      public void commitInsert(int surveyId, int userId)
      Inserts the registered answers made by the user identified by userId on the survey identified by surveyId.
      Specified by:
      commitInsert in interface AnswerRepository
      Parameters:
      surveyId - the id of the survey
      userId - the id of the user
    • commitModify

      public void commitModify(int surveyId, int userId)
      Modifies the registered answers made by the user identified by userId on the survey identified by surveyId.
      Parameters:
      surveyId - the id of the survey
      userId - the id of the user
    • commitDelete

      public void commitDelete(int surveyId, int userId)
      Deletes the registered answers made by the user identified by userId on the survey identified by surveyId.
      Parameters:
      surveyId - the id of the survey
      userId - the id of the user
    • clean

      public void clean(int surveyId, int userId)
      Deletes the registered answers made by the user identified by userId on the survey identified by surveyId.
      Specified by:
      clean in interface AnswerRepository
      Parameters:
      surveyId - the id of the survey
      userId - the id of the user