MyEclipse for Spring
Code Reference: CustomerServiceImpl.java
The service implementation behind the customer screens. This page covers its transaction settings and its calls to the data layer.
CustomerServiceImpl implements the customer service interface and owns the transaction boundary. It calls the data access object, applies the small amount of business logic in the sample and returns plain Java types.
Transaction settings
The class is marked read only at the type level. Write methods override the setting with a read write transaction. This pattern keeps read paths fast and makes writes explicit. Start with one transaction per public write method and widen it only when a use case truly spans several operations.
Business logic
- Normalise. Trim the name and lower case the email before saving.
- Check uniqueness. Reject a save when another record already uses the email.
- Default status. Set a new record to active when no status is supplied.
- Return results. Return the saved record so that the caller can show the assigned key.
Keep the service free of web types. It should not know about requests, sessions or views. That separation lets the same service serve a JSP screen, a GWT client and a scheduled job.