mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 07:18:23 +08:00
feat(execute): 提供Future类型的操作支持。
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.4.3</version>
|
||||
<version>0.4.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user