@@ -456,14 +456,12 @@ public static boolean isContainKeyInArray(String key, String[] array) {
456456
457457 /**获取单个对象,该对象处于parentObject内
458458 * @param parentPath parentObject的路径
459- * @param parentConfig 对子object的SQL查询配置,需要传两个层级
460459 * @param name parentObject的key
461460 * @param request parentObject的value
462461 * @return
463462 * @throws Exception
464463 */
465- private JSONObject getObject (String parentPath , String name
466- , final JSONObject request ) throws Exception {
464+ private JSONObject getObject (String parentPath , String name , final JSONObject request ) throws Exception {
467465 Log .i (TAG , "\n getObject: parentPath = " + parentPath
468466 + ";\n name = " + name + "; request = " + JSON .toJSONString (request ));
469467 if (request == null ) {// Moment:{} || request.isEmpty()) {//key-value条件
@@ -677,7 +675,6 @@ private JSONObject getObject(String parentPath, String name
677675 */
678676 /**获取对象数组,该对象数组处于parentObject内
679677 * @param parentPath parentObject的路径
680- * @param parentConfig 对子object的SQL查询配置,需要传两个层级
681678 * @param name parentObject的key
682679 * @param request parentObject的value
683680 * @return 转为JSONArray不可行,因为会和被当成条件的key:JSONArray冲突。好像一般也就key{}:JSONArray用到??
@@ -721,31 +718,34 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
721718
722719
723720 //total<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
724- // if (query != JSONRequest.QUERY_TABLE) {
725721
726- JSONObject otherRequest = new JSONObject (true );
727722
728- boolean queryTotal = true ;
729- int total = 0 ;//满足条件的总数,忽略page,count
730- Log .d (TAG , "getArray query != JSONRequest.QUERY_TABLE >> " );
723+ final boolean queryTotal = query != JSONRequest .QUERY_TABLE ;
724+ Log .d (TAG , "getArray queryTotal = " + queryTotal );
725+
726+ boolean setConfig = true ;
731727 String firstTableKey = null ;
732728 String table ;
733729 Object value ;
734730 QueryConfig config = null ;
731+ int total = 0 ;//满足条件的总数,忽略page,count
732+
733+ JSONObject otherRequest = new JSONObject (true );
734+
735735 for (String key : set ) {
736736 if (key == null ) {
737737 continue ;
738738 }
739739
740- if (queryTotal ) {
740+ if (setConfig ) {
741741 table = Pair .parseEntry (key , true ).getKey ();
742742 value = isTableKey (table ) ? request .get (key ) : null ;
743743 if (value != null && value instanceof JSONObject ) {// && value.isEmpty() == false) {
744- queryTotal = false ;
744+ setConfig = false ;
745745
746746 firstTableKey = key ;
747747
748- config = getConfigWithTotal (path , table , (JSONObject ) value );
748+ config = getArrayConfig (path , table , (JSONObject ) value , queryTotal );
749749 total = config .getTotal ();
750750 }
751751 }
@@ -754,15 +754,14 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
754754 otherRequest .put (key , request .get (key ));
755755 }
756756 }
757- if (total <= size *page ) {
758- Log .d (TAG , "getArray total <= size*page >> size = 0;" );
757+ if (queryTotal && total <= size *page ) {
758+ Log .d (TAG , "getArray queryTotal && total <= size*page >> size = 0;" );
759759 size = 0 ;//不再查询,但不能return null;因为还需要put条件
760760 }
761761 if (total > 0 ) {
762762 Log .d (TAG , "getArray total = " + total + " >> putQueryResult(...)" );
763763 putQueryResult (path + "/" + JSONResponse .KEY_TOTAL , total );//GET下替代HEAD的方式
764764 }
765- // }
766765 //total>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
767766
768767 Log .d (TAG , "getArray size = " + size + "; page = " + page );
@@ -796,7 +795,6 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
796795 parent = new JSONObject (true );
797796 }
798797 parent .put (firstTableKey , first );//依赖的对象值在queryResultMap中取
799- // response.put("" + i, parent);
800798 response .add (parent );
801799 }
802800 }
@@ -815,10 +813,12 @@ private JSONArray getArray(String parentPath, String name, final JSONObject requ
815813 * @param path
816814 * @param name
817815 * @param value
816+ * @param queryTotal
818817 * @return
819818 * @throws Exception
820819 */
821- public QueryConfig getConfigWithTotal (String path , String table , final JSONObject value ) throws Exception {
820+ public QueryConfig getArrayConfig (String path , String table , final JSONObject value
821+ , boolean queryTotal ) throws Exception {
822822 if (StringUtil .isNotEmpty (table , true ) == false ) {
823823 Log .e (TAG , "estimateMaxCount StringUtil.isNotEmpty(table, true) == false >> return 0;" );
824824 return null ;
@@ -830,7 +830,6 @@ public QueryConfig getConfigWithTotal(String path, String table, final JSONObjec
830830 String k ;
831831 Object v ;
832832 Object target ;
833- // String valid;
834833 for (Entry <String , Object > entry : entrySet ) {
835834 k = entry == null ? "" : StringUtil .getString (entry .getKey ());
836835 if (k .isEmpty () == false ) {
@@ -849,32 +848,15 @@ public QueryConfig getConfigWithTotal(String path, String table, final JSONObjec
849848 }
850849 k = k .substring (0 , k .length () - 1 );
851850 v = target ;
852-
853- // value.put(k.substring(0, k.length() - 1), target);//解析依赖,后面就不用再解析了
854851 }
855852
856- //如果这些通不过,getObject时也通不过
857- // valid = new String(k);
858- // if (valid.endsWith("$")) {
859- // valid = valid.substring(0, valid.length() - 1);
860- // } else if (valid.endsWith("{}")) {
861- // valid = valid.substring(0, valid.length() - 2);
862- // } else if (valid.endsWith("<>")) {
863- // valid = valid.substring(0, valid.length() - 2);
864- // }
865- //
866- // if (valid.endsWith("|") || valid.endsWith("&") || valid.endsWith("!")) {
867- // valid = valid.substring(0, valid.length() - 1);
868- // }
869- //
870- // if (isWord(valid)) {
871853 request .put (k , v );//和value性质不同
872- // }
873854 }
874855 }
875856 }
876857
877- JSONObject response = new Parser (RequestMethod .HEAD ).parseResponse (new JSONRequest (table , request ));
858+ JSONObject response = queryTotal == false
859+ ? null : new Parser (RequestMethod .HEAD ).parseResponse (new JSONRequest (table , request ));
878860 if (response != null ) {
879861 response = response .getJSONObject (table );
880862 }
0 commit comments