Skip to content

Commit

Permalink
Merge pull request #2 from Ghost-chu/CarmJos-master
Browse files Browse the repository at this point in the history
Carm jos master
  • Loading branch information
Ghost-chu authored Aug 9, 2022
2 parents 44ac81c + 9f086fe commit ec9968b
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 8 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>com.ghostchu.fork.cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<version>0.4.3</version>
<version>0.4.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
3 changes: 3 additions & 0 deletions 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.Future;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -206,6 +207,8 @@ 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);

default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) {
if (handler == null) handler = defaultExceptionHandler();
handler.accept(exception, this);
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>com.ghostchu.fork.cc.carm.lib</groupId>
<version>0.4.3</version>
<version>0.4.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
1 change: 1 addition & 0 deletions demo/src/test/java/cc/carm/lib/easysql/EasySQLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void onTest() {
tests.add(new SQLUpdateReturnKeysTest());
tests.add(new QueryCloseTest());
tests.add(new QueryFunctionTest());
tests.add(new QueryFutureTest());
tests.add(new QueryAsyncTest());
// tests.add(new DeleteTest());

Expand Down
3 changes: 2 additions & 1 deletion demo/src/test/java/cc/carm/lib/easysql/TestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jetbrains.annotations.NotNull;

import java.sql.SQLException;
import java.util.concurrent.ExecutionException;

public abstract class TestHandler {

Expand All @@ -13,7 +14,7 @@ protected static void print(@NotNull String format, Object... params) {
}

@ApiStatus.OverrideOnly
public abstract void onTest(SQLManager sqlManager) throws SQLException;
public abstract void onTest(SQLManager sqlManager) throws SQLException, ExecutionException, InterruptedException;

public boolean executeTest(int index, SQLManager sqlManager) {
String testName = getClass().getSimpleName();
Expand Down
33 changes: 33 additions & 0 deletions demo/src/test/java/cc/carm/lib/easysql/tests/QueryFutureTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cc.carm.lib.easysql.tests;

import cc.carm.lib.easysql.TestHandler;
import cc.carm.lib.easysql.api.SQLManager;

import java.sql.SQLException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class QueryFutureTest extends TestHandler {


@Override
public void onTest(SQLManager sqlManager) throws SQLException, ExecutionException, InterruptedException {


Future<Integer> future = sqlManager.createQuery()
.inTable("test_user_table")
.orderBy("id", false)
.setLimit(1)
.build().executeFuture((query) -> {
if (!query.getResultSet().next()) {
return -1;
} else {
return query.getResultSet().getInt("id");
}
});

int id = future.get();
System.out.println("id(future): " + id);

}
}
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>com.ghostchu.fork.cc.carm.lib</groupId>
<version>0.4.3</version>
<version>0.4.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import cc.carm.lib.easysql.api.function.SQLFunction;
import cc.carm.lib.easysql.api.function.SQLHandler;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
Expand All @@ -10,6 +11,8 @@
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> {
Expand Down Expand Up @@ -94,4 +97,10 @@ public void executeAsync(SQLHandler<T> success, SQLExceptionHandler failure) {
});
}

@Override
public @NotNull <R> Future<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;
}
}
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>com.ghostchu.fork.cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<packaging>pom</packaging>
<version>0.4.3</version>
<version>0.4.4</version>

<modules>
<module>api</module>
Expand Down
4 changes: 2 additions & 2 deletions 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>com.ghostchu.fork.cc.carm.lib</groupId>
<version>0.4.3</version>
<version>0.4.4</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -79,7 +79,7 @@
<!--项目地址 https://github.com/Chris2018998/BeeCP -->
<groupId>com.github.chris2018998</groupId>
<artifactId>beecp</artifactId>
<version>3.3.7</version>
<version>3.3.8</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
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>com.ghostchu.fork.cc.carm.lib</groupId>
<version>0.4.3</version>
<version>0.4.4</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down

0 comments on commit ec9968b

Please sign in to comment.