feat: 实现和配置 TABLE_SCHEMA_MAP

This commit is contained in:
Bill 2024-06-02 17:02:21 +08:00
parent 72996e9550
commit 201c078083

View File

@ -130,6 +130,11 @@ public abstract class AbstractSQLConfig<T extends Object> implements SQLConfig<T
public static Pattern PATTERN_RANGE;
public static Pattern PATTERN_FUNCTION;
/**
* SCHEMA 映射
*/
public static Map<String, String> TABLE_SCHEMA_MAP;
/**
* 表名映射隐藏真实表名对安全要求很高的表可以这么做
*/
@ -157,6 +162,19 @@ public abstract class AbstractSQLConfig<T extends Object> implements SQLConfig<T
// TODO 改成更好的正则校验前面为单词中间为操作符后面为值
PATTERN_FUNCTION = Pattern.compile("^[A-Za-z0-9%,:_@&~`!=\\<\\>\\|\\[\\]\\{\\} /\\.\\+\\-\\*\\^\\?\\(\\)\\$]+$");
TABLE_SCHEMA_MAP = new HashMap<>();
TABLE_SCHEMA_MAP.put(Table.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(Column.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(PgClass.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(PgAttribute.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(SysTable.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(SysColumn.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(ExtendedProperty.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(AllTable.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(AllColumn.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(AllTableComment.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_SCHEMA_MAP.put(AllColumnComment.class.getSimpleName(), DEFAULT_SCHEMA);
TABLE_KEY_MAP = new HashMap<>();
TABLE_KEY_MAP.put(Table.class.getSimpleName(), Table.TABLE_NAME);
TABLE_KEY_MAP.put(Column.class.getSimpleName(), Column.TABLE_NAME);
@ -1320,7 +1338,8 @@ public abstract class AbstractSQLConfig<T extends Object> implements SQLConfig<T
return ""; //Oracle, Dameng all_tables, dba_tables all_tab_columns, dba_columns 表好像不属于任何 Schema
}
String sch = getSchema();
//String sch = getSchema();
String sch = TABLE_SCHEMA_MAP.get(table);
return sch == null ? DEFAULT_SCHEMA : sch;
}
@Override