Skip to content

Commit 5822909

Browse files
committed
Server:优化Paser#getArray关于total的处理并去除getArrayConfig被注释代码;QueryHelper优化性能;修正User和Controller部分注释
1 parent f13d777 commit 5822909

4 files changed

Lines changed: 24 additions & 42 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public String post(@RequestBody String request) {
5959
return new Parser(RequestMethod.POST).parse(request);
6060
}
6161

62-
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
62+
/**用POST方法HEAD,request和response都非明文,浏览器看不到,用于对安全性要求高的HEAD请求
6363
* @param request
6464
* @return
6565
*/
6666
@RequestMapping(value="post_head", method = org.springframework.web.bind.annotation.RequestMethod.POST)
6767
public String post_head(@RequestBody String request) {
6868
return new Parser(RequestMethod.POST_HEAD).parse(request);
6969
}
70-
/**用POST方法GET数据,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
70+
/**用POST方法GET,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
7171
* @param request
7272
* @return
7373
*/

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

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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, "\ngetObject: 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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class User extends BaseModel {
4444
private List<String> pictureList; //照片列表
4545
private String tag; //标签
4646
private Integer starred; //星标
47-
private List<Long> friendIdList; //照片列表
47+
private List<Long> friendIdList; //朋友列表
4848

4949
/**默认构造方法,JSON等解析时必须要有
5050
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ private synchronized Connection getConnection() throws Exception {
6060
}
6161

6262
private synchronized void saveCache(String sql, Map<Integer, JSONObject> map) {
63-
if (sql == null || map == null || map.isEmpty()) {
64-
Log.i(TAG, "saveList sql == null || map == null || map.isEmpty() >> return;");
63+
if (sql == null || map == null) { //空map有效,说明查询过sql了 || map.isEmpty()) {
64+
Log.i(TAG, "saveList sql == null || map == null >> return;");
6565
return;
6666
}
6767
cacheMap.put(sql, map);

0 commit comments

Comments
 (0)