修复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.size = columnMetaRs.getLong("COLUMN_SIZE");
this.isNullable = columnMetaRs.getBoolean("NULLABLE"); this.isNullable = columnMetaRs.getBoolean("NULLABLE");
this.comment = columnMetaRs.getString("REMARKS"); this.remarks = columnMetaRs.getString("REMARKS");
this.columnDef = columnMetaRs.getString("COLUMN_DEF"); this.columnDef = columnMetaRs.getString("COLUMN_DEF");
// 保留小数位数 // 保留小数位数
@ -313,18 +313,18 @@ public class Column implements Serializable, Cloneable {
* *
* @return 注释 * @return 注释
*/ */
public String getComment() { public String getRemarks() {
return comment; return remarks;
} }
/** /**
* 设置注释 * 设置注释
* *
* @param comment 注释 * @param remarks 注释
* @return this * @return this
*/ */
public Column setComment(final String comment) { public Column setRemarks(final String remarks) {
this.comment = comment; this.remarks = remarks;
return this; 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; List<String> result = null;
try (final ResultSet rs = this.raw.getTables(catalog, schema, tableNamePattern, Convert.toStrArray(types))) { try (final ResultSet rs = this.raw.getTables(catalog, schema, tableNamePattern, Convert.toStrArray(types))) {
if (null != rs) { if (null != rs) {
// 初始化结果列表大小为ResultSet的获取大小
result = new ArrayList<>(rs.getFetchSize()); result = new ArrayList<>(rs.getFetchSize());
String table; String table;
// 遍历ResultSet获取每个表的名称
while (rs.next()) { while (rs.next()) {
table = rs.getString("TABLE_NAME"); table = rs.getString("TABLE_NAME");
if (StrUtil.isNotBlank(table)) { if (StrUtil.isNotBlank(table)) {
// 如果表名不为空则添加到结果列表中
result.add(table); result.add(table);
} }
} }
} }
} catch (final SQLException e){ } catch (final SQLException e) {
// 处理SQL异常转换为DbException抛出
throw new DbException(e); throw new DbException(e);
} }
// 返回结果列表如果为空则返回空列表
return CollUtil.emptyIfNull(result); 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) { } catch (final Exception e) {
throw new DbException("Get columns error!", e); throw new DbException("Get columns error!", e);
} }

View File

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