From 201c078083a4c8aa59e0aa93f24af6ab18728ec8 Mon Sep 17 00:00:00 2001 From: Bill <1594805355@qq.com> Date: Sun, 2 Jun 2024 17:02:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=92=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20TABLE=5FSCHEMA=5FMAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/apijson/orm/AbstractSQLConfig.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index c39fd9d4..8c2339dc 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -130,6 +130,11 @@ public abstract class AbstractSQLConfig implements SQLConfig TABLE_SCHEMA_MAP; + /** * 表名映射,隐藏真实表名,对安全要求很高的表可以这么做 */ @@ -157,6 +162,19 @@ public abstract class AbstractSQLConfig implements SQLConfig\\|\\[\\]\\{\\} /\\.\\+\\-\\*\\^\\?\\(\\)\\$]+$"); + 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 String getSQLSchema() { 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 From c3a3399224b1fed1fb2f7751ae7a62d75086691e Mon Sep 17 00:00:00 2001 From: TommyLemon <1184482681@qq.com> Date: Sun, 2 Jun 2024 17:13:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?getSQLSchema=20=E6=A0=B9=E6=8D=AE=E4=BC=98?= =?UTF-8?q?=E5=85=88=E7=BA=A7=E5=A4=84=E7=90=86=E4=B8=8D=E5=90=8C=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/apijson/orm/AbstractSQLConfig.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index 8c2339dc..6b714e58 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -1323,7 +1323,7 @@ public String getSchema() { @Override public String getSQLSchema() { String table = getTable(); - //强制,避免因为全局默认的 @schema 自动填充进来,导致这几个类的 schema 为 sys 等其它值 + // FIXME 全部默认填充判断是 系统表 则不填充 // 强制,避免因为全局默认的 @schema 自动填充进来,导致这几个类的 schema 为 sys 等其它值 if (Table.TAG.equals(table) || Column.TAG.equals(table)) { return SCHEMA_INFORMATION; //MySQL, PostgreSQL, SQL Server 都有的 } @@ -1338,9 +1338,11 @@ public String getSQLSchema() { return ""; //Oracle, Dameng 的 all_tables, dba_tables 和 all_tab_columns, dba_columns 表好像不属于任何 Schema } - //String sch = getSchema(); - String sch = TABLE_SCHEMA_MAP.get(table); - return sch == null ? DEFAULT_SCHEMA : sch; + String sch = getSchema(); // 前端传参 @schema 优先 + if (sch == null) { + sch = TABLE_SCHEMA_MAP.get(table); // 其次 Access 表 alias 和 schema 配置 + } + return sch == null ? DEFAULT_SCHEMA : sch; // 最后代码默认兜底配置 } @Override public AbstractSQLConfig setSchema(String schema) {