Skip to content

Commit 5e8e06c

Browse files
committed
Server:优化含[]的依赖路径解析,滞后更新改为提前更新
1 parent 53f36ba commit 5e8e06c

2 files changed

Lines changed: 36 additions & 37 deletions

File tree

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/StringUtil.java‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,7 @@ public static boolean isNotEmpty(CharSequence cs, boolean trim) {
296296
* @return
297297
*/
298298
public static boolean isNotEmpty(String s, boolean trim) {
299-
// Log.i(TAG, "getTrimedString s = " + s);
300-
if (s == null) {
301-
return false;
302-
}
303-
if (trim) {
304-
s = s.trim();
305-
}
306-
if (s.length() <= 0) {
307-
return false;
308-
}
309-
310-
currentString = s;
311-
312-
return true;
299+
return ! isEmpty(s, trim);
313300
}
314301

315302
//判断字符是否非空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Parser.java‎

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,38 @@ && isInRelationMap(path) == false) {
603603
System.out.println("getObject key.endsWith(@) >> parseRelation = " + parseRelation);
604604
String replaceKey = key.substring(0, key.length() - 1);//key{}@ getRealKey
605605
String keyPath = getAbsPath(path, replaceKey);
606-
String valuePath = parseRelation ? getRelationValuePath(keyPath) : new String((String) value);
606+
String valuePath = new String((String) value);//改用实时替换[] -> []/i
607+
//parseRelation ? getRelationValuePath(keyPath) : new String((String) value);
607608

608609
if (valuePath.startsWith(SEPARATOR)) {
609610
valuePath = getAbsPath(parentPath, valuePath);
611+
} else {//处理[] -> []/i
612+
String[] ps = StringUtil.split(parentPath, "]/");//"[]/");
613+
614+
if (ps != null && ps.length > 1) {
615+
String[] vs = StringUtil.split(valuePath, "]/");
616+
617+
if (vs != null && vs.length > 0) {
618+
String pos;
619+
for (int i = 0; i < ps.length - 1; i++) {
620+
if (ps[i] == null || ps[i].equals(vs[i]) == false) {//允许""?
621+
break;
622+
}
623+
624+
pos = ps[i+1].contains("/") == false ? ps[i+1]
625+
: ps[i+1].substring(0, ps[i+1].indexOf("/"));
626+
if (
627+
//StringUtil.isNumer(pos) &&
628+
vs[i+1].startsWith(pos + "/") == false) {
629+
vs[i+1] = pos + "/" + vs[i+1];
630+
}
631+
}
632+
valuePath = StringUtil.getString(vs, "]/");
633+
}
634+
}
610635
}
611636
//先尝试获取,尽量保留缺省依赖路径,这样就不需要担心路径改变
612-
Object target = getValueByPath(valuePath, true);
637+
Object target = getValueByPath(valuePath);
613638
Log.i(TAG, "getObject valuePath = " + valuePath + "; target = " + target);
614639

615640
if (valuePath.equals(target)) {//必须valuePath和保证getValueByPath传进去的一致!
@@ -629,6 +654,7 @@ && isInRelationMap(path) == false) {
629654
Log.i(TAG, "getObject parseRelation == false"
630655
+ " >> containRelation = true; putRelation(keyPath, valuePath);");
631656
containRelation = true;
657+
//TODO 上面用实时替换[] -> []/i
632658
putRelation(keyPath, valuePath);
633659
}
634660
} else {//直接替换原来的key@:path为key:target
@@ -793,7 +819,7 @@ private JSONObject getArray(String parentPath, String name, JSONObject request)
793819
break;//数据库返回数量不够count,后面没有了。有依赖不为空,无依赖直接查询数据库。
794820
}
795821
transferredRequest.put("" + i, parent);
796-
updateRelation(path, getAbsPath(path, "" + i));//request结构已改变,需要更新依赖关系
822+
// updateRelation(path, getAbsPath(path, "" + i));//request结构已改变,需要更新依赖关系
797823
}
798824

799825
if (isInRelationMap(path)) {
@@ -864,8 +890,7 @@ public int estimateMaxCount(String path, String table, JSONObject value) throws
864890
if (v == null) {
865891
continue;
866892
}
867-
target = getValueByPath(getAbsPath(
868-
((String) v).startsWith(SEPARATOR) ? path : "", (String) v), true);
893+
target = getValueByPath(getAbsPath(((String) v).startsWith(SEPARATOR) ? path : "", (String) v));
869894
if (target != null && ((String) v).equals(target) == false) {
870895
k = k.substring(0, k.length() - 1);
871896
v = target;
@@ -1003,20 +1028,11 @@ private synchronized void putQueryResult(String path, Object result) {
10031028
}
10041029
/**根据路径获取值
10051030
* @param valuePath
1006-
* @return
1031+
* @return parent == null ? valuePath : parent.get(keys[keys.length - 1])
10071032
*/
10081033
private Object getValueByPath(String valuePath) {
1009-
return getValueByPath(valuePath, false);
1010-
}
1011-
/**根据路径获取值
1012-
* @param valuePath
1013-
* @param containKey
1014-
* @return containKey && parent.containsKey(targetKey) == false ? path : parent.get(targetKey);
1015-
*/
1016-
private Object getValueByPath(String valuePath, boolean containKey) {
1017-
Log.i(TAG, "<<<<<<<<<<<<<<< \n getValueByPath valuePath = " + valuePath
1018-
+ "; containKey = " + containKey + "\n <<<<<<<<<<<<<<<<<<");
1019-
if (StringUtil.isNotEmpty(valuePath, true) == false) {
1034+
Log.i(TAG, "<<<<<<<<<<<<<<< \n getValueByPath valuePath = " + valuePath + "\n <<<<<<<<<<<<<<<<<<");
1035+
if (StringUtil.isEmpty(valuePath, true)) {
10201036
Log.e(TAG, "getValueByPath StringUtil.isNotEmpty(valuePath, true) == false >> return null;");
10211037
return null;
10221038
}
@@ -1054,13 +1070,9 @@ private Object getValueByPath(String valuePath, boolean containKey) {
10541070
parent = getJSONObject(parent, keys[i]);
10551071
}
10561072
}
1057-
if (parent == null) {
1058-
return containKey ? valuePath : null;
1059-
}
10601073

1061-
System.out.println("getValueByPath return parent.get(keys[keys.length - 1]); >> ");
1062-
String targetKey = keys[keys.length - 1];
1063-
return containKey && parent.containsKey(targetKey) == false ? valuePath : parent.get(targetKey);
1074+
System.out.println("getValueByPath return parent == null ? valuePath : parent.get(keys[keys.length - 1]); >> ");
1075+
return parent == null ? valuePath : parent.get(keys[keys.length - 1]);
10641076
}
10651077

10661078
//依赖引用关系 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

0 commit comments

Comments
 (0)