'Handling data deletion in spring data jpa pagination?
I have a method like the below.
public List<ResponseDto> getChanges();
This service returns the result, but it is a stateful method because calling another service A, affects the result of getChangedAccounts() method. For example, I have 30 items in my list, in the normal situation (when the client does not call service A) this method works fine (page number 1 up to 3, with page size 10), but the problem is when the client call service A because it changes the status of entities and that changed record does not return in getChangedAccounts(). So in this scenario for example the first bunch (page no=1 page size=10) has been changed during service A and currently, I have 20 records, so when the client calls (page no=3 page size=10) there is no result, is there any way to keep the page no order but return previous data?
I know about hasPrevious(), but I don't exactly what should I do.
Page<Entity> changedEntities = repository.findChanges(paramA, paramB, pageable);
if (ObjectUtils.isEmpty(changedEntities) || ObjectUtils.isEmpty(changedEntities.getContent())) {
if (changedEntities.getTotalElements() == 0)
throw new NotFoundException("Not found any changes!");
else {
while (changedEntities.hasPrevious()){
Pageable pageable1 = changedEntities.previousPageable();
}
}
}
PageImpl<ResponseDto> responseDtoPage = new PageImpl<>(changedEntities.getContent()
.stream()
.map(ce-> new ResponseDto(ce.getMessageId(), ce.getAccountNumber()))
.collect(Collectors.toList())
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
