mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-09-25 16:13:24 +08:00
Add CacheManage
This commit is contained in:
@ -111,10 +111,10 @@ public class SQLExecutor {
|
||||
executeResult.setHeaderList(headerList);
|
||||
for (int i = 1; i <= col; i++) {
|
||||
headerList.add(Header.builder()
|
||||
.dataType(ai.chat2db.spi.util.JdbcUtils.resolveDataType(
|
||||
resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode())
|
||||
.name(resultSetMetaData.getColumnName(i))
|
||||
.build());
|
||||
.dataType(ai.chat2db.spi.util.JdbcUtils.resolveDataType(
|
||||
resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode())
|
||||
.name(resultSetMetaData.getColumnName(i))
|
||||
.build());
|
||||
}
|
||||
|
||||
// 获取数据信息
|
||||
@ -152,7 +152,6 @@ public class SQLExecutor {
|
||||
return execute(sql, getConnection());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有的数据库
|
||||
*
|
||||
@ -181,7 +180,7 @@ public class SQLExecutor {
|
||||
*/
|
||||
public List<Map<String, String>> schemas(String databaseName, String schemaName) {
|
||||
List<Map<String, String>> schemaList = Lists.newArrayList();
|
||||
if(StringUtils.isEmpty(databaseName) && StringUtils.isEmpty(schemaName)){
|
||||
if (StringUtils.isEmpty(databaseName) && StringUtils.isEmpty(schemaName)) {
|
||||
try (ResultSet resultSet = getConnection().getMetaData().getSchemas()) {
|
||||
if (resultSet != null) {
|
||||
while (resultSet.next()) {
|
||||
@ -192,7 +191,7 @@ public class SQLExecutor {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Get schemas error",e);
|
||||
throw new RuntimeException("Get schemas error", e);
|
||||
}
|
||||
return schemaList;
|
||||
}
|
||||
@ -206,7 +205,7 @@ public class SQLExecutor {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Get schemas error",e);
|
||||
throw new RuntimeException("Get schemas error", e);
|
||||
}
|
||||
return schemaList;
|
||||
}
|
||||
@ -222,11 +221,16 @@ public class SQLExecutor {
|
||||
*/
|
||||
public List<Table> tables(String databaseName, String schemaName, String tableName, String types[]) {
|
||||
List<Table> tables = Lists.newArrayList();
|
||||
int n = 0;
|
||||
try (ResultSet resultSet = getConnection().getMetaData().getTables(databaseName, schemaName, tableName,
|
||||
types)) {
|
||||
types)) {
|
||||
if (resultSet != null) {
|
||||
while (resultSet.next()) {
|
||||
n++;
|
||||
tables.add(buildTable(resultSet));
|
||||
if (n >= 5000) {// 最多只取5000条
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@ -247,7 +251,7 @@ public class SQLExecutor {
|
||||
public List<TableColumn> columns(String databaseName, String schemaName, String tableName, String columnName) {
|
||||
List<TableColumn> tableColumns = Lists.newArrayList();
|
||||
try (ResultSet resultSet = getConnection().getMetaData().getColumns(databaseName, schemaName, tableName,
|
||||
columnName)) {
|
||||
columnName)) {
|
||||
if (resultSet != null) {
|
||||
while (resultSet.next()) {
|
||||
tableColumns.add(buildColumn(resultSet));
|
||||
@ -269,8 +273,9 @@ public class SQLExecutor {
|
||||
*/
|
||||
public List<TableIndex> indexes(String databaseName, String schemaName, String tableName) {
|
||||
List<TableIndex> tableIndices = Lists.newArrayList();
|
||||
try (ResultSet resultSet = getConnection().getMetaData().getIndexInfo(databaseName, schemaName, tableName, false,
|
||||
false)) {
|
||||
try (ResultSet resultSet = getConnection().getMetaData().getIndexInfo(databaseName, schemaName, tableName,
|
||||
false,
|
||||
false)) {
|
||||
List<TableIndexColumn> tableIndexColumns = Lists.newArrayList();
|
||||
|
||||
while (resultSet != null && resultSet.next()) {
|
||||
@ -278,18 +283,18 @@ public class SQLExecutor {
|
||||
}
|
||||
|
||||
tableIndexColumns.stream().filter(c -> c.getIndexName() != null).collect(
|
||||
Collectors.groupingBy(TableIndexColumn::getIndexName)).entrySet()
|
||||
.stream().forEach(entry -> {
|
||||
TableIndex tableIndex = new TableIndex();
|
||||
TableIndexColumn column = entry.getValue().get(0);
|
||||
tableIndex.setName(entry.getKey());
|
||||
tableIndex.setTableName(column.getTableName());
|
||||
tableIndex.setSchemaName(column.getSchemaName());
|
||||
tableIndex.setDatabaseName(column.getDatabaseName());
|
||||
tableIndex.setUnique(!column.getNonUnique());
|
||||
tableIndex.setColumnList(entry.getValue());
|
||||
tableIndices.add(tableIndex);
|
||||
});
|
||||
Collectors.groupingBy(TableIndexColumn::getIndexName)).entrySet()
|
||||
.stream().forEach(entry -> {
|
||||
TableIndex tableIndex = new TableIndex();
|
||||
TableIndexColumn column = entry.getValue().get(0);
|
||||
tableIndex.setName(entry.getKey());
|
||||
tableIndex.setTableName(column.getTableName());
|
||||
tableIndex.setSchemaName(column.getSchemaName());
|
||||
tableIndex.setDatabaseName(column.getDatabaseName());
|
||||
tableIndex.setUnique(!column.getNonUnique());
|
||||
tableIndex.setColumnList(entry.getValue());
|
||||
tableIndices.add(tableIndex);
|
||||
});
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -304,7 +309,7 @@ public class SQLExecutor {
|
||||
* @return
|
||||
*/
|
||||
public List<ai.chat2db.spi.model.Function> functions(String databaseName,
|
||||
String schemaName) {
|
||||
String schemaName) {
|
||||
List<ai.chat2db.spi.model.Function> functions = Lists.newArrayList();
|
||||
try (ResultSet resultSet = getConnection().getMetaData().getFunctions(databaseName, schemaName, null);) {
|
||||
while (resultSet != null && resultSet.next()) {
|
||||
|
Reference in New Issue
Block a user