@@ -119,6 +119,10 @@ public List<JSONObject> getCache(String sql, SQLConfig config) {
119119 @ Override
120120 public JSONObject getCacheItem (String sql , int position , SQLConfig config ) {
121121 List <JSONObject > list = getCache (sql , config );
122+ return getCacheItem (list , position , config );
123+ }
124+
125+ public JSONObject getCacheItem (List <JSONObject > list , int position , SQLConfig config ) {
122126 // 只要 list 不为 null,则如果 list.get(position) == null,则返回 {} ,避免再次 SQL 查询
123127 if (list == null ) {
124128 return null ;
@@ -128,6 +132,10 @@ public JSONObject getCacheItem(String sql, int position, SQLConfig config) {
128132 return result != null ? result : new JSONObject ();
129133 }
130134
135+
136+
137+
138+
131139 /**移除缓存
132140 * @param sql key
133141 * @param config
@@ -168,9 +176,7 @@ public ResultSet execute(@NotNull Statement statement, String sql) throws Except
168176 public JSONObject execute (@ NotNull SQLConfig config , boolean unknownType ) throws Exception {
169177 long executedSQLStartTime = System .currentTimeMillis ();
170178
171- boolean isPrepared = config .isPrepared ();
172179 final String sql = config .getSQL (false );
173- config .setPrepared (isPrepared );
174180
175181 if (StringUtil .isEmpty (sql , true )) {
176182 Log .e (TAG , "execute StringUtil.isEmpty(sql, true) >> return null;" );
@@ -219,7 +225,8 @@ public JSONObject execute(@NotNull SQLConfig config, boolean unknownType) throws
219225 //导致后面 rs.getMetaData() 报错 Operation not allowed after ResultSet closed result.put("moreResults", statement.getMoreResults());
220226 }
221227 else {
222- switch (config .getMethod ()) {
228+ RequestMethod method = config .getMethod ();
229+ switch (method ) {
223230 case POST :
224231 case PUT :
225232 case DELETE :
@@ -250,17 +257,26 @@ public JSONObject execute(@NotNull SQLConfig config, boolean unknownType) throws
250257 result .put (idKey + "[]" , config .getIdIn ());
251258 }
252259
260+ if (method == RequestMethod .PUT || method == RequestMethod .DELETE ) {
261+ config .setMethod (RequestMethod .GET );
262+ removeCache (config .getSQL (false ), config );
263+ config .setMethod (method );
264+ }
265+
253266 return result ;
254267
255268 case GET :
256269 case GETS :
257270 case HEAD :
258271 case HEADS :
259- result = isHead || isExplain ? null : getCacheItem (sql , position , config );
272+ List <JSONObject > cache = getCache (sql , config );
273+ result = getCacheItem (cache , position , config );
260274 Log .i (TAG , ">>> execute result = getCache('" + sql + "', " + position + ") = " + result );
261275 if (result != null ) {
262- cachedSQLCount ++;
263- List <JSONObject > cache = getCache (sql , config );
276+ if (isExplain == false ) {
277+ cachedSQLCount ++;
278+ }
279+
264280 if (cache != null && cache .size () > 1 ) {
265281 result .put (KEY_RAW_LIST , cache );
266282 }
@@ -600,9 +616,13 @@ else if (curJoin.isOuterJoin() || curJoin.isAntiJoin()) {
600616 config .setExplain (false );
601617 result .put ("sql" , config .getSQL (false ));
602618 config .setExplain (isExplain );
603- config .setPrepared (isPrepared );
604619 }
605620 result .put ("list" , resultList );
621+
622+ if (unknownType == false ) {
623+ putCache (sql , Arrays .asList (result ), config );
624+ }
625+
606626 return result ;
607627 }
608628
@@ -622,7 +642,6 @@ else if (curJoin.isOuterJoin() || curJoin.isAntiJoin()) {
622642 putCache (entry .getKey (), entry .getValue (), null );
623643 }
624644
625- putCache (sql , resultList , config );
626645 Log .i (TAG , ">>> execute putCache('" + sql + "', resultList); resultList.size() = " + resultList .size ());
627646
628647 // 数组主表对象额外一次返回全部,方便 Parser 缓存来提高性能
@@ -638,6 +657,8 @@ else if (curJoin.isOuterJoin() || curJoin.isAntiJoin()) {
638657 }
639658 }
640659
660+ putCache (sql , resultList , config );
661+
641662 long endTime = System .currentTimeMillis ();
642663 Log .d (TAG , "\n \n execute endTime = " + endTime + "; duration = " + (endTime - startTime )
643664 + "\n return resultList.get(" + position + ");" + "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n \n " );
@@ -727,7 +748,6 @@ protected void executeAppJoin(SQLConfig config, List<JSONObject> resultList, Map
727748
728749 boolean prepared = jc .isPrepared ();
729750 String sql = jc .getSQL (false );
730- jc .setPrepared (prepared );
731751
732752 if (StringUtil .isEmpty (sql , true )) {
733753 throw new NullPointerException (TAG + ".executeAppJoin StringUtil.isEmpty(sql, true) >> return null;" );
0 commit comments