修复Oracle下特殊表名导致meta信息获取不到问题

This commit is contained in:
Looly 2024-04-29 14:06:39 +08:00
parent 3c7377bf0c
commit a1d566b34c
3 changed files with 30 additions and 17 deletions

View File

@ -61,7 +61,7 @@ public class Column implements Serializable, Cloneable {
/**
* 注释
*/
private String comment;
private String remarks;
/**
* 是否自增
*/
@ -135,7 +135,7 @@ public class Column implements Serializable, Cloneable {
this.size = columnMetaRs.getLong("COLUMN_SIZE");
this.isNullable = columnMetaRs.getBoolean("NULLABLE");
this.comment = columnMetaRs.getString("REMARKS");
this.remarks = columnMetaRs.getString("REMARKS");
this.columnDef = columnMetaRs.getString("COLUMN_DEF");
// 保留小数位数
@ -313,18 +313,18 @@ public class Column implements Serializable, Cloneable {
*
* @return 注释
*/
public String getComment() {
return comment;
public String getRemarks() {
return remarks;
}
/**
* 设置注释
*
* @param comment 注释
* @param remarks 注释
* @return this
*/
public Column setComment(final String comment) {
this.comment = comment;
public Column setRemarks(final String remarks) {
this.remarks = remarks;
return this;
}

View File

@ -110,23 +110,35 @@ public class DatabaseMetaDataWrapper extends SimpleWrapper<DatabaseMetaData> {
}
}
public List<String> getTableNames(final String tableNamePattern, final TableType... types){
/**
* 获取符合指定模式的表名称列表
*
* @param tableNamePattern 表名模式用于匹配表名
* @param types 表类型数组可选指定要查询的表的类型
* @return 包含匹配表名的列表如果没有匹配的表则返回空列表
*/
public List<String> getTableNames(final String tableNamePattern, final TableType... types) {
List<String> result = null;
try (final ResultSet rs = this.raw.getTables(catalog, schema, tableNamePattern, Convert.toStrArray(types))) {
if (null != rs) {
// 初始化结果列表大小为ResultSet的获取大小
result = new ArrayList<>(rs.getFetchSize());
String table;
// 遍历ResultSet获取每个表的名称
while (rs.next()) {
table = rs.getString("TABLE_NAME");
if (StrUtil.isNotBlank(table)) {
// 如果表名不为空则添加到结果列表中
result.add(table);
}
}
}
} catch (final SQLException e){
} catch (final SQLException e) {
// 处理SQL异常转换为DbException抛出
throw new DbException(e);
}
// 返回结果列表如果为空则返回空列表
return CollUtil.emptyIfNull(result);
}
@ -247,7 +259,7 @@ public class DatabaseMetaDataWrapper extends SimpleWrapper<DatabaseMetaData> {
}
}
}
return (CollUtil.isEmpty(columnNames)) ? new String[0] :columnNames.toArray(new String[0]);
return (CollUtil.isEmpty(columnNames)) ? new String[0] : columnNames.toArray(new String[0]);
} catch (final Exception e) {
throw new DbException("Get columns error!", e);
}

View File

@ -65,7 +65,7 @@ public class MetaUtil {
* 获得所有表名
*
* @param ds 数据源
* @param schema 表数据库名对于Oracle为用户名
* @param schema 要使用的数据库模式在某些数据库系统中相当于命名空间对于Oracle为用户名
* @param types 表类型
* @return 表名列表
* @since 3.3.1
@ -78,13 +78,13 @@ public class MetaUtil {
* 获得所有表名
*
* @param ds 数据源
* @param schema 表数据库名对于Oracle为用户名
* @param tableNamePattern 表名匹配模式
* @param schema 要使用的数据库模式在某些数据库系统中相当于命名空间对于Oracle为用户名
* @param tableNamePattern 表名匹配模式null表示匹配所有表
* @param types 表类型
* @return 表名列表
* @since 3.3.1
*/
public static List<String> getTableNames(final DataSource ds, String schema, final String tableNamePattern, final TableType... types) {
public static List<String> getTableNames(final DataSource ds, final String schema, final String tableNamePattern, final TableType... types) {
return getTableNames(ds, null, schema, tableNamePattern, types);
}
@ -92,8 +92,9 @@ public class MetaUtil {
* 获得所有表名
*
* @param ds 数据源
* @param schema 表数据库名对于Oracle为用户名
* @param tableNamePattern 表名匹配模式
* @param catalog 要使用的数据库目录在某些数据库系统中相当于数据库名称
* @param schema 要使用的数据库模式在某些数据库系统中相当于命名空间对于Oracle为用户名
* @param tableNamePattern 表名匹配模式null表示匹配所有表
* @param types 表类型
* @return 表名列表
* @since 3.3.1
@ -104,7 +105,7 @@ public class MetaUtil {
conn = ds.getConnection();
// catalog和schema获取失败默认使用null代替
if(null == schema){
if (null == schema) {
catalog = getCatalog(conn);
}
if (null == schema) {