I was wondering if it is possible to execute an async delete or update Query directly with jOOQ.
dslContext.delete(MY_TABLE).where(...).execute();
I was only able to find a method for async fetching in ResultQuery
resultQuery.fetchLater();
Is there an easy way to do this?
Note, that as of jOOQ 3.10, as jOOQ still relies on JDBC, "asynchronous" calls merely delegate the blocking JDBC call to some executor asynchronously, but that executor will still block on the JDBC connection.
Oracle is currently working on a new, truly asynchronous API that complements JDBC. Once that stabilises, jOOQ will adapt to that as well, and will be able to run statements truly asynchronously in the database.
Meanwhile...
jOOQ 3.8 introduced support for Java 8's CompletionStage
. You can now run:
CompletionStage<Integer> completion = ctx.delete(MY_TABLE).where(...).executeAsync();
You can also optionally pass an Executor
to the executeAsync()
method.
One way for you to perform asynchronous querying with jOOQ is by using Java's own concurrency APIs. For instance, you can write the following code:
final Query query = dslContext.delete(MY_TABLE).where(...);
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> future = executor.submit(new Callable<Integer>() {
@Override
public Integer call() {
return query.execute();
}
});
Note that the fetchLater()
method was deprecated with jOOQ 3.2 as of #2581.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With