Skip to content

Commit

Permalink
feat(future): 提供更方便的executeFuture使用方法。
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Aug 10, 2022
1 parent ce088a7 commit d92a752
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
17 changes: 16 additions & 1 deletion api/src/main/java/cc/carm/lib/easysql/api/SQLAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;

Expand Down Expand Up @@ -207,7 +208,21 @@ default void executeAsync(@Nullable SQLHandler<T> success) {
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();
Expand Down
2 changes: 1 addition & 1 deletion demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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> {
Expand Down Expand Up @@ -95,7 +94,7 @@ public void executeAsync(SQLHandler<T> success, SQLExceptionHandler failure) {
}

@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;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion with-pool/beecp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion with-pool/hikaricp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit d92a752

Please sign in to comment.