Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Created December 24, 2021 12:23
Show Gist options
  • Save GaetanoPiazzolla/b1e3e33467c2ac52cc87c80f22a08038 to your computer and use it in GitHub Desktop.
Save GaetanoPiazzolla/b1e3e33467c2ac52cc87c80f22a08038 to your computer and use it in GitHub Desktop.
JDBC and R2DBC differences in "getAllRows"
// JDBC
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<BookDTO>> getAll() {
UUID uuid = UUID.randomUUID();
log.info("getAll() {} running", uuid);
ResponseEntity<List<BookDTO>> list = ResponseEntity.ok(
this.bookRepository.findAll().stream().
map(mapper::toDto).collect(Collectors.toList()));
log.info("getAll() {} executed", uuid);
return list;
}
// R2DBC
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Flux<BookDTO> getAll() {
return Flux.just(UUID.randomUUID()).flatMap(uuid -> {
log.info("getAll() {} running", uuid);
return this.bookRepository.findAll().
map(mapper::toDto).doFinally((a) -> {
log.info("getAll() {} executed", uuid);
});
});
}
@GaetanoPiazzolla
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment