Level 7 - Milestone 6

Milestone 6 - The Repository Layer

In this milestone we will create the repository package, and add a class that will be used to retrieve relevant data for each request.

Before completion of this milestone, students will:

  • Add a repository-layer class for their application
  • Add a method that is called from the service class

Add a Repository Class

Create a packaged named "repository" at the same level as the presentation package. Repository-layer classes are responsible for simply retrieving pristine data which we need to handle a request. Notice that the responsibilities of these classes are very well-defined: the only thing they should do is simply grab the data we need, and return it to the service-layer method from which it was called. There is no real manipulation of the data that takes place at this level.

The @Repository is another stereotype annotation for @Component, however unlike @Service it does provide us with some additional functionality compared to @Component. While the effects of this difference may not be immediately noticeable, the @Repository annotation does allow Spring to catch any specific persistence specific exceptions and rethrow them as one of Spring's unified unchecked exceptions. The significance of that is well beyond the scope of this course, and not something we will ever really need to worry about, but is included here for the sake of completeness.

Next we will simply make the same changes to our repository class that we made previously to the service layer: just move our test method down another level and make sure to call this new method from the service-layer class. Once this is done, we have now gone as far down as we will need to go. We will soon replace the functionality of this new method with code to make request to retrieve actual data, but for now this will allow us to test that the all of our classes are now working together.

Summary of Code Changes for this Milestone

    Cheetah-Search
    • src
      • main
        • java
          • org.jointheleague.level7.cheetah
          • resources
            • application.yml
    • build.gradle