Skip to content

Commit

Permalink
AbstractSQLConfig 新增支持把 APIJSON 配置表从业务表所在 schema 隔离出来到单独的 schema;解决 S…
Browse files Browse the repository at this point in the history
…QLConfig 自定义的 idKey 和 userIdKey 在 Structure 中未同步导致自定义值校验不通过;
  • Loading branch information
TommyLemon committed Nov 21, 2020
1 parent 572aeb6 commit cf2bf9a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 14 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>4.2.4</version>
<version>4.2.5</version>
</dependency>


Expand Down Expand Up @@ -53,7 +53,8 @@
<!-- 数据库 JDBC 驱动 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->


<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 <<<<<<<<< -->
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
<<<<<<<<< -->
<dependency>
<groupId>com.github.TommyLemon</groupId>
<artifactId>unitauto-java</artifactId>
Expand All @@ -64,7 +65,8 @@
<artifactId>unitauto-jar</artifactId>
<version>2.5.3</version>
</dependency>
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 >>>>>>>>> -->
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
>>>>>>>>> -->

</dependencies>

Expand Down
21 changes: 12 additions & 9 deletions src/main/java/apijson/framework/APIJSONApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public static void init(boolean shutdownWhenServerError, @NotNull APIJSONCreator
APIJSONParser.APIJSON_CREATOR = creator;
APIJSONController.APIJSON_CREATOR = creator;


System.out.println("\n\n\n开始初始化:权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
try {
APIJSONVerifier.init(shutdownWhenServerError, creator);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("\n完成初始化:权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");



System.out.println("\n\n\n开始初始化:远程函数配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
try {
APIJSONFunctionParser.init(shutdownWhenServerError, creator);
Expand Down Expand Up @@ -110,15 +122,6 @@ public static void init(boolean shutdownWhenServerError, @NotNull APIJSONCreator



System.out.println("\n\n\n开始初始化:权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
try {
APIJSONVerifier.init(shutdownWhenServerError, creator);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("\n完成初始化:权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");


System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 启动完成,试试调用自动化 API 吧 ^_^ >>>>>>>>>>>>>>>>>>>>>>>>\n");
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/apijson/framework/APIJSONConstant.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package apijson.framework;


/**APIJSON 常量类
* @author Lemon
*/
import apijson.JSONResponse;
import apijson.orm.JSONRequest;
import apijson.orm.Visitor;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/apijson/framework/APIJSONCreator.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package apijson.framework;

import apijson.orm.FunctionParser;
Expand All @@ -9,6 +23,7 @@
import apijson.orm.Verifier;
import apijson.orm.VerifierCreator;


/**APIJSON相关创建器
* @author Lemon
*/
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/apijson/framework/APIJSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,18 @@ public void onVerifyContent() throws Exception {
// public int getMaxQueryCount() {
// return 50;
// }

@Override
public String getIdKey(String database, String schema, String table) {
return APIJSONSQLConfig.SIMPLE_CALLBACK.getIdKey(database, schema, table);
}
@Override
public String getUserIdKey(String database, String schema, String table) {
return APIJSONSQLConfig.SIMPLE_CALLBACK.getUserIdKey(database, schema, table);
}
@Override
public Object newId(RequestMethod method, String database, String schema, String table) {
return APIJSONSQLConfig.SIMPLE_CALLBACK.newId(method, database, schema, table);
}

}
22 changes: 20 additions & 2 deletions src/main/java/apijson/framework/APIJSONSQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class APIJSONSQLConfig extends AbstractSQLConfig {
static {
DEFAULT_DATABASE = DATABASE_MYSQL; //TODO 默认数据库类型,改成你自己的
DEFAULT_SCHEMA = "sys"; //TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
// TABLE_KEY_MAP.put(Access.class.getSimpleName(), "apijson_access");

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

}



@Override
public String getDBVersion() {
if (isMySQL()) {
Expand Down Expand Up @@ -179,6 +180,23 @@ public String getDBPassword() {
// return false;
// }

/**获取 APIJSON 配置表所在数据库模式 schema,默认与业务表一块
* @return
*/
public String getConfigSchema() {
return getSchema();
}
/**是否为 APIJSON 配置表
* @return
*/
public boolean isConfigTable() {
return CONFIG_TABLE_LIST.contains(getTable());
}
@Override
public String getSQLSchema() {
String sch = isConfigTable() ? getConfigSchema() : super.getSQLSchema();
return sch == null ? DEFAULT_SCHEMA : sch;
}


@Override
Expand Down

0 comments on commit cf2bf9a

Please sign in to comment.