The Responsibilities of a Persistence Adapter
Let's have a look at what a persistence adapter usually does:
- Takes input
- Maps input into a database format
- Sends input to the database
- Maps database output into an application format
- Returns 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 will talk about strategies without mapping in Chapter 8, Mapping between Boundaries.
Instead of using JPA or another object-relational mapping framework...