Responsibilities of a persistence adapter
Let’s have a look at what a persistence adapter usually does:
- Takes the input.
- Maps the input into database format.
- Sends the input to the database.
- Maps the database output into application format.
- Returns the output.
The persistence adapter takes input through a port interface. The input model may be a domain entity or an object dedicated to a specific database operation, as specified by the interface.
It then maps the input model to a format it can work with to modify or query the database. In Java projects, we commonly use the Java Persistence API (JPA) to talk to a database, so we might map the input into JPA entity objects that reflect the structure of the database tables. Depending on the context, mapping the input model into JPA entities may be a lot of work for little gain, so we’ll talk about strategies without mapping in Chapter 9, Mapping between Boundaries.
Instead of using JPA...