Skip to content

Commit 01d31b5

Browse files
committed
优化日志和注释
1 parent 42ca342 commit 01d31b5

File tree

7 files changed

+51
-51
lines changed

7 files changed

+51
-51
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public <T extends Object> T getArgVal(String path, Class<T> clazz) {
287287
/**根据路径取值
288288
* @param path
289289
* @param clazz
290-
* @param tryAll false-仅当前对象,true-本次请求的全局对象以及 Parser<T, JSONRequest, L> 缓存值
290+
* @param tryAll false-仅当前对象,true-本次请求的全局对象以及 Parser<T, M, L> 缓存值
291291
* @return
292292
* @param <T>
293293
*/
@@ -419,7 +419,7 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> Object
419419
}
420420

421421
if (lang != null && SCRIPT_EXECUTOR_MAP.get(lang) == null) {
422-
throw new ClassNotFoundException("找不到脚本语言 " + lang + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionParser<T, JSONRequest, L> 中注册!");
422+
throw new ClassNotFoundException("找不到脚本语言 " + lang + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionParser<T, M, L> 中注册!");
423423
}
424424

425425
int version = row.get("version") != null ? Integer.parseInt(row.get("version").toString()) : 0;

APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public AbstractObjectParser<T, M, L> setParser(Parser<T, M, L> parser) {
6767
public AbstractObjectParser(@NotNull M request, String parentPath, SQLConfig<T, M, L> arrayConfig
6868
, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
6969
if (request == null) {
70-
throw new IllegalArgumentException(TAG + ".ObjectParser<T, JSONRequest, L> request == null!!!");
70+
throw new IllegalArgumentException(TAG + ".ObjectParser<T, M, L> request == null!!!");
7171
}
7272
this.request = request;
7373
this.parentPath = parentPath;
@@ -201,9 +201,9 @@ public AbstractObjectParser<T, M, L> parse(String name, boolean isReuse) throws
201201
this.table = tentry.getKey();
202202
this.alias = tentry.getValue();
203203

204-
Log.d(TAG, "AbstractObjectParser<T, JSONRequest, L> parentPath = " + parentPath + "; name = " + name + "; table = " + table + "; alias = " + alias);
205-
Log.d(TAG, "AbstractObjectParser<T, JSONRequest, L> type = " + type + "; isTable = " + isTable + "; isArrayMainTable = " + isArrayMainTable);
206-
Log.d(TAG, "AbstractObjectParser<T, JSONRequest, L> isEmpty = " + request.isEmpty() + "; tri = " + tri + "; drop = " + drop);
204+
Log.d(TAG, "AbstractObjectParser<T, M, L> parentPath = " + parentPath + "; name = " + name + "; table = " + table + "; alias = " + alias);
205+
Log.d(TAG, "AbstractObjectParser<T, M, L> type = " + type + "; isTable = " + isTable + "; isArrayMainTable = " + isArrayMainTable);
206+
Log.d(TAG, "AbstractObjectParser<T, M, L> isEmpty = " + request.isEmpty() + "; tri = " + tri + "; drop = " + drop);
207207

208208
breakParse = false;
209209

@@ -390,7 +390,7 @@ else if (_method == PUT && value instanceof List<?> && (whereList == null || whe
390390
@Override
391391
public boolean onParse(@NotNull String key, @NotNull Object value) throws Exception {
392392
if (key.endsWith("@")) { // StringUtil.isPath((String) value)) {
393-
// [] 内主表 position > 0 时,用来生成 SQLConfig<T, JSONRequest, L> 的键值对全都忽略,不解析
393+
// [] 内主表 position > 0 时,用来生成 SQLConfig<T, M, L> 的键值对全都忽略,不解析
394394
if (value instanceof Map<?, ?>) { // key{}@ getRealKey, SQL 子查询对象,JSONRequest -> SQLConfig.getSQL
395395
String replaceKey = key.substring(0, key.length() - 1);
396396

APIJSONORM/src/main/java/apijson/orm/AbstractParser.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
import static apijson.RequestMethod.CRUD;
3434
import static apijson.RequestMethod.GET;
3535

36-
/**Parser<T, JSONRequest, L> for parsing request to JSONRequest
36+
/**Parser<T, M, L> for parsing request to JSONRequest
3737
* @author Lemon
3838
*/
3939
public abstract class AbstractParser<T, M extends Map<String, Object>, L extends List<Object>>
40-
implements Parser<T, M, L>, ParserCreator<T, M, L>, VerifierCreator<T, M, L>, SQLCreator<T, M, L> { //, JSONParser<JSONRequest, L> {
40+
implements Parser<T, M, L>, ParserCreator<T, M, L>, VerifierCreator<T, M, L>, SQLCreator<T, M, L> {
4141
protected static final String TAG = "AbstractParser";
4242

4343
/**
@@ -1098,7 +1098,7 @@ public M getStructure(@NotNull String table, String method, String tag, int vers
10981098

10991099
protected Map<String, ObjectParser<T, M, L>> arrayObjectParserCacheMap = new HashMap<>();
11001100

1101-
// protected SQLConfig<T, JSONRequest, L> itemConfig;
1101+
// protected SQLConfig<T, M, L> itemConfig;
11021102
/**获取单个对象,该对象处于parentObject内
11031103
* @param request parentObject 的 value
11041104
* @param parentPath parentObject 的路径
@@ -1405,7 +1405,7 @@ else if (childKeys.length == 1 && apijson.JSONObject.isTableKey(childKeys[0])) {
14051405
long startTime = System.currentTimeMillis();
14061406

14071407
/* 这里优化了 Table[]: { Table:{} } 这种情况下的性能
1408-
* 如果把 List<Map<String, Object>> 改成 L 来减少以下 addAll 一次复制,则会导致 AbstractSQLExecutor<T, JSONRequest, L> 等其它很多地方 get 要改为 getJSONObject,
1408+
* 如果把 List<Map<String, Object>> 改成 L 来减少以下 addAll 一次复制,则会导致 AbstractSQLExecutor<T, M, L> 等其它很多地方 get 要改为 getJSONObject,
14091409
* 修改类型会导致不兼容旧版依赖 ORM 的项目,而且整体上性能只有特殊情况下性能提升,其它非特殊情况下因为多出很多 instanceof Map<?, ?> 的判断而降低了性能。
14101410
*/
14111411
Map<String, Object> fo = i != 0 || arrTableKey == null ? null : JSON.get(parent, arrTableKey);
@@ -1802,7 +1802,7 @@ else if (join != null){
18021802
// onList.add(table + "." + key + " = " + targetTable + "." + targetKey); // ON User.id = Moment.userId
18031803

18041804
// 保证和 SQLExcecutor 缓存的 Config 里 where 顺序一致,生成的 SQL 也就一致 <<<<<<<<<
1805-
// AbstractSQLConfig.newSQLConfig<T, JSONRequest, L> 中强制把 id, id{}, userId, userId{} 放到了最前面 tableObj.put(key, tableObj.remove(key));
1805+
// AbstractSQLConfig.newSQLConfig<T, M, L> 中强制把 id, id{}, userId, userId{} 放到了最前面 tableObj.put(key, tableObj.remove(key));
18061806

18071807
if (refObj.size() != tableObj.size()) { // 把 key 强制放最前,AbstractSQLExcecutor 中 config.putWhere 也是放尽可能最前
18081808
refObj.putAll(tableObj);
@@ -1814,8 +1814,8 @@ else if (join != null){
18141814
// 保证和 SQLExcecutor 缓存的 Config 里 where 顺序一致,生成的 SQL 也就一致 >>>>>>>>>
18151815
}
18161816

1817-
//拼接多个 SQLConfig<T, JSONRequest, L> 的SQL语句,然后执行,再把结果分别缓存(Moment, User等)到 SQLExecutor<T, JSONRequest, L> 的 cacheMap
1818-
// AbstractSQLConfig<T, JSONRequest, L> config0 = null;
1817+
//拼接多个 SQLConfig<T, M, L> 的SQL语句,然后执行,再把结果分别缓存(Moment, User等)到 SQLExecutor<T, M, L> 的 cacheMap
1818+
// AbstractSQLConfig<T, M, L> config0 = null;
18191819
// String sql = "SELECT " + config0.getColumnString() + " FROM " + config0.getTable() + " INNER JOIN " + targetTable + " ON "
18201820
// + onList.get(0) + config0.getGroupString() + config0.getHavingString() + config0.getOrderString();
18211821

@@ -2091,7 +2091,7 @@ public M executeSQL(SQLConfig<T, M, L> config, boolean isSubquery) throws Except
20912091
else {
20922092
sqlExecutor = getSQLExecutor();
20932093
result = sqlExecutor.execute(config, false);
2094-
// FIXME 改为直接在 sqlExecutor 内加好,最后 Parser<T, JSONRequest, L> 取结果,可以解决并发执行导致内部计算出错
2094+
// FIXME 改为直接在 sqlExecutor 内加好,最后 Parser<T, M, L> 取结果,可以解决并发执行导致内部计算出错
20952095
// executedSQLDuration += sqlExecutor.getExecutedSQLDuration() + sqlExecutor.getSqlResultDuration();
20962096
}
20972097

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ public String gainGroupString(boolean hasPrefix) {
15911591

15921592
for (int i = 0; i < keys.length; i++) {
15931593
if (isPrepared()) {
1594-
// 不能通过 ? 来代替,因为SQLExecutor<T, JSONRequest, L> statement.setString后 GROUP BY 'userId' 有单引号,只能返回一条数据,必须去掉单引号才行!
1594+
// 不能通过 ? 来代替,因为SQLExecutor<T, M, L> statement.setString后 GROUP BY 'userId' 有单引号,只能返回一条数据,必须去掉单引号才行!
15951595
if (StringUtil.isName(keys[i]) == false) {
15961596
throw new IllegalArgumentException("@group:value 中 value里面用 , 分割的每一项都必须是1个单词!并且不要有空格!");
15971597
}
@@ -2239,7 +2239,7 @@ public String gainColumnString(boolean inSQLJoin) throws Exception {
22392239
for (String c : column) {
22402240
if (containRaw) {
22412241
// 由于 HashMap 对 key 做了 hash 处理,所以 get 比 containsValue 更快
2242-
if ("".equals(RAW_MAP.get(c)) || RAW_MAP.containsValue(c)) { // newSQLConfig<T, JSONRequest, L> 提前处理好的
2242+
if ("".equals(RAW_MAP.get(c)) || RAW_MAP.containsValue(c)) { // newSQLConfig<T, M, L> 提前处理好的
22432243
//排除@raw中的值,以避免使用date_format(date,'%Y-%m-%d %H:%i:%s') 时,冒号的解析出错
22442244
//column.remove(c);
22452245
continue;
@@ -2385,7 +2385,7 @@ public String gainColumnString(boolean inSQLJoin) throws Exception {
23852385
String expression = keys[i]; //fun(arg0,arg1,...)
23862386

23872387
if (containRaw) { // 由于 HashMap 对 key 做了 hash 处理,所以 get 比 containsValue 更快
2388-
if ("".equals(RAW_MAP.get(expression)) || RAW_MAP.containsValue(expression)) { // newSQLConfig<T, JSONRequest, L> 提前处理好的
2388+
if ("".equals(RAW_MAP.get(expression)) || RAW_MAP.containsValue(expression)) { // newSQLConfig<T, M, L> 提前处理好的
23892389
continue;
23902390
}
23912391

@@ -2394,7 +2394,7 @@ public String gainColumnString(boolean inSQLJoin) throws Exception {
23942394
String alias = expression.substring(index+1);
23952395
boolean hasAlias = StringUtil.isName(alias);
23962396
String pre = index > 0 && hasAlias ? expression.substring(0, index) : expression;
2397-
if (RAW_MAP.containsValue(pre) || "".equals(RAW_MAP.get(pre))) { // newSQLConfig<T, JSONRequest, L> 提前处理好的
2397+
if (RAW_MAP.containsValue(pre) || "".equals(RAW_MAP.get(pre))) { // newSQLConfig<T, M, L> 提前处理好的
23982398
keys[i] = pre + (hasAlias ? getAs() + q + alias + q : "");
23992399
continue;
24002400
}
@@ -2685,7 +2685,7 @@ else if ("!=null".equals(ck)) {
26852685
origin = parseArgsSplitWithSpace(mkes);
26862686
} else {
26872687
String mk = RAW_MAP.get(origin);
2688-
if (mk != null) { // newSQLConfig<T, JSONRequest, L> 提前处理好的
2688+
if (mk != null) { // newSQLConfig<T, M, L> 提前处理好的
26892689
if (mk.length() > 0) {
26902690
origin = mk;
26912691
}
@@ -2750,7 +2750,7 @@ private String parseArgsSplitWithSpace(String[] mkes) {
27502750
String origin = mkes[j];
27512751

27522752
String mk = RAW_MAP.get(origin);
2753-
if (mk != null) { // newSQLConfig<T, JSONRequest, L> 提前处理好的
2753+
if (mk != null) { // newSQLConfig<T, M, L> 提前处理好的
27542754
if (mk.length() > 0) {
27552755
mkes[j] = mk;
27562756
}
@@ -3612,7 +3612,7 @@ else if (c == ')') {
36123612
}
36133613
else if (StringUtil.isNotEmpty(andCond, true)) { // andCond 必须放后面,否则 prepared 值顺序错误
36143614
if (isHaving) {
3615-
// HAVING 前 WHERE 已经有条件 ? 占位,不能反过来,想优化 AND 连接在最前,需要多遍历一次内部的 key,也可以 newSQLConfig<T, JSONRequest, L> 时存到 andList
3615+
// HAVING 前 WHERE 已经有条件 ? 占位,不能反过来,想优化 AND 连接在最前,需要多遍历一次内部的 key,也可以 newSQLConfig<T, M, L> 时存到 andList
36163616
result = "( " + result + " )" + AND + andCond;
36173617
}
36183618
else {
@@ -4463,7 +4463,7 @@ else if (isPrepared() && (c.contains("--") || PATTERN_RANGE.matcher(c).matches()
44634463
return gainCondition(logic.isNot(), condition);
44644464
}
44654465
else if (range instanceof Subquery) {
4466-
// 如果在 Parser<T, JSONRequest, L> 解析成 SQL 字符串再引用,没法保证安全性,毕竟可以再通过远程函数等方式来拼接再替代,最后引用的字符串就能注入
4466+
// 如果在 Parser<T, M, L> 解析成 SQL 字符串再引用,没法保证安全性,毕竟可以再通过远程函数等方式来拼接再替代,最后引用的字符串就能注入
44674467
return gainKey(k) + (logic.isNot() ? NOT : "") + " IN " + gainSubqueryString((Subquery) range);
44684468
}
44694469

@@ -4919,7 +4919,7 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> String
49194919

49204920
// TODO procedure 改为 List<Procedure> procedureList; behind : true; function: callFunction(); String key; ...
49214921
// for (...) { Call procedure1();\n SQL \n; Call procedure2(); ... }
4922-
// 貌似不需要,因为 ObjectParser<T, JSONRequest, L> 里就已经处理的顺序等,只是这里要解决下 Schema 问题。
4922+
// 貌似不需要,因为 ObjectParser<T, M, L> 里就已经处理的顺序等,只是这里要解决下 Schema 问题。
49234923

49244924
String procedure = config.getProcedure();
49254925
if (StringUtil.isNotEmpty(procedure, true)) {
@@ -5445,7 +5445,7 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> SQLConf
54455445
RequestMethod method, String table, String alias
54465446
, M request, List<Join<T, M, L>> joinList, boolean isProcedure, Callback<T, M, L> callback) throws Exception {
54475447
if (request == null) { // User:{} 这种空内容在查询时也有效
5448-
throw new NullPointerException(TAG + ": newSQLConfig<T, JSONRequest, L> request == null!");
5448+
throw new NullPointerException(TAG + ": newSQLConfig<T, M, L> request == null!");
54495449
}
54505450

54515451
Boolean explain = getBoolean(request, KEY_EXPLAIN);
@@ -5502,7 +5502,7 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> SQLConf
55025502
}
55035503
}
55045504
if (newIdIn.isEmpty()) {
5505-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> idIn instanceof List >> 去掉无效 id 后 newIdIn.isEmpty()");
5505+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> idIn instanceof List >> 去掉无效 id 后 newIdIn.isEmpty()");
55065506
}
55075507
idIn = newIdIn;
55085508

@@ -5519,12 +5519,12 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> SQLConf
55195519
if (id != null) { // null 无效
55205520
if (id instanceof Number) {
55215521
if (((Number) id).longValue() <= 0) { // 一定没有值
5522-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> " + table + ".id <= 0");
5522+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> " + table + ".id <= 0");
55235523
}
55245524
}
55255525
else if (id instanceof String) {
55265526
if (StringUtil.isEmpty(id, true)) { // 一定没有值
5527-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> StringUtil.isEmpty(" + table + ".id, true)");
5527+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> StringUtil.isEmpty(" + table + ".id, true)");
55285528
}
55295529
}
55305530
else if (id instanceof Subquery) {}
@@ -5542,7 +5542,7 @@ else if (id instanceof Subquery) {}
55425542
}
55435543
}
55445544
if (contains == false) { // empty有效 BaseModel.isEmpty(idIn) == false) {
5545-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> idIn != null && (((List<?>) idIn).contains(id) == false");
5545+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> idIn != null && (((List<?>) idIn).contains(id) == false");
55465546
}
55475547
}
55485548

@@ -5564,7 +5564,7 @@ else if (id instanceof Subquery) {}
55645564
}
55655565
}
55665566
if (newUserIdIn.isEmpty()) {
5567-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> userIdIn instanceof List >> 去掉无效 userId 后 newIdIn.isEmpty()");
5567+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> userIdIn instanceof List >> 去掉无效 userId 后 newIdIn.isEmpty()");
55685568
}
55695569
userIdIn = newUserIdIn;
55705570
}
@@ -5573,12 +5573,12 @@ else if (id instanceof Subquery) {}
55735573
if (userId != null) { // null 无效
55745574
if (userId instanceof Number) {
55755575
if (((Number) userId).longValue() <= 0) { // 一定没有值
5576-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> " + table + ".userId <= 0");
5576+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> " + table + ".userId <= 0");
55775577
}
55785578
}
55795579
else if (userId instanceof String) {
55805580
if (StringUtil.isEmpty(userId, true)) { // 一定没有值
5581-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> StringUtil.isEmpty(" + table + ".userId, true)");
5581+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> StringUtil.isEmpty(" + table + ".userId, true)");
55825582
}
55835583
}
55845584
else if (userId instanceof Subquery) {}
@@ -5596,7 +5596,7 @@ else if (userId instanceof Subquery) {}
55965596
}
55975597
}
55985598
if (contains == false) { // empty有效 BaseModel.isEmpty(userIdIn) == false) {
5599-
throw new NotExistException(TAG + ": newSQLConfig<T, JSONRequest, L> userIdIn != null && (((List<?>) userIdIn).contains(userId) == false");
5599+
throw new NotExistException(TAG + ": newSQLConfig<T, M, L> userIdIn != null && (((List<?>) userIdIn).contains(userId) == false");
56005600
}
56015601
}
56025602
}
@@ -5737,7 +5737,7 @@ else if (userId instanceof Subquery) {}
57375737

57385738
if (values == null || values.length != columns.length) {
57395739
throw new Exception("服务器内部错误:\n" + TAG
5740-
+ " newSQLConfig<T, JSONRequest, L> values == null || values.length != columns.length !");
5740+
+ " newSQLConfig<T, M, L> values == null || values.length != columns.length !");
57415741
}
57425742

57435743
column = (id == null ? "" : idKey + ",") + (userId == null ? "" : userIdKey + ",")
@@ -5899,7 +5899,7 @@ else if (w.startsWith("!")) {
58995899

59005900
// 可重写回调方法自定义处理 // 动态设置的场景似乎很少,而且去掉后不方便用户排错!
59015901
// 去掉判断,有时候不在没关系,如果是对增删改等非开放请求强制要求传对应的条件,可以用 Operation.NECESSARY
5902-
if (request.containsKey(w) == false) { // 和 request.get(w) == null 没区别,前面 Parser<T, JSONRequest, L> 已经过滤了 null
5902+
if (request.containsKey(w) == false) { // 和 request.get(w) == null 没区别,前面 Parser<T, M, L> 已经过滤了 null
59035903
// throw new IllegalArgumentException(table + ":{} 里的 @combine:value 中的value里 " + ws[i] + " 对应的 " + w + " 不在它里面!");
59045904
callback.onMissingKey4Combine(table, request, combine, ws[i], w);
59055905
if (config instanceof AbstractSQLConfig) {
@@ -6269,7 +6269,7 @@ public static <T, M extends Map<String, Object>, L extends List<Object>> SQLConf
62696269
boolean isQuery = RequestMethod.isQueryMethod(method);
62706270
config.setKeyPrefix(isQuery && config.isMain() == false);
62716271

6272-
//TODO 解析出 SQLConfig<T, JSONRequest, L> 再合并 column, order, group 等
6272+
//TODO 解析出 SQLConfig<T, M, L> 再合并 column, order, group 等
62736273
if (joinList == null || joinList.isEmpty() || RequestMethod.isQueryMethod(method) == false) {
62746274
return config;
62756275
}
@@ -6519,7 +6519,7 @@ public static interface IdCallback<T> {
65196519
}
65206520

65216521
public static interface Callback<T, M extends Map<String, Object>, L extends List<Object>> extends IdCallback<T> {
6522-
/**获取 SQLConfig<T, JSONRequest, L> 的实例
6522+
/**获取 SQLConfig<T, M, L> 的实例
65236523
* @param method
65246524
* @param database
65256525
* @param schema

0 commit comments

Comments
 (0)