Created
December 24, 2021 12:23
-
-
Save GaetanoPiazzolla/b1e3e33467c2ac52cc87c80f22a08038 to your computer and use it in GitHub Desktop.
JDBC and R2DBC differences in "getAllRows"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code snippet Related to medium article:
https://blog.devgenius.io/an-epic-tale-comparing-jdbc-and-r2dbc-in-a-real-world-scenario-part-2-2-d908df49651c#823f-8a39553a5cf4