@@ -81,7 +81,7 @@ public Parser(RequestMethod requestMethod) {
8181 private QueryHelper queryHelper ;
8282 private Map <String , Object > queryResultMap ;//path-result
8383
84- private boolean parseRelation ;
84+ // private boolean parseRelation;
8585 //不用keyPath-valuePath-value是因为很可能很多valuePath对应同一个value
8686// private Map<String, String> keyValuePathMap;//keyPath-valuePath
8787
@@ -129,7 +129,7 @@ public JSONObject parseResponse(JSONObject request) {
129129
130130// keyValuePathMap = new HashMap<String, String>();
131131 queryResultMap = new HashMap <String , Object >();
132- parseRelation = false ;
132+ // parseRelation = false;
133133
134134 Exception error = null ;
135135 queryHelper = new QueryHelper ();
@@ -489,12 +489,12 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
489489 return null ;
490490 }
491491 final String path = getAbsPath (parentPath , name );
492- if (parseRelation //优化性能:第二遍遍历时如果内部没有依赖引用其它就跳过
493- && StringUtil .isNotEmpty (path , true )//避免最外层返回true而不能parseRelation
494- // && isInRelationMap(path) == false
495- ) {
496- return request ;
497- }
492+ // if (parseRelation //优化性能:第二遍遍历时如果内部没有依赖引用其它就跳过
493+ // && StringUtil.isNotEmpty(path, true)//避免最外层返回true而不能parseRelation
494+ //// && isInRelationMap(path) == false
495+ // ) {
496+ // return request;
497+ // }
498498 //为第二遍parseRelation = true服务,优化查询性能并避免"[]":{"0":{"1":{}}}这种导致第3层当成[]的直接子Object
499499 final boolean isArrayChild = parentConfig != null && StringUtil .isNumer (name ) && ("" + parentConfig .getPosition ()).equals (name );
500500 final String table = isArrayChild ? null : Pair .parseEntry (name , true ).getKey ();
@@ -601,9 +601,9 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
601601 if (value instanceof String == false ) {
602602 throw new IllegalArgumentException ("\" key@\" : 后面必须为依赖路径String!" );
603603 }
604- System .out .println ("getObject key.endsWith(@) >> parseRelation = " + parseRelation );
604+ // System.out.println("getObject key.endsWith(@) >> parseRelation = " + parseRelation);
605605 String replaceKey = key .substring (0 , key .length () - 1 );//key{}@ getRealKey
606- String keyPath = getAbsPath (path , replaceKey );
606+ // String keyPath = getAbsPath(path, replaceKey);
607607 String valuePath = new String ((String ) value );//改用实时替换[] -> []/i
608608 //parseRelation ? getRelationValuePath(keyPath) : new String((String) value);
609609
@@ -620,23 +620,23 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
620620 if (valuePath .equals (target )) {//必须valuePath和保证getValueByPath传进去的一致!
621621 Log .i (TAG , "getObject target != null && target instanceof String"
622622 + " && ((String) target).startsWith(valuePath) >> " );
623- if (parseRelation ) {
624- //非查询关键词 @key 不影响查询,直接跳过
625- if (isTableKey && (key .startsWith ("@" ) == false || QueryConfig .TABLE_KEY_LIST .contains (key ))) {
626- Log .e (TAG , "getObject parseRelation >> isTableKey && (key.startsWith(@) == false"
627- + " || QueryConfig.TABLE_KEY_LIST.contains(key)) >> return null;" );
628- return null ;//parseRelation时还获取不到就不用再做无效的query了。不考虑 Table:{Table:{}}嵌套
629- } else {
630- Log .d (TAG , "getObject parseRelation >> isTableKey(table) == false >> continue;" );
631- continue ;//舍去,对Table无影响
632- }
633- } else {//标记并存放依赖关系
623+ // if (parseRelation) {
624+ // //非查询关键词 @key 不影响查询,直接跳过
625+ // if (isTableKey && (key.startsWith("@") == false || QueryConfig.TABLE_KEY_LIST.contains(key))) {
626+ // Log.e(TAG, "getObject parseRelation >> isTableKey && (key.startsWith(@) == false"
627+ // + " || QueryConfig.TABLE_KEY_LIST.contains(key)) >> return null;");
628+ // return null;//parseRelation时还获取不到就不用再做无效的query了。不考虑 Table:{Table:{}}嵌套
629+ // } else {
630+ // Log.d(TAG, "getObject parseRelation >> isTableKey(table) == false >> continue;");
631+ // continue;//舍去,对Table无影响
632+ // }
633+ // } else {//标记并存放依赖关系
634634 Log .i (TAG , "getObject parseRelation == false"
635635 + " >> containRelation = true; putRelation(keyPath, valuePath);" );
636636 containRelation = true ;
637637 //TODO 上面用实时替换[] -> []/i
638638// putRelation(keyPath, valuePath);
639- }
639+ // }
640640 } else {//直接替换原来的key@:path为key:target
641641 Log .i (TAG , "getObject >> key = replaceKey; value = target;" );
642642 key = replaceKey ;
@@ -663,9 +663,9 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
663663 boolean query = false ;
664664 //执行SQL操作数据库
665665 if (containRelation == false && isTableKey ) {//提高性能
666- if (parseRelation == false
667- // || isInRelationMap(path)
668- ) {//避免覆盖原来已经获取的
666+ // if (parseRelation == false
667+ //// || isInRelationMap(path)
668+ // ) {//避免覆盖原来已经获取的
669669 query = true ;
670670 // keyValuePathMap.remove(path);
671671 //移除所有startswith path的keyPath?
@@ -697,7 +697,7 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
697697 if (transferredRequest == null ) {
698698 transferredRequest = new JSONObject (true );
699699 }
700- }
700+ // }
701701 }
702702
703703 if (selfDefineKeyMap != null ) {
@@ -760,7 +760,9 @@ private JSONObject getArray(String parentPath, String name, JSONObject request)
760760
761761 //最好先获取第一个table的所有项(where条件),填充一个列表?
762762 Set <String > set = new LinkedHashSet <>(request .keySet ());
763- if (parseRelation == false && set != null ) {
763+ if (
764+ // parseRelation == false &&
765+ set != null ) {
764766 if (count <= 0 || count > 5 ) {//5以下不优化长度
765767 String table ;
766768 Object value ;
@@ -790,10 +792,10 @@ private JSONObject getArray(String parentPath, String name, JSONObject request)
790792 JSONObject transferredRequest = new JSONObject (true );
791793
792794 JSONObject parent = null ;
793- Object value ;
794- JSONObject result ;
795- Log .d (TAG , "getArray parseRelation = " + parseRelation );
796- if (parseRelation == false ) {
795+ // Object value;
796+ // JSONObject result;
797+ // Log.d(TAG, "getArray parseRelation = " + parseRelation);
798+ // if (parseRelation == false) {
797799 //生成count个
798800 for (int i = 0 ; i < count ; i ++) {
799801 parent = getObject (path , config .setPosition (i ), "" + i , request );
@@ -808,31 +810,31 @@ private JSONObject getArray(String parentPath, String name, JSONObject request)
808810// transferredRequest.put(JSONRequest.KEY_COUNT, count);
809811// transferredRequest.put(JSONRequest.KEY_PAGE, page);
810812// }
811- } else {
812- boolean isArrayKey ;
813- for (String key : set ) {//0:{},1:{}...
814- value = request .get (key );
815- if (value instanceof JSONObject ) {//JSONObject,往下一级提取
816- config .setPosition (Integer .valueOf (0 + StringUtil .getNumber (key , true )));
817- isArrayKey = isArrayKey (key );
818- if (isArrayKey ) {//json array
819- result = getArray (path , key , (JSONObject ) value );
820- } else {//json object
821- result = getObject (path , config , key , (JSONObject ) value );
822- }
823- if (result == null || result .isEmpty ()) {
824- if (isArrayKey ) {
825- continue ;
826- } else {
827- break ;//数据库返回数量不够count,后面没有了。有依赖不为空,无依赖直接查询数据库。
828- }
829- }
830- transferredRequest .put (key , result );
831- } else {//JSONArray或其它Object
832- //array里不允许关联,只能在object中关联
833- }
834- }
835- }
813+ // } else {
814+ // boolean isArrayKey;
815+ // for (String key : set) {//0:{},1:{}...
816+ // value = request.get(key);
817+ // if (value instanceof JSONObject) {//JSONObject,往下一级提取
818+ // config.setPosition(Integer.valueOf(0 + StringUtil.getNumber(key, true)));
819+ // isArrayKey = isArrayKey(key);
820+ // if (isArrayKey) {//json array
821+ // result = getArray(path, key, (JSONObject) value);
822+ // } else {//json object
823+ // result = getObject(path, config, key, (JSONObject) value);
824+ // }
825+ // if (result == null || result.isEmpty()) {
826+ // if (isArrayKey) {
827+ // continue;
828+ // } else {
829+ // break;//数据库返回数量不够count,后面没有了。有依赖不为空,无依赖直接查询数据库。
830+ // }
831+ // }
832+ // transferredRequest.put(key, result);
833+ // } else {//JSONArray或其它Object
834+ // //array里不允许关联,只能在object中关联
835+ // }
836+ // }
837+ // }
836838
837839 //解决[]:{Comment[]:{...}}内层count,page丢失
838840 request .put (JSONRequest .KEY_COUNT , count );
0 commit comments