Вот первый метод:
Код: Выделить всё
@WithTransaction
public Uni modifyWorkplace(Workplace request) {
return workplaceRepository.update("nickname = ?1, version = ?2 where id = ?3",
request.getNickname(),
request.getVersion(),
request.getId())
.onItem().transformToUni(updateCount -> {
return workplaceRepository.findById(request.getId());
})
.onItem().ifNull().failWith(() -> new IllegalArgumentException("Workplace not found"));
}
Код: Выделить всё
@WithSession
@WithTransaction
public Uni modifyWorkplace(Workplace request) {
return workplaceRepository.findById(request.getId())
.chain(existing ->
workplaceRepository.update("nickname = ?1, version = ?2 where id = ?3",
request.getNickname(),
request.getVersion(),
request.getId())
.chain(updateCount -> {
return workplaceRepository.findById(request.getId());
})
)
.onItem().ifNull().failWith(() -> new IllegalArgumentException("Workplace not found"));
}
Код: Выделить всё
@WithSession
@WithTransaction
public Uni modifyWorkplace(Workplace request) {
return workplaceRepository.findById(request.getId())
.onItem()
.ifNotNull()
.transformToUni(existing ->
workplaceRepository.update("nickname = ?1, version = ?2 where id = ?3", request.getNickname(), request.getVersion(), request.getId())
.onItem().transformToUni(updateCount -> {
return workplaceRepository.getSession()
.onItem()
.ifNotNull()
.transformToUni(session -> session.refresh(existing).replaceWith(existing));
})
)
.onItem().ifNull().failWith(() -> new IllegalArgumentException("Workplace not found"));
}
}
- Почему во втором случае всегда возвращаются устаревшие данные?< /li>
Почему использование session.refresh решает эту проблему?
Подробнее здесь: https://stackoverflow.com/questions/793 ... nd-panache