Skip to content

Commit

Permalink
[Optimization][Data Studio]add getSchemas and getTables api (#3735)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxt2015 authored Aug 28, 2024
1 parent 4b0913d commit 63f6318
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,49 @@ public Result<List<Schema>> 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<List<Schema>> 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<List<Table>> getTables(@RequestParam Integer id, @RequestParam String schemaName) {
return Result.succeed(databaseService.getTables(id, schemaName));
}

/**
* clear cache of schemas and tables
*
Expand Down
16 changes: 16 additions & 0 deletions dinky-admin/src/main/java/org/dinky/service/DataBaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ public interface DataBaseService extends ISuperService<DataBase> {
*/
List<Schema> getSchemasAndTables(Integer id);

/**
* get all schemas of database
*
* @param id {@link Integer}
* @return {@link List}< {@link Schema}>
*/
List<Schema> getSchemas(Integer id);

/**
* get all tables of schema of database
* @param id {@link Integer}
* @param schemaName {@link String}
* @return {@link List}< {@link Table}>
*/
List<Table> getTables(Integer id, String schemaName);

/**
* get columns of table
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ public List<Schema> getSchemasAndTables(Integer id) {
return schemasAndTables;
}

@Override
public List<Schema> getSchemas(Integer id) {
DataBase dataBase = getById(id);
Asserts.checkNotNull(dataBase, Status.DATASOURCE_NOT_EXIST.getMessage());
Driver driver = Driver.build(dataBase.getDriverConfig());
List<Schema> schemas = driver.listSchemas();
driver.close();
return schemas;
}

@Override
public List<Table> getTables(Integer id, String schemaName) {
DataBase dataBase = getById(id);
Asserts.checkNotNull(dataBase, Status.DATASOURCE_NOT_EXIST.getMessage());
Driver driver = Driver.build(dataBase.getDriverConfig());
List<Table> tables = driver.listTables(schemaName);
driver.close();
return tables;
}

@Override
public List<Column> listColumns(Integer id, String schemaName, String tableName) {
DataBase dataBase = getById(id);
Expand Down

0 comments on commit 63f6318

Please sign in to comment.