Skip to content

Commit cf2bf9a

Browse files
committed
AbstractSQLConfig 新增支持把 APIJSON 配置表从业务表所在 schema 隔离出来到单独的 schema;解决 SQLConfig 自定义的 idKey 和 userIdKey 在 Structure 中未同步导致自定义值校验不通过;
1 parent 572aeb6 commit cf2bf9a

6 files changed

Lines changed: 83 additions & 14 deletions

File tree

pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>com.github.Tencent</groupId>
2424
<artifactId>APIJSON</artifactId>
25-
<version>4.2.4</version>
25+
<version>4.2.5</version>
2626
</dependency>
2727

2828

@@ -53,7 +53,8 @@
5353
<!-- 数据库 JDBC 驱动 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
5454

5555

56-
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 <<<<<<<<< -->
56+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
57+
<<<<<<<<< -->
5758
<dependency>
5859
<groupId>com.github.TommyLemon</groupId>
5960
<artifactId>unitauto-java</artifactId>
@@ -64,7 +65,8 @@
6465
<artifactId>unitauto-jar</artifactId>
6566
<version>2.5.3</version>
6667
</dependency>
67-
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 >>>>>>>>> -->
68+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
69+
>>>>>>>>> -->
6870

6971
</dependencies>
7072

src/main/java/apijson/framework/APIJSONApplication.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ public static void init(boolean shutdownWhenServerError, @NotNull APIJSONCreator
7070
APIJSONParser.APIJSON_CREATOR = creator;
7171
APIJSONController.APIJSON_CREATOR = creator;
7272

73+
74+
System.out.println("\n\n\n开始初始化:权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
75+
try {
76+
APIJSONVerifier.init(shutdownWhenServerError, creator);
77+
}
78+
catch (Exception e) {
79+
e.printStackTrace();
80+
}
81+
System.out.println("\n完成初始化:权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
82+
83+
84+
7385
System.out.println("\n\n\n开始初始化:远程函数配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
7486
try {
7587
APIJSONFunctionParser.init(shutdownWhenServerError, creator);
@@ -110,15 +122,6 @@ public static void init(boolean shutdownWhenServerError, @NotNull APIJSONCreator
110122

111123

112124

113-
System.out.println("\n\n\n开始初始化:权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
114-
try {
115-
APIJSONVerifier.init(shutdownWhenServerError, creator);
116-
}
117-
catch (Exception e) {
118-
e.printStackTrace();
119-
}
120-
System.out.println("\n完成初始化:权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
121-
122125

123126
System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 启动完成,试试调用自动化 API 吧 ^_^ >>>>>>>>>>>>>>>>>>>>>>>>\n");
124127
}

src/main/java/apijson/framework/APIJSONConstant.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
115
package apijson.framework;
216

17+
18+
/**APIJSON 常量类
19+
* @author Lemon
20+
*/
321
import apijson.JSONResponse;
422
import apijson.orm.JSONRequest;
523
import apijson.orm.Visitor;

src/main/java/apijson/framework/APIJSONCreator.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
115
package apijson.framework;
216

317
import apijson.orm.FunctionParser;
@@ -9,6 +23,7 @@
923
import apijson.orm.Verifier;
1024
import apijson.orm.VerifierCreator;
1125

26+
1227
/**APIJSON相关创建器
1328
* @author Lemon
1429
*/

src/main/java/apijson/framework/APIJSONParser.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,18 @@ public void onVerifyContent() throws Exception {
183183
// public int getMaxQueryCount() {
184184
// return 50;
185185
// }
186+
187+
@Override
188+
public String getIdKey(String database, String schema, String table) {
189+
return APIJSONSQLConfig.SIMPLE_CALLBACK.getIdKey(database, schema, table);
190+
}
191+
@Override
192+
public String getUserIdKey(String database, String schema, String table) {
193+
return APIJSONSQLConfig.SIMPLE_CALLBACK.getUserIdKey(database, schema, table);
194+
}
195+
@Override
196+
public Object newId(RequestMethod method, String database, String schema, String table) {
197+
return APIJSONSQLConfig.SIMPLE_CALLBACK.newId(method, database, schema, table);
198+
}
186199

187200
}

src/main/java/apijson/framework/APIJSONSQLConfig.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class APIJSONSQLConfig extends AbstractSQLConfig {
4242
static {
4343
DEFAULT_DATABASE = DATABASE_MYSQL; //TODO 默认数据库类型,改成你自己的
4444
DEFAULT_SCHEMA = "sys"; //TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
45+
// TABLE_KEY_MAP.put(Access.class.getSimpleName(), "apijson_access");
4546

4647
// 由 APIJSONVerifier.init 方法读取数据库 Access 表来替代手动输入配置
4748
// //表名映射,隐藏真实表名,对安全要求很高的表可以这么做
@@ -79,11 +80,11 @@ public String getUserIdKey(String database, String schema, String table) {
7980
// return null; // return null 则不生成 id,一般用于数据库自增 id
8081
// }
8182
};
82-
83+
8384
}
8485

8586

86-
87+
8788
@Override
8889
public String getDBVersion() {
8990
if (isMySQL()) {
@@ -179,6 +180,23 @@ public String getDBPassword() {
179180
// return false;
180181
// }
181182

183+
/**获取 APIJSON 配置表所在数据库模式 schema,默认与业务表一块
184+
* @return
185+
*/
186+
public String getConfigSchema() {
187+
return getSchema();
188+
}
189+
/**是否为 APIJSON 配置表
190+
* @return
191+
*/
192+
public boolean isConfigTable() {
193+
return CONFIG_TABLE_LIST.contains(getTable());
194+
}
195+
@Override
196+
public String getSQLSchema() {
197+
String sch = isConfigTable() ? getConfigSchema() : super.getSQLSchema();
198+
return sch == null ? DEFAULT_SCHEMA : sch;
199+
}
182200

183201

184202
@Override

0 commit comments

Comments
 (0)