@@ -128,7 +128,7 @@ public JSONObject parseResponse(JSONObject request) {
128128 Exception error = null ;
129129 queryHelper = new QueryHelper ();
130130 try {
131- requestObject = getObject (null , null , null , request );
131+ requestObject = getObject (null , null , request );
132132 } catch (Exception e ) {
133133 e .printStackTrace ();
134134 error = e ;
@@ -462,7 +462,7 @@ public static boolean isContainKeyInArray(String key, String[] array) {
462462 * @return
463463 * @throws Exception
464464 */
465- private JSONObject getObject (String parentPath , final QueryConfig parentConfig , String name
465+ private JSONObject getObject (String parentPath , String name
466466 , final JSONObject request ) throws Exception {
467467 Log .i (TAG , "\n getObject: parentPath = " + parentPath
468468 + ";\n name = " + name + "; request = " + JSON .toJSONString (request ));
@@ -472,9 +472,8 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
472472 final String path = getAbsPath (parentPath , name );
473473
474474 //为第二遍parseRelation = true服务,优化查询性能并避免"[]":{"0":{"1":{}}}这种导致第3层当成[]的直接子Object
475- final boolean isArrayChild = parentConfig != null && StringUtil .isNumer (name ) && ("" + parentConfig .getPosition ()).equals (name );
476- final String table = isArrayChild ? null : Pair .parseEntry (name , true ).getKey ();
477- final boolean isTableKey = isArrayChild == false && isTableKey (table );
475+ final String table = Pair .parseEntry (name , true ).getKey ();
476+ final boolean isTableKey = isTableKey (table );
478477 Log .d (TAG , "getObject table = " + table + "; isTableKey = " + isTableKey );
479478
480479
@@ -490,7 +489,6 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
490489
491490 Object value ;
492491 JSONObject result ;
493- boolean isFirst = true ;
494492 for (String key : set ) {
495493 value = request .get (key );
496494 if (value == null ) {
@@ -501,17 +499,7 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
501499 if (isArrayKey (key )) {//APIJSON Array
502500 result = getArray (path , key , (JSONObject ) value );
503501 } else {//APIJSON Object
504- result = getObject (path , isFirst && isArrayChild //以第0个JSONObject为准
505- ? parentConfig : null , key , (JSONObject ) value );
506-
507- //如果第0个都为空,那后面的也都无意义了。
508- if (isFirst && isArrayChild && (result == null || result .isEmpty ())) {
509- Log .d (TAG , "getObject isFirst && isArrayChild"
510- + " && (result == null || result.isEmpty()) >> return null;" );
511- return null ;
512- }
513-
514- isFirst = false ;//[]里第一个不能为[]
502+ result = getObject (path , key , (JSONObject ) value );
515503 }
516504 Log .i (TAG , "getObject key = " + key + "; result = " + result );
517505 if (result != null && result .isEmpty () == false ) {//只添加!=null的值,可能数据库返回数据不够count
@@ -630,14 +618,7 @@ private JSONObject getObject(String parentPath, final QueryConfig parentConfig,
630618 if (isTableKey ) {//提高性能
631619 query = true ;
632620
633- QueryConfig config = newQueryConfig (table , transferredRequest );
634-
635- if (parentConfig == null ) {//导致全部都是第0个 || isArrayChild == false) {
636- config .setCount (1 );
637- } else {
638- config .setCount (parentConfig .getCount ()).setPage (parentConfig .getPage ())
639- .setPosition (parentConfig .getPosition ());//避免position > 0的object获取不到
640- }
621+ QueryConfig config = newQueryConfig (table , transferredRequest ).setCount (1 );
641622
642623 try {
643624 transferredRequest = getSQLObject (config );
@@ -712,10 +693,6 @@ private JSONObject getArray(String parentPath, String name, final JSONObject req
712693 final int page = request .getIntValue (JSONRequest .KEY_PAGE );
713694 Log .d (TAG , "getArray query = " + query + "; count = " + count + "; page = " + page );
714695
715- // //后面还要put回来,所以中间不要return;除非不需要保留page,count!
716- // request.remove(JSONRequest.KEY_QUERY);
717- // request.remove(JSONRequest.KEY_COUNT);
718- // request.remove(JSONRequest.KEY_PAGE);
719696
720697 //最好先获取第一个table的所有项(where条件),填充一个列表?
721698 Set <String > set = new LinkedHashSet <>(request .keySet ());
@@ -745,7 +722,6 @@ private JSONObject getArray(String parentPath, String name, final JSONObject req
745722 int total = 0 ;//满足条件的总数,忽略page,count
746723 Log .d (TAG , "getArray query != JSONRequest.QUERY_TABLE >> " );
747724 String firstTableKey = null ;
748- // JSONObject firstRequest = null;
749725 String table ;
750726 Object value ;
751727 QueryConfig config = null ;
@@ -761,12 +737,9 @@ private JSONObject getArray(String parentPath, String name, final JSONObject req
761737 queryTotal = false ;
762738
763739 firstTableKey = key ;
764- // firstRequest = (JSONObject) value;
765740
766741 config = getConfigWithTotal (path , table , (JSONObject ) value );
767742 total = config .getTotal ();
768-
769- // request.remove(firstTableKey);
770743 }
771744 }
772745
@@ -790,7 +763,6 @@ private JSONObject getArray(String parentPath, String name, final JSONObject req
790763 //Table<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
791764 JSONObject response = new JSONObject (true );
792765 if (size > 0 && config != null ) {//request内部没有JSONObject或者不存在适合条件的table内容
793- // QueryConfig config = new QueryConfig(requestMethod, size, page);//count不能变,变了后start就不对了
794766 config .setMethod (requestMethod ).setCount (size ).setPage (page );
795767 JSONObject parent ;
796768 JSONObject first ;
@@ -799,7 +771,7 @@ private JSONObject getArray(String parentPath, String name, final JSONObject req
799771 try {
800772 first = getSQLObject (config .setPosition (i ));
801773 } catch (Exception e ) {
802- Log .e (TAG , "getArray try { transferredRequest = getSQLObject(config2); } catch (Exception e) {" );
774+ Log .e (TAG , "getArray try { first = getSQLObject(config2); } catch (Exception e) {" );
803775 if (e instanceof NotExistException ) {//非严重异常,有时候只是数据不存在
804776 first = null ;//内部吃掉异常,put到最外层
805777 } else {
@@ -812,7 +784,7 @@ private JSONObject getArray(String parentPath, String name, final JSONObject req
812784 }
813785 putQueryResult (path + "/" + i + "/" + firstTableKey , first );
814786
815- parent = getObject (path , null , "" + i , otherRequest );//request);
787+ parent = getObject (path , "" + i , otherRequest );//request);
816788 if (parent == null ) {
817789 parent = new JSONObject (true );
818790 }
@@ -824,13 +796,6 @@ private JSONObject getArray(String parentPath, String name, final JSONObject req
824796
825797
826798
827- // //解决[]:{Comment[]:{...}}内层0之后的count,page丢失,导致性能下降
828- // request.put(firstTableKey, firstRequest);//顺序错了!
829- //
830- // request.put(JSONRequest.KEY_QUERY, query);
831- // request.put(JSONRequest.KEY_COUNT, count);
832- // request.put(JSONRequest.KEY_PAGE, page);
833-
834799 Log .i (TAG , "getArray return response = \n " + JSON .toJSONString (response ) + "\n >>>>>>>>>>>>>>>\n \n \n " );
835800
836801 return response ;
0 commit comments