diff --git a/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java b/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java index 79fe078706..759df23d0c 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java @@ -256,6 +256,49 @@ public Result> getSchemasAndTables(@RequestParam Integer id) { return Result.succeed(databaseService.getSchemasAndTables(id)); } + /** + * get all schemas of database + * + * @param id {@link Integer} + * @return {@link Result}< {@link List}< {@link Schema}>> + */ + @Cacheable(cacheNames = "metadata_schema", key = "#id") + @GetMapping("/getSchemas") + @ApiOperation("Get All Schemas And Tables") + @ApiImplicitParam( + name = "id", + value = "DataBase Id", + required = true, + dataType = "Integer", + paramType = "path", + dataTypeClass = Integer.class, + example = "1") + @SaCheckPermission(PermissionConstants.REGISTRATION_DATA_SOURCE_DETAIL_TREE) + public Result> getSchemas(@RequestParam Integer id) { + return Result.succeed(databaseService.getSchemas(id)); + } + + /** + * get all tables of schema of database + * + * @param id {@link Integer} + * @return {@link Result}< {@link List}< {@link Schema}>> + */ + @GetMapping("/getTables") + @ApiOperation("Get All Schemas And Tables") + @ApiImplicitParam( + name = "id", + value = "DataBase Id", + required = true, + dataType = "Integer", + paramType = "path", + dataTypeClass = Integer.class, + example = "1") + @SaCheckPermission(PermissionConstants.REGISTRATION_DATA_SOURCE_DETAIL_TREE) + public Result> getTables(@RequestParam Integer id, @RequestParam String schemaName) { + return Result.succeed(databaseService.getTables(id, schemaName)); + } + /** * clear cache of schemas and tables * diff --git a/dinky-admin/src/main/java/org/dinky/service/DataBaseService.java b/dinky-admin/src/main/java/org/dinky/service/DataBaseService.java index 73953ff677..e0bbafb54e 100644 --- a/dinky-admin/src/main/java/org/dinky/service/DataBaseService.java +++ b/dinky-admin/src/main/java/org/dinky/service/DataBaseService.java @@ -97,6 +97,22 @@ public interface DataBaseService extends ISuperService { */ List getSchemasAndTables(Integer id); + /** + * get all schemas of database + * + * @param id {@link Integer} + * @return {@link List}< {@link Schema}> + */ + List getSchemas(Integer id); + + /** + * get all tables of schema of database + * @param id {@link Integer} + * @param schemaName {@link String} + * @return {@link List}< {@link Table}> + */ + List getTables(Integer id, String schemaName); + /** * get columns of table * diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/DataBaseServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/DataBaseServiceImpl.java index 725192d4a9..2b5f117613 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/DataBaseServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/DataBaseServiceImpl.java @@ -151,6 +151,26 @@ public List getSchemasAndTables(Integer id) { return schemasAndTables; } + @Override + public List getSchemas(Integer id) { + DataBase dataBase = getById(id); + Asserts.checkNotNull(dataBase, Status.DATASOURCE_NOT_EXIST.getMessage()); + Driver driver = Driver.build(dataBase.getDriverConfig()); + List schemas = driver.listSchemas(); + driver.close(); + return schemas; + } + + @Override + public List
getTables(Integer id, String schemaName) { + DataBase dataBase = getById(id); + Asserts.checkNotNull(dataBase, Status.DATASOURCE_NOT_EXIST.getMessage()); + Driver driver = Driver.build(dataBase.getDriverConfig()); + List
tables = driver.listTables(schemaName); + driver.close(); + return tables; + } + @Override public List listColumns(Integer id, String schemaName, String tableName) { DataBase dataBase = getById(id);