diff --git a/jOOQ/src/main/java/org/jooq/Query.java b/jOOQ/src/main/java/org/jooq/Query.java
index 02db5e5754..c210b58392 100644
--- a/jOOQ/src/main/java/org/jooq/Query.java
+++ b/jOOQ/src/main/java/org/jooq/Query.java
@@ -45,6 +45,9 @@ import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
import org.jooq.conf.ParamType;
import org.jooq.conf.Settings;
@@ -77,6 +80,44 @@ public interface Query extends QueryPart, Attachable , AutoCloseable {
*/
int execute() throws DataAccessException;
+
+
+ /**
+ * Execute the query in a new {@link CompletionStage} that is asynchronously
+ * completed by a task running in the {@link ForkJoinPool#commonPool()}.
+ *
+ * @return A result value, depending on the concrete implementation of
+ * {@link Query}:
+ *
+ * - {@link Delete} : the number of deleted records
+ * - {@link Insert} : the number of inserted records
+ * - {@link Merge} : the result may have no meaning
+ * - {@link Select} : the number of resulting records
+ * - {@link Truncate} : the result may have no meaning
+ * - {@link Update} : the number of updated records
+ *
+ */
+ CompletionStage executeAsync();
+
+ /**
+ * Execute the query in a new {@link CompletionStage} that is asynchronously
+ * completed by a task running in the given executor.
+ *
+ * @return A result value, depending on the concrete implementation of
+ * {@link Query}:
+ *
+ * - {@link Delete} : the number of deleted records
+ * - {@link Insert} : the number of inserted records
+ * - {@link Merge} : the result may have no meaning
+ * - {@link Select} : the number of resulting records
+ * - {@link Truncate} : the result may have no meaning
+ * - {@link Update} : the number of updated records
+ *
+ */
+ CompletionStage executeAsync(Executor executor);
+
+
+
/**
* Whether this query is executable in its current state.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingQuery.java
index 9312e73eeb..10bf06b45c 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingQuery.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingQuery.java
@@ -42,6 +42,8 @@ package org.jooq.impl;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.Executor;
import org.jooq.AttachableInternal;
import org.jooq.Clause;
@@ -133,6 +135,16 @@ abstract class AbstractDelegatingQuery extends AbstractQueryPar
return delegate.execute();
}
+ @Override
+ public final CompletionStage executeAsync() {
+ return delegate.executeAsync();
+ }
+
+ @Override
+ public final CompletionStage executeAsync(Executor executor) {
+ return delegate.executeAsync(executor);
+ }
+
@Override
public final boolean isExecutable() {
return delegate.isExecutable();
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java
index b6d6271ab8..7810386cb3 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java
@@ -60,6 +60,9 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.Executor;
import org.jooq.AttachableInternal;
import org.jooq.Configuration;
@@ -382,6 +385,20 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query, Attacha
}
}
+
+
+ @Override
+ public final CompletionStage executeAsync() {
+ return CompletableFuture.supplyAsync(this::execute);
+ }
+
+ @Override
+ public final CompletionStage executeAsync(Executor executor) {
+ return CompletableFuture.supplyAsync(this::execute, executor);
+ }
+
+
+
/**
* Default implementation to indicate whether this query should close the
* {@link ResultSet} after execution. Subclasses may override this method.