diff --git a/demo/src/test/java/cc/carm/lib/easysql/EasySQLTest.java b/demo/src/test/java/cc/carm/lib/easysql/EasySQLTest.java index b361946e..39257492 100644 --- a/demo/src/test/java/cc/carm/lib/easysql/EasySQLTest.java +++ b/demo/src/test/java/cc/carm/lib/easysql/EasySQLTest.java @@ -52,6 +52,8 @@ public void onTest() { tests.add(new QueryFunctionTest()); tests.add(new QueryFutureTest()); tests.add(new QueryAsyncTest()); + + tests.add(new TableMetadataTest()); // tests.add(new DeleteTest()); print("准备进行测试..."); diff --git a/demo/src/test/java/cc/carm/lib/easysql/TestHandler.java b/demo/src/test/java/cc/carm/lib/easysql/TestHandler.java index d6480888..17bae5fa 100644 --- a/demo/src/test/java/cc/carm/lib/easysql/TestHandler.java +++ b/demo/src/test/java/cc/carm/lib/easysql/TestHandler.java @@ -4,9 +4,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import java.sql.SQLException; -import java.util.concurrent.ExecutionException; - public abstract class TestHandler { protected static void print(@NotNull String format, Object... params) { @@ -14,7 +11,7 @@ protected static void print(@NotNull String format, Object... params) { } @ApiStatus.OverrideOnly - public abstract void onTest(SQLManager sqlManager) throws SQLException, ExecutionException, InterruptedException; + public abstract void onTest(SQLManager sqlManager) throws Exception; public boolean executeTest(int index, SQLManager sqlManager) { String testName = getClass().getSimpleName(); diff --git a/demo/src/test/java/cc/carm/lib/easysql/tests/TableMetadataTest.java b/demo/src/test/java/cc/carm/lib/easysql/tests/TableMetadataTest.java new file mode 100644 index 00000000..de04c044 --- /dev/null +++ b/demo/src/test/java/cc/carm/lib/easysql/tests/TableMetadataTest.java @@ -0,0 +1,39 @@ +package cc.carm.lib.easysql.tests; + +import cc.carm.lib.easysql.TestHandler; +import cc.carm.lib.easysql.api.SQLManager; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CompletableFuture; + +public class TableMetadataTest extends TestHandler { + + @Override + public void onTest(SQLManager sqlManager) throws Exception { + + print(" 获取数据库中所有的表"); + CompletableFuture> tables = sqlManager.fetchMetadata( + (meta) -> meta.getTables(null, null, "%", new String[]{"TABLE"}), + (rs) -> { + List data = new ArrayList<>(); + while (rs.next()) { + data.add(rs.getString("TABLE_NAME")); + } + return data; + } + ); + print("表名:" + Arrays.toString(tables.get().toArray())); + + print(" 获取数据库中所有的列"); + CompletableFuture> columns = sqlManager.fetchTableMetadata("test%").listColumns(); + print("列名:" + Arrays.toString(columns.get().toArray())); + + print("表是否存在 " + sqlManager.fetchTableMetadata("test_user_info").validateExist().get()); + print("列是否存在 " + sqlManager.fetchTableMetadata("test_user_info").isColumnExists("uid").get()); + + } + +}