mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-14 02:33:34 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d92a752239 | |||
| ce088a72a7 | |||
| 26ab19ec75 | |||
| 198a800196 | |||
| 2ea8f3cfa7 | |||
| 2061dc13bf | |||
| 760235fae8 | |||
| d3036ffe4d |
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<version>0.4.2</version>
|
<version>0.4.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import java.sql.SQLException;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,6 +208,22 @@ public interface SQLAction<T> {
|
|||||||
void executeAsync(@Nullable SQLHandler<T> success,
|
void executeAsync(@Nullable SQLHandler<T> success,
|
||||||
@Nullable SQLExceptionHandler failure);
|
@Nullable SQLExceptionHandler failure);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以异步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) {
|
default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) {
|
||||||
if (handler == null) handler = defaultExceptionHandler();
|
if (handler == null) handler = defaultExceptionHandler();
|
||||||
handler.accept(exception, this);
|
handler.accept(exception, this);
|
||||||
|
|||||||
@@ -125,8 +125,7 @@ public interface SQLTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default @NotNull ReplaceBuilder<PreparedSQLUpdateAction<Integer>> createReplace(@NotNull SQLManager sqlManager) {
|
default @NotNull ReplaceBuilder<PreparedSQLUpdateAction<Integer>> createReplace(@NotNull SQLManager sqlManager) {
|
||||||
return Optional.ofNullable(getSQLManager()).map(this::createReplace)
|
return sqlManager.createReplace(getTableName());
|
||||||
.orElseThrow(() -> new NullPointerException("This table doesn't have a SQLManger."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default @NotNull ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> createReplaceBatch() {
|
default @NotNull ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> createReplaceBatch() {
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.4.2</version>
|
<version>0.4.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||||
<maven.deploy.skip>true</maven.deploy.skip>
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
|
|
||||||
<log4j.version>2.17.2</log4j.version>
|
<log4j.version>2.18.0</log4j.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easysql-demo</artifactId>
|
<artifactId>easysql-demo</artifactId>
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class EasySQLTest {
|
|||||||
tests.add(new SQLUpdateReturnKeysTest());
|
tests.add(new SQLUpdateReturnKeysTest());
|
||||||
tests.add(new QueryCloseTest());
|
tests.add(new QueryCloseTest());
|
||||||
tests.add(new QueryFunctionTest());
|
tests.add(new QueryFunctionTest());
|
||||||
|
tests.add(new QueryFutureTest());
|
||||||
tests.add(new QueryAsyncTest());
|
tests.add(new QueryAsyncTest());
|
||||||
// tests.add(new DeleteTest());
|
// tests.add(new DeleteTest());
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.ApiStatus;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public abstract class TestHandler {
|
public abstract class TestHandler {
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ public abstract class TestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.OverrideOnly
|
@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) {
|
public boolean executeTest(int index, SQLManager sqlManager) {
|
||||||
String testName = getClass().getSimpleName();
|
String testName = getClass().getSimpleName();
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.4.2</version>
|
<version>0.4.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cc.carm.lib.easysql.action;
|
|||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
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.api.function.SQLHandler;
|
||||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -10,6 +11,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
||||||
@@ -91,4 +93,10 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>0.4.2</version>
|
<version>0.4.5</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>api</module>
|
<module>api</module>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.4.2</version>
|
<version>0.4.5</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -79,7 +79,7 @@
|
|||||||
<!--项目地址 https://github.com/Chris2018998/BeeCP -->
|
<!--项目地址 https://github.com/Chris2018998/BeeCP -->
|
||||||
<groupId>com.github.chris2018998</groupId>
|
<groupId>com.github.chris2018998</groupId>
|
||||||
<artifactId>beecp</artifactId>
|
<artifactId>beecp</artifactId>
|
||||||
<version>3.3.6</version>
|
<version>3.3.8</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.4.2</version>
|
<version>0.4.5</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
Reference in New Issue
Block a user