@@ -75,11 +75,12 @@ public RequestParser(RequestMethod requestMethod) {
7575
7676
7777 private JSONObject requestObject ;
78+ private QueryHelper queryHelper ;
79+ private Map <String , JSONObject > queryResultMap ;//path-result
7880
7981 private boolean parseRelation ;
8082 //不用keyPath-valuePath-value是因为很可能很多valuePath对应同一个value
8183 private Map <String , String > keyValuePathMap ;//keyPath-valuePath
82- private Map <String , JSONObject > queryResultMap ;//path-result
8384
8485
8586 /**解析请求json并获取对应结果
@@ -128,6 +129,7 @@ public JSONObject parseResponse(JSONObject request) {
128129 parseRelation = false ;
129130
130131 Exception error = null ;
132+ queryHelper = new QueryHelper ();
131133 try {
132134 requestObject = getObject (null , null , null , request );
133135
@@ -144,8 +146,8 @@ public JSONObject parseResponse(JSONObject request) {
144146 e .printStackTrace ();
145147 error = e ;
146148 }
147-
148- QueryHelper . getInstance (). close () ;
149+ queryHelper . close ();
150+ queryHelper = null ;
149151 // QueryHelper2.getInstance().close();
150152
151153
@@ -231,13 +233,21 @@ public static JSONObject extendResult(JSONObject object, int status, String mess
231233 object .put (JSONResponse .KEY_MESSAGE , message );
232234 return object ;
233235 }
236+
237+
234238 /**添加请求成功的状态内容
235239 * @param object
236240 * @return
237241 */
238242 public static JSONObject extendSuccessResult (JSONObject object ) {
239243 return extendResult (object , 200 , "success" );
240244 }
245+ /**获取请求成功的状态内容
246+ * @return
247+ */
248+ public static JSONObject newSuccessResult () {
249+ return newResult (200 , "success" );
250+ }
241251 /**添加请求成功的状态内容
242252 * @param object
243253 * @return
@@ -285,8 +295,19 @@ public static JSONObject newErrorResult(Exception e) {
285295 * @param method
286296 * @param request
287297 * @return
298+ * @throws Exception
288299 */
289300 public static JSONObject getCorrectRequest (RequestMethod method , JSONObject request ) throws Exception {
301+ return getCorrectRequest (method , request , null );
302+ }
303+ /**获取正确的请求,非GET请求必须是服务器指定的
304+ * @param method
305+ * @param request
306+ * @param queryHelper
307+ * @return
308+ */
309+ public static JSONObject getCorrectRequest (RequestMethod method , JSONObject request , QueryHelper queryHelper )
310+ throws Exception {
290311 if (isPublicMethod (method )) {
291312 return request ;//需要指定JSON结构的get请求可以改为post请求。一般只有对安全性要求高的才会指定,而这种情况用明文的GET方式几乎肯定不安全
292313 }
@@ -307,12 +328,17 @@ public static JSONObject getCorrectRequest(RequestMethod method, JSONObject requ
307328
308329 JSONObject object = null ;
309330 String error = "" ;
331+ if (queryHelper == null ) {
332+ queryHelper = new QueryHelper ();
333+ }
310334 try {
311- object = QueryHelper . getInstance () .select (config );
335+ object = queryHelper .select (config );
312336 } catch (Exception e ) {
313337 e .printStackTrace ();
314338 error = e .getMessage ();
315339 }
340+ queryHelper .close ();
341+
316342 if (object == null || object .isEmpty ()) {
317343 throw new UnsupportedOperationException ("非GET请求必须是服务端允许的操作! \n " + error );
318344 }
@@ -469,7 +495,7 @@ && isInRelationMap(path) == false) {
469495 boolean nameIsNumber = StringUtil .isNumer (name );
470496 String table = Pair .parseEntry (name ).getValue ();
471497 Log .d (TAG , "getObject table = " + table );
472-
498+
473499 QueryConfig config = nameIsNumber ? parentConfig : null ;
474500 if (config == null ) {
475501 config = new QueryConfig (requestMethod , table ).setCount (1 );
@@ -495,7 +521,7 @@ && isInRelationMap(path) == false) {
495521 JSONObject result ;
496522 boolean isFirst = true ;
497523 for (String key : set ) {
498- value = transferredRequest . containsKey ( key ) ? transferredRequest . get ( key ) : request .get (key );
524+ value = request .get (key );
499525 if (value instanceof JSONObject ) {//JSONObject,往下一级提取
500526 if (isArrayKey (key )) {//APIJSON Array
501527 result = getArray (path , config , key , (JSONObject ) value );
@@ -602,15 +628,15 @@ && isInRelationMap(path) == false) {
602628 if (((String ) value ).startsWith (SEPARATOR )) {
603629 value = getAbsPath (parentPath , (String ) value );
604630 }
605- // Object target = getValueByPath((String) value);
606- // Log.d(TAG, "getObject value = " + value + "; target = " + target);
607- // if (target == null || ((String) value).equals(target)) {//标记并存放依赖关系
608- containRelation = true ;
609- putRelation (getAbsPath (path , replaceKey ), (String ) value );
610- // } else {//直接替换原来的key@:path为key:target
611- // transferredRequest.remove(key);
612- // transferredRequest.put(replaceKey, target);
613- // }
631+ // Object target = getValueByPath((String) value);
632+ // Log.d(TAG, "getObject value = " + value + "; target = " + target);
633+ // if (target == null || ((String) value).equals(target)) {//标记并存放依赖关系
634+ containRelation = true ;
635+ putRelation (getAbsPath (path , replaceKey ), (String ) value );
636+ // } else {//直接替换原来的key@:path为key:target
637+ // transferredRequest.remove(key);
638+ // transferredRequest.put(replaceKey, target);
639+ // }
614640 }
615641 }
616642 }
@@ -925,7 +951,7 @@ private Object getValueByPath(String valuePath, boolean containKey) {
925951 break ;
926952 }
927953 }
928-
954+
929955 //逐层到达targetKey的直接容器JSONObject parent
930956 if (keys != null && keys .length > 1 ) {
931957 for (int i = 0 ; i < keys .length - 1 ; i ++) {//一步一步到达指定位置parentPath
@@ -968,7 +994,7 @@ public static JSONObject getJSONObject(JSONObject object, String key) {
968994 private synchronized JSONObject getSQLObject (QueryConfig config ) throws Exception {
969995 Log .i (TAG , "getSQLObject config = " + JSON .toJSONString (config ));
970996 AccessVerifier .verify (requestObject , config );
971- return QueryHelper . getInstance () .select (config );//QueryHelper2.getInstance().select(config);//
997+ return queryHelper .select (config );//QueryHelper2.getInstance().select(config);//
972998 }
973999
9741000 /**获取查询配置
0 commit comments