3737 * @author Lemon
3838 */
3939public abstract class AbstractSQLExecutor implements SQLExecutor {
40- private static final String TAG = "SQLExecutor " ;
40+ private static final String TAG = "AbstractSQLExecutor " ;
4141
4242
4343 //访问一次后丢失,可能因为static导致内存共享,别的地方改变了内部对象的值
@@ -280,16 +280,16 @@ protected void executeAppJoin(SQLConfig config, Map<Integer, JSONObject> resultM
280280
281281 jc = j .getJoinConfig ();
282282 cc = j .getCacheConfig (); //这里用config改了getSQL后再还原很麻烦,所以提前给一个config2更好
283-
283+
284284 //取出 "id@": "@/User/userId" 中所有 userId 的值
285285 List <Object > targetValueList = new ArrayList <>();
286286 JSONObject mainTable ;
287287 Object targetValue ;
288-
288+
289289 for (int i = 0 ; i < resultMap .size (); i ++) {
290290 mainTable = resultMap .get (i );
291291 targetValue = mainTable == null ? null : mainTable .get (j .getTargetKey ());
292-
292+
293293 if (targetValue != null && targetValueList .contains (targetValue ) == false ) {
294294 targetValueList .add (targetValue );
295295 }
@@ -301,21 +301,21 @@ protected void executeAppJoin(SQLConfig config, Map<Integer, JSONObject> resultM
301301 jc .putWhere (j .getKey () + "{}" , targetValueList , false );
302302
303303 jc .setMain (true ).setPreparedValueList (new ArrayList <>());
304-
304+
305305 boolean prepared = jc .isPrepared ();
306306 final String sql = jc .getSQL (false );
307307 jc .setPrepared (prepared );
308308
309309 if (StringUtil .isEmpty (sql , true )) {
310310 throw new NullPointerException (TAG + ".executeAppJoin StringUtil.isEmpty(sql, true) >> return null;" );
311311 }
312-
312+
313313 long startTime = System .currentTimeMillis ();
314314 Log .d (TAG , "\n <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
315315 + "\n executeAppJoin startTime = " + startTime
316316 + "\n sql = \n " + sql
317317 + "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n " );
318-
318+
319319 //执行副表的批量查询 并 缓存到 childMap
320320 ResultSet rs = executeQuery (jc );
321321
@@ -341,7 +341,7 @@ protected void executeAppJoin(SQLConfig config, Map<Integer, JSONObject> resultM
341341
342342 Log .d (TAG , "\n executeAppJoin while (rs.next()) { resultMap.put( " + index + ", result); "
343343 + "\n >>>>>>>>>>>>>>>>>>>>>>>>>>> \n \n " );
344-
344+
345345 //缓存到 childMap
346346 cc .putWhere (j .getKey (), result .get (j .getKey ()), false );
347347 cacheSql = cc .getSQL (false );
@@ -351,12 +351,12 @@ protected void executeAppJoin(SQLConfig config, Map<Integer, JSONObject> resultM
351351 }
352352
353353 rs .close ();
354-
354+
355355
356356 long endTime = System .currentTimeMillis ();
357357 Log .d (TAG , "\n \n executeAppJoin endTime = " + endTime + "; duration = " + (endTime - startTime )
358358 + "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n \n " );
359-
359+
360360 }
361361 }
362362
@@ -429,25 +429,7 @@ protected JSONObject onPutColumn(@NotNull SQLConfig config, @NotNull ResultSet r
429429 }
430430 }
431431
432- Object value = rs .getObject (columnIndex );
433- // Log.d(TAG, "name:" + rsmd.getColumnName(i));
434- // Log.d(TAG, "lable:" + rsmd.getColumnLabel(i));
435- // Log.d(TAG, "type:" + rsmd.getColumnType(i));
436- // Log.d(TAG, "typeName:" + rsmd.getColumnTypeName(i));
437-
438- // Log.i(TAG, "select while (rs.next()) { >> for (int i = 0; i < length; i++) {"
439- // + "\n >>> value = " + value);
440-
441- if (value != null ) { //数据库查出来的null和empty值都有意义,去掉会导致 Moment:{ @column:"content" } 部分无结果及中断数组查询!
442- if (value instanceof Timestamp ) {
443- value = ((Timestamp ) value ).toString ();
444- }
445- else if (value instanceof String && isJSONType (rsmd , columnIndex )) { //json String
446- value = JSON .parse ((String ) value );
447- }
448- }
449-
450- finalTable .put (lable , value );
432+ finalTable .put (lable , getValue (config , rs , rsmd , tablePosition , table , columnIndex , childMap ));
451433
452434 return table ;
453435 }
@@ -469,6 +451,29 @@ protected Map<Integer, JSONObject> onPutTable(@NotNull SQLConfig config, @NotNul
469451 }
470452
471453
454+ protected Object getValue (@ NotNull SQLConfig config , @ NotNull ResultSet rs , @ NotNull ResultSetMetaData rsmd
455+ , final int tablePosition , @ NotNull JSONObject table , final int columnIndex , Map <String , JSONObject > childMap ) throws Exception {
456+
457+ Object value = rs .getObject (columnIndex );
458+ // Log.d(TAG, "name:" + rsmd.getColumnName(i));
459+ // Log.d(TAG, "lable:" + rsmd.getColumnLabel(i));
460+ // Log.d(TAG, "type:" + rsmd.getColumnType(i));
461+ // Log.d(TAG, "typeName:" + rsmd.getColumnTypeName(i));
462+
463+ // Log.i(TAG, "select while (rs.next()) { >> for (int i = 0; i < length; i++) {"
464+ // + "\n >>> value = " + value);
465+
466+ //数据库查出来的null和empty值都有意义,去掉会导致 Moment:{ @column:"content" } 部分无结果及中断数组查询!
467+ if (value instanceof Timestamp ) {
468+ value = ((Timestamp ) value ).toString ();
469+ }
470+ else if (value instanceof String && isJSONType (rsmd , columnIndex )) { //json String
471+ value = JSON .parse ((String ) value );
472+ }
473+
474+ return value ;
475+ }
476+
472477
473478 /**判断是否为JSON类型
474479 * @param rsmd
0 commit comments