Asynchronous fetching
Whenever you consider that you need asynchronous fetching (for instance, a query takes too long to wait for it or multiple queries can run independently of each other (non-atomically)) you can rely on the jOOQ + CompletableFuture
combination. For instance, the following asynchronous operation chains an INSERT
statement, an UPDATE
statement, and a DELETE
statement using the CompletableFuture
API and the threads obtained from the default ForkJoinPool
API (if you are not familiar with this API, then you can consider purchasing the Java Coding Problems book from Packt, which dives deeper into this topic):
@Async public CompletableFuture<Void> insertUpdateDeleteOrder() { return CompletableFuture.supplyAsync(() -> { return ctx.insertInto(ORDER) .values(null, LocalDate.of(2003, 2, 12), LocalDate.of(2003, 3, 1), LocalDate.of(2003, 2, 27), "Shipped"...