Databases Reference
In-Depth Information
Creating the service implementation
The last step is to modify the
RepositoryContactService
class to use the custom
functionality. This step has the following two phases:
1.
Remove the
buildPageSpecification()
and
sortByLastNameAndFirstNameAsc()
methods.
2.
Modify the
findAllForPage()
and
search()
methods to delegate the
method call forward to our repository.
The source code of the modified methods is given as follows:
@Transactional(readOnly = true)
@Override
public List<Contact> findAllForPage(int pageIndex, int pageSize) {
return repository.findAllForPage(pageIndex, pageSize);
}
@Transactional(readOnly = true)
@Override
public List<Contact> search(SearchDTO dto) {
return repository.findContactsForPage(dto.getSearchTerm(), dto.
getPageIndex(), dto.getPageSize());
}
What did we just do?
We just moved the pagination and search logic from the
RepositoryContactService
class to the
ContactRepositoryImpl
class and
eliminated the dependency between our service layer and Querydsl. The outcome of
our actions is illustrated in the following diagram: