2020import static apijson .framework .APIJSONConstant .VISITOR_ID ;
2121
2222import java .rmi .ServerException ;
23+ import java .util .Comparator ;
2324import java .util .HashMap ;
2425import java .util .Map ;
26+ import java .util .SortedMap ;
27+ import java .util .TreeMap ;
2528
2629import javax .servlet .http .HttpSession ;
2730
@@ -141,6 +144,9 @@ public static JSONObject initAccess(boolean shutdownWhenServerError, APIJSONCrea
141144
142145 { //Access<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
143146 JSONRequest access = new JSONRequest ();
147+ if (Log .DEBUG == false ) {
148+ access .put ("debug" , 0 );
149+ }
144150 accessItem .put (ACCESS_ , access );
145151 } //Access>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
146152
@@ -196,18 +202,14 @@ public static JSONObject initAccess(boolean shutdownWhenServerError, APIJSONCrea
196202 onServerError ("name: " + name + "不合法!字段 alias 的值为空时,name 必须为合法表名!" , shutdownWhenServerError );
197203 }
198204
199- if (Log .DEBUG || item .getBooleanValue ("debug" ) == false ) {
200- ACCESS_MAP .put (name , map );
201- }
205+ ACCESS_MAP .put (name , map );
202206 }
203207 else {
204208 if (JSONRequest .isTableKey (alias ) == false ) {
205209 onServerError ("alias: " + alias + "不合法!字段 alias 的值只能为 空 或者 合法表名!" , shutdownWhenServerError );
206210 }
207211
208- if (Log .DEBUG || item .getBooleanValue ("debug" ) == false ) {
209- ACCESS_MAP .put (alias , map );
210- }
212+ ACCESS_MAP .put (alias , map );
211213 }
212214
213215 APIJSONSQLConfig .TABLE_KEY_MAP .put (alias , name );
@@ -260,7 +262,7 @@ public static JSONObject initRequest(boolean shutdownWhenServerError, APIJSONCre
260262 JSONRequest requestItem = new JSONRequest ();
261263
262264 { //Request<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
263- requestItem .put (REQUEST_ , new JSONRequest ());
265+ requestItem .put (REQUEST_ , new JSONRequest (). setOrder ( "version-,id+" )); // 方便查找
264266 } //Request>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
265267
266268 request .putAll (requestItem .toArray (0 , 0 , REQUEST_ ));
@@ -280,9 +282,9 @@ public static JSONObject initRequest(boolean shutdownWhenServerError, APIJSONCre
280282 throw new NullPointerException ("没有可用的权限配置" );
281283 }
282284
283- // Log.d(TAG, "init < for REQUEST_MAP.size() = " + REQUEST_MAP.size() + " <<<<<<<<<<<<<<<<<<<<<<<<");
285+ Log .d (TAG , "init < for REQUEST_MAP.size() = " + REQUEST_MAP .size () + " <<<<<<<<<<<<<<<<<<<<<<<<" );
284286
285- // REQUEST_MAP.clear();
287+ REQUEST_MAP .clear ();
286288
287289 JSONObject item ;
288290 for (int i = 0 ; i < list .size (); i ++) {
@@ -311,7 +313,6 @@ public static JSONObject initRequest(boolean shutdownWhenServerError, APIJSONCre
311313
312314 JSONObject structure = JSON .parseObject (item .getString ("structure" ));
313315
314-
315316 JSONObject target = null ;
316317
317318 if (structure != null ) {
@@ -338,18 +339,31 @@ public static JSONObject initRequest(boolean shutdownWhenServerError, APIJSONCre
338339 onServerError ("服务器内部错误,Request 表中的 version = " + version + ", method = " + method + ", tag = " + tag + " 对应的 structure 不能为空!" , shutdownWhenServerError );
339340 }
340341
341- // REQUEST_MAP.put(tag, target);
342+ String cacheKey = getCacheKeyForRequest (method , tag );
343+ SortedMap <Integer , JSONObject > versionedMap = REQUEST_MAP .get (cacheKey );
344+ if (versionedMap == null ) {
345+ versionedMap = new TreeMap <>(new Comparator <Integer >() {
346+
347+ @ Override
348+ public int compare (Integer o1 , Integer o2 ) {
349+ return o2 == null ? -1 : o2 .compareTo (o1 ); // 降序
350+ }
351+ });
352+ }
353+ versionedMap .put (Integer .valueOf (version ), item );
354+ REQUEST_MAP .put (cacheKey , versionedMap );
342355 }
343356
344- // Log.d(TAG, "init for /> REQUEST_MAP.size() = " + REQUEST_MAP.size() + " >>>>>>>>>>>>>>>>>>>>>>>");
357+ Log .d (TAG , "init for /> REQUEST_MAP.size() = " + REQUEST_MAP .size () + " >>>>>>>>>>>>>>>>>>>>>>>" );
345358
346359 return response ;
347360 }
348361
362+
349363 public static void test () {
350364 testStructure ();
351365 }
352-
366+
353367 static final String requestString = "{\" Comment\" :{\" REFUSE\" : \" id\" , \" MUST\" : \" userId,momentId,content\" }, \" INSERT\" :{\" Comment:to\" :{}}}" ;
354368 static final String responseString = "{\" User\" :{\" REMOVE\" : \" phone\" , \" REPLACE\" :{\" sex\" :2}, \" INSERT\" :{\" name\" :\" api\" }}, \" UPDATE\" :{\" Comment:to\" :{}}}" ;
355369 /**
0 commit comments