MyEclipse for Spring
Code Reference: CustomerDaoImpl.java
The data access implementation behind the customer service, showing how a persistence template is used for reads and writes.
CustomerDaoImpl implements the customer data access interface. It is the only class in the sample that talks to the persistence template. Everything above it works with plain Java types, which keeps the service layer free of persistence details.
Methods
- findById. Reads one record by key and returns null when no row matches.
- findAll. Reads every record ordered by name.
- findByEmail. Reads one record by the unique email value.
- save. Creates or updates a record and returns the managed instance.
- delete. Removes a record by key and returns the number of affected rows.
Template usage
Each method is a short call to the template. Reads pass a query and a row mapper. Writes pass the entity. No method contains business logic, and none opens a transaction. The transaction boundary belongs to the service layer, which is one level up.
The class is generated. If the project needs a hand written query, add it to the model as a named query so that it is regenerated with the rest of the layer.