[#5014] Add Query.executeAsync() and executeAsync(Executor)
This commit is contained in:
parent
0806dee1c6
commit
1d50db6017
@ -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}:
|
||||
* <ul>
|
||||
* <li> {@link Delete} : the number of deleted records</li>
|
||||
* <li> {@link Insert} : the number of inserted records</li>
|
||||
* <li> {@link Merge} : the result may have no meaning</li>
|
||||
* <li> {@link Select} : the number of resulting records</li>
|
||||
* <li> {@link Truncate} : the result may have no meaning</li>
|
||||
* <li> {@link Update} : the number of updated records</li>
|
||||
* </ul>
|
||||
*/
|
||||
CompletionStage<Integer> 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}:
|
||||
* <ul>
|
||||
* <li> {@link Delete} : the number of deleted records</li>
|
||||
* <li> {@link Insert} : the number of inserted records</li>
|
||||
* <li> {@link Merge} : the result may have no meaning</li>
|
||||
* <li> {@link Select} : the number of resulting records</li>
|
||||
* <li> {@link Truncate} : the result may have no meaning</li>
|
||||
* <li> {@link Update} : the number of updated records</li>
|
||||
* </ul>
|
||||
*/
|
||||
CompletionStage<Integer> executeAsync(Executor executor);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Whether this query is executable in its current state.
|
||||
* <p>
|
||||
|
||||
@ -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<Q extends Query> extends AbstractQueryPar
|
||||
return delegate.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompletionStage<Integer> executeAsync() {
|
||||
return delegate.executeAsync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompletionStage<Integer> executeAsync(Executor executor) {
|
||||
return delegate.executeAsync(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isExecutable() {
|
||||
return delegate.isExecutable();
|
||||
|
||||
@ -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<Integer> executeAsync() {
|
||||
return CompletableFuture.supplyAsync(this::execute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompletionStage<Integer> 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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user