1
mirror of https://github.com/CarmJos/EasySQL.git synced 2026-06-05 09:01:26 +08:00

Compare commits

...

8 Commits

Author SHA1 Message Date
carm d92a752239 feat(future): 提供更方便的executeFuture使用方法。 2022-08-10 20:16:48 +08:00
dependabot[bot] ce088a72a7 chore(deps): bump beecp from 3.3.7 to 3.3.8 (#56)
Bumps [beecp](https://github.com/Chris2018998/BeeCP) from 3.3.7 to 3.3.8.
- [Release notes](https://github.com/Chris2018998/BeeCP/releases)
- [Commits](https://github.com/Chris2018998/BeeCP/compare/3.3.7...BeeCP-3.3.8)

---
updated-dependencies:
- dependency-name: com.github.chris2018998:beecp
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-09 04:11:31 +08:00
carm 26ab19ec75 feat(execute): 提供Future类型的操作支持。 2022-08-05 17:55:44 +08:00
dependabot[bot] 198a800196 chore(deps): bump beecp from 3.3.6 to 3.3.7 (#53)
Bumps [beecp](https://github.com/Chris2018998/Beecp) from 3.3.6 to 3.3.7.
- [Release notes](https://github.com/Chris2018998/Beecp/releases)
- [Commits](https://github.com/Chris2018998/Beecp/compare/3.3.6...3.3.7)

---
updated-dependencies:
- dependency-name: com.github.chris2018998:beecp
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-11 20:26:15 +08:00
carm 2ea8f3cfa7 Merge remote-tracking branch 'origin/master' 2022-07-10 06:50:48 +08:00
carm 2061dc13bf fix(table): 修复 SQLTable#createReplace 方法递归调用异常 2022-07-10 06:50:33 +08:00
carm 760235fae8 chore(deps): bump log4j.version from 2.17.2 to 2.18.0
Merge pull request #52 from CarmJos/dependabot/maven/log4j.version-2.18.0
2022-07-04 17:44:13 +08:00
dependabot[bot] d3036ffe4d chore(deps): bump log4j.version from 2.17.2 to 2.18.0
Bumps `log4j.version` from 2.17.2 to 2.18.0.

Updates `log4j-api` from 2.17.2 to 2.18.0

Updates `log4j-core` from 2.17.2 to 2.18.0

Updates `log4j-slf4j-impl` from 2.17.2 to 2.18.0

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-api
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: org.apache.logging.log4j:log4j-core
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: org.apache.logging.log4j:log4j-slf4j-impl
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-04 08:50:30 +00:00
12 changed files with 71 additions and 11 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<version>0.4.2</version>
<version>0.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -12,6 +12,8 @@ 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;
/**
@@ -206,6 +208,22 @@ public interface SQLAction<T> {
void executeAsync(@Nullable SQLHandler<T> success,
@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) {
if (handler == null) handler = defaultExceptionHandler();
handler.accept(exception, this);
@@ -125,8 +125,7 @@ public interface SQLTable {
}
default @NotNull ReplaceBuilder<PreparedSQLUpdateAction<Integer>> createReplace(@NotNull SQLManager sqlManager) {
return Optional.ofNullable(getSQLManager()).map(this::createReplace)
.orElseThrow(() -> new NullPointerException("This table doesn't have a SQLManger."));
return sqlManager.createReplace(getTableName());
}
default @NotNull ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> createReplaceBatch() {
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.2</version>
<version>0.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -17,7 +17,7 @@
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>true</maven.deploy.skip>
<log4j.version>2.17.2</log4j.version>
<log4j.version>2.18.0</log4j.version>
</properties>
<artifactId>easysql-demo</artifactId>
@@ -50,6 +50,7 @@ public class EasySQLTest {
tests.add(new SQLUpdateReturnKeysTest());
tests.add(new QueryCloseTest());
tests.add(new QueryFunctionTest());
tests.add(new QueryFutureTest());
tests.add(new QueryAsyncTest());
// tests.add(new DeleteTest());
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.sql.SQLException;
import java.util.concurrent.ExecutionException;
public abstract class TestHandler {
@@ -13,7 +14,7 @@ public abstract class TestHandler {
}
@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();
@@ -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
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.2</version>
<version>0.4.5</version>
</parent>
<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.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;
@@ -10,6 +11,7 @@ import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
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;
}
}
+1 -1
View File
@@ -19,7 +19,7 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<packaging>pom</packaging>
<version>0.4.2</version>
<version>0.4.5</version>
<modules>
<module>api</module>
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.2</version>
<version>0.4.5</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -79,7 +79,7 @@
<!--项目地址 https://github.com/Chris2018998/BeeCP -->
<groupId>com.github.chris2018998</groupId>
<artifactId>beecp</artifactId>
<version>3.3.6</version>
<version>3.3.8</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.4.2</version>
<version>0.4.5</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>