1
mirror of https://github.com/CarmJos/EasySQL.git synced 2024-09-19 21:35:47 +00:00

feat(future): 提供更方便的executeFuture使用方法。

This commit is contained in:
Carm Jos 2022-08-10 20:16:48 +08:00
parent ce088a72a7
commit d92a752239
8 changed files with 23 additions and 9 deletions

View File

@ -5,7 +5,7 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<version>0.4.4</version>
<version>0.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -12,6 +12,7 @@ import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ -207,7 +208,21 @@ public interface SQLAction<T> {
void executeAsync(@Nullable SQLHandler<T> success,
@Nullable SQLExceptionHandler failure);
<R> @NotNull Future<R> executeFuture(@NotNull SQLFunction<T, R> handler);
/**
* 以异步Future方式执行SQL语句
*
* @return 异步执行的Future实例可通过 {@link Future#get()} 阻塞并等待结果
*/
default @NotNull CompletableFuture<Void> executeFuture() {
return executeFuture((t -> null));
}
/**
* 以异步Future方式执行SQL语句
*
* @return 异步执行的Future实例可通过 {@link Future#get()} 阻塞并等待结果
*/
<R> @NotNull CompletableFuture<R> executeFuture(@NotNull SQLFunction<T, R> handler);
default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) {
if (handler == null) handler = defaultExceptionHandler();

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.4</version>
<version>0.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.4</version>
<version>0.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -12,7 +12,6 @@ import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public abstract class AbstractSQLAction<T> implements SQLAction<T> {
@ -95,7 +94,7 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
}
@Override
public @NotNull <R> Future<R> executeFuture(@NotNull SQLFunction<T, R> handler) {
public @NotNull <R> CompletableFuture<R> executeFuture(@NotNull SQLFunction<T, R> handler) {
CompletableFuture<R> future = new CompletableFuture<>();
executeAsync((t -> future.complete(handler.apply(t))), (e, q) -> future.completeExceptionally(e));
return future;

View File

@ -19,7 +19,7 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<packaging>pom</packaging>
<version>0.4.4</version>
<version>0.4.5</version>
<modules>
<module>api</module>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.4</version>
<version>0.4.5</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.4</version>
<version>0.4.5</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>