Purpose

We've covered a lot of Spring Boot elements. In this commit, a number of these have been applied to support the persistence of trustee data to the database.

Use this opportunity to review code without explanation. Record any doubts, questions or bug reports that are raised by this.

Change of id of trustee

In this example, we've changed the id of the Trustee domain object from a UUID to a Long which will be incremented by the database. This is purely for consistency purposes, but it does have slight ripple effect through the codebase.

Using SQL

Most of the work is done in the repository class. Since charities and trustees are related at the domain level, we choose the save trustees to the database by updating the domain objects and then saving the charity. Any changes to the trustees are saved when the charity is saved.

You can see this being done by looking at the saveCharity() method.

Using Joins

In the findByAcronymWithTrustees method, the query does a join across the charity and trustee tables, and then the results are mapped into a graph of charity and trustee objects. This appears to be more efficient, since we are only running one query to get charity and trustee information. This would be fine if the client (the service) was going to use both charity and trustee data in its invocation. However, that's unlikely to happen at the moment. Indeed, the service layer returns a charity DTO and requires a separate call to get the trustee DTOs.

The code is written this way to illustrate a design point. When writing applications that span layers in your code and that span different models (here OO and relational) thinking about the number of queries to issue and the amount of data to return is an important consideration.

As an exercise, why not cut a branch and try to implement some features in a different way?

This isn't an instructional tutorial. It's just a signpost to an opportunity for self-evaluation. Reading the code of others is a task that you'll do a lot more than writing your own code. Learning to navigate the changes and follow the dependencies is also a good exercise.