Skip to content

Commit 5525eab

Browse files
committed
完善对 APP JOIN 同层和跨层的校验;完善对 APP JOIN 的 SQL 执行与缓存次数统计;解决同层 JOIN 新增的报错 bug;解决 APP JOIN 副表返回内部字段 @RAW@LIST;fastjson2 改为 1.2.79
1 parent 104db00 commit 5525eab

File tree

5 files changed

+202
-148
lines changed

5 files changed

+202
-148
lines changed

APIJSONORM/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<dependency>
2222
<groupId>com.alibaba</groupId>
2323
<artifactId>fastjson</artifactId>
24-
<version>2.0.4</version>
24+
<version>1.2.79</version>
2525
</dependency>
2626
<dependency>
2727
<groupId>javax.activation</groupId>

APIJSONORM/src/main/java/apijson/JSON.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
import com.alibaba.fastjson.JSONArray;
88
import com.alibaba.fastjson.JSONObject;
9+
import com.alibaba.fastjson.parser.Feature;
910
import com.alibaba.fastjson.serializer.SerializerFeature;
10-
import com.alibaba.fastjson2.JSONReader;
11+
import com.alibaba.fastjson.JSONReader;
1112

1213
import java.util.List;
1314

@@ -64,10 +65,10 @@ public static String getCorrectJson(String s, boolean isArray) {
6465
* @param json
6566
* @return
6667
*/
67-
private static final JSONReader.Feature[] DEFAULT_FASTJSON_FEATURES = {JSONReader.Feature.FieldBased, JSONReader.Feature.UseBigDecimalForDoubles};
68+
private static final Feature[] DEFAULT_FASTJSON_FEATURES = {Feature.OrderedField, Feature.UseBigDecimal};
6869
public static Object parse(Object obj) {
6970
try {
70-
return com.alibaba.fastjson2.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), DEFAULT_FASTJSON_FEATURES);
71+
return com.alibaba.fastjson.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), DEFAULT_FASTJSON_FEATURES);
7172
} catch (Exception e) {
7273
Log.i(TAG, "parse catch \n" + e.getMessage());
7374
}
@@ -101,7 +102,7 @@ public static <T> T parseObject(String json, Class<T> clazz) {
101102
Log.e(TAG, "parseObject clazz == null >> return null;");
102103
} else {
103104
try {
104-
return com.alibaba.fastjson2.JSON.parseObject(getCorrectJson(json), clazz, DEFAULT_FASTJSON_FEATURES);
105+
return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), clazz, DEFAULT_FASTJSON_FEATURES);
105106
} catch (Exception e) {
106107
Log.i(TAG, "parseObject catch \n" + e.getMessage());
107108
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public AbstractObjectParser setParser(AbstractParser<?> parser) {
7171
* @param parentPath
7272
* @param request
7373
* @param name
74-
* @throws Exception
74+
* @throws Exception
7575
*/
7676
public AbstractObjectParser(@NotNull JSONObject request, String parentPath, SQLConfig arrayConfig
7777
, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
@@ -400,7 +400,7 @@ public boolean onParse(@NotNull String key, @NotNull Object value) throws Except
400400
if (arrObj == null) {
401401
throw new IllegalArgumentException("子查询 " + path + "/" + key + ":{ from:value } 中 value 对应的主表对象 " + from + ":{} 不存在!");
402402
}
403-
//
403+
//
404404
SQLConfig cfg = (SQLConfig) arrObj.get(AbstractParser.KEY_CONFIG);
405405
if (cfg == null) {
406406
throw new NotExistException(TAG + ".onParse cfg == null");
@@ -453,7 +453,7 @@ else if (value instanceof String) { // //key{}@ getRealKey, 引用赋值路径
453453
Log.d(TAG, "onParse isTable(table) == false >> return true;");
454454
return true;//舍去,对Table无影响
455455
}
456-
}
456+
}
457457

458458
//直接替换原来的key@:path为key:target
459459
Log.i(TAG, "onParse >> key = replaceKey; value = target;");
@@ -517,7 +517,7 @@ else if (isTable && key.startsWith("@") && JSONRequest.TABLE_KEY_LIST.contains(k
517517
/**
518518
* @param key
519519
* @param value
520-
* @param isFirst
520+
* @param isFirst
521521
* @return
522522
* @throws Exception
523523
*/
@@ -553,7 +553,7 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
553553
+ "数组 []:{} 中每个 key:{} 都必须是表 TableKey:{} 或 数组 arrayKey[]:{} !");
554554
}
555555

556-
if ( //避免使用 "test":{"Test":{}} 绕过限制,实现查询爆炸 isTableKey &&
556+
if ( //避免使用 "test":{"Test":{}} 绕过限制,实现查询爆炸 isTableKey &&
557557
(arrayConfig == null || arrayConfig.getPosition() == 0)) {
558558
objectCount ++;
559559
int maxObjectCount = parser.getMaxObjectCount();
@@ -577,7 +577,7 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
577577

578578

579579

580-
//TODO 改用 MySQL json_add,json_remove,json_contains 等函数!
580+
//TODO 改用 MySQL json_add,json_remove,json_contains 等函数!
581581
/**PUT key:[]
582582
* @param key
583583
* @param array
@@ -757,7 +757,7 @@ public AbstractObjectParser executeSQL() throws Exception {
757757
//执行SQL操作数据库
758758
if (isTable == false) {//提高性能
759759
sqlReponse = new JSONObject(sqlRequest);
760-
}
760+
}
761761
else {
762762
try {
763763
sqlReponse = onSQLExecute();
@@ -896,7 +896,8 @@ public JSONObject onSQLExecute() throws Exception {
896896
result = parser.executeSQL(sqlConfig, isSubquery);
897897

898898
boolean isSimpleArray = false;
899-
List<JSONObject> rawList = null;
899+
// 提取并缓存数组主表的列表数据
900+
List<JSONObject> rawList = (List<JSONObject>) result.remove(AbstractSQLExecutor.KEY_RAW_LIST);
900901

901902
if (isArrayMainTable && position == 0 && result != null) {
902903

@@ -905,8 +906,7 @@ public JSONObject onSQLExecute() throws Exception {
905906
&& (childMap == null || childMap.isEmpty())
906907
&& (table.equals(arrayTable));
907908

908-
// 提取并缓存数组主表的列表数据
909-
rawList = (List<JSONObject>) result.remove(AbstractSQLExecutor.KEY_RAW_LIST);
909+
// APP JOIN 副表时副表返回了这个字段 rawList = (List<JSONObject>) result.remove(AbstractSQLExecutor.KEY_RAW_LIST);
910910
if (rawList != null) {
911911
String arrayPath = parentPath.substring(0, parentPath.lastIndexOf("[]") + 2);
912912

0 commit comments

Comments
 (0)