37
37
* @author Lemon
38
38
*/
39
39
public abstract class AbstractParser <T , M extends Map <String , Object >, L extends List <Object >>
40
- implements Parser <T , M , L >, ParserCreator < T , M , L >, VerifierCreator < T , M , L >, SQLCreator < T , M , L > {
40
+ implements Parser <T , M , L > {
41
41
protected static final String TAG = "AbstractParser" ;
42
42
43
43
/**
@@ -411,7 +411,6 @@ public AbstractParser<T, M, L> setNeedVerifyContent(boolean needVerifyContent) {
411
411
return this ;
412
412
}
413
413
414
-
415
414
protected SQLExecutor <T , M , L > sqlExecutor ;
416
415
protected Verifier <T , M , L > verifier ;
417
416
protected Map <String , Object > queryResultMap ;//path-result
@@ -420,15 +419,16 @@ public AbstractParser<T, M, L> setNeedVerifyContent(boolean needVerifyContent) {
420
419
public SQLExecutor <T , M , L > getSQLExecutor () {
421
420
if (sqlExecutor == null ) {
422
421
sqlExecutor = createSQLExecutor ();
423
- sqlExecutor .setParser (this );
424
422
}
423
+ sqlExecutor .setParser (this );
425
424
return sqlExecutor ;
426
425
}
427
426
@ Override
428
427
public Verifier <T , M , L > getVerifier () {
429
428
if (verifier == null ) {
430
429
verifier = createVerifier ().setVisitor (getVisitor ());
431
430
}
431
+ verifier .setParser (this );
432
432
return verifier ;
433
433
}
434
434
@@ -437,13 +437,14 @@ public Verifier<T, M, L> getVerifier() {
437
437
* @return
438
438
* @throws Exception
439
439
*/
440
- @ NotNull
441
440
public static <M extends Map <String , Object >> M parseRequest (String request ) throws Exception {
442
- M obj = JSON .parseObject (request );
443
- if (obj == null ) {
444
- throw new UnsupportedEncodingException ("JSON格式不合法!" );
441
+ try {
442
+ M req = JSON .parseObject (request );
443
+ Objects .requireNonNull (req );
444
+ return req ;
445
+ } catch (Throwable e ) {
446
+ throw new UnsupportedEncodingException ("JSON格式不合法!" + e .getMessage () + "! " + request );
445
447
}
446
- return obj ;
447
448
}
448
449
449
450
/**解析请求json并获取对应结果
@@ -569,7 +570,6 @@ public M parseResponse(M request) {
569
570
570
571
final String requestString = JSON .toJSONString (request );//request传进去解析后已经变了
571
572
572
-
573
573
queryResultMap = new HashMap <String , Object >();
574
574
575
575
Exception error = null ;
@@ -608,7 +608,8 @@ public M parseResponse(M request) {
608
608
609
609
res .putIfAbsent ("time" , endTime );
610
610
if (Log .DEBUG ) {
611
- res .put ("sql:generate|cache|execute|maxExecute" , getSQLExecutor ().getGeneratedSQLCount () + "|" + getSQLExecutor ().getCachedSQLCount () + "|" + getSQLExecutor ().getExecutedSQLCount () + "|" + getMaxSQLCount ());
611
+ sqlExecutor = getSQLExecutor ();
612
+ res .put ("sql:generate|cache|execute|maxExecute" , sqlExecutor .getGeneratedSQLCount () + "|" + sqlExecutor .getCachedSQLCount () + "|" + sqlExecutor .getExecutedSQLCount () + "|" + getMaxSQLCount ());
612
613
res .put ("depth:count|max" , queryDepth + "|" + getMaxQueryDepth ());
613
614
614
615
executedSQLDuration += sqlExecutor .getExecutedSQLDuration () + sqlExecutor .getSqlResultDuration ();
@@ -639,6 +640,7 @@ public M parseResponse(M request) {
639
640
Log .fd (TAG , requestMethod + "/parseResponse endTime = " + endTime + "; duration = " + duration );
640
641
Log .sl ("" , '>' , "\n \n \n " );
641
642
}
643
+
642
644
return res ;
643
645
}
644
646
@@ -1085,6 +1087,7 @@ public M getStructure(@NotNull String table, String method, String tag, int vers
1085
1087
1086
1088
// 获取指定的JSON结构 <<<<<<<<<<<<<<
1087
1089
SQLConfig <T , M , L > config = createSQLConfig ().setMethod (GET ).setTable (table );
1090
+ config .setParser (this );
1088
1091
config .setPrepared (false );
1089
1092
config .setColumn (Arrays .asList ("structure" ));
1090
1093
@@ -2105,8 +2108,7 @@ public M executeSQL(SQLConfig<T, M, L> config, boolean isSubquery) throws Except
2105
2108
}
2106
2109
}
2107
2110
else {
2108
- sqlExecutor = getSQLExecutor ();
2109
- result = sqlExecutor .execute (config , false );
2111
+ result = getSQLExecutor ().execute (config , false );
2110
2112
// FIXME 改为直接在 sqlExecutor 内加好,最后 Parser<T, M, L> 取结果,可以解决并发执行导致内部计算出错
2111
2113
// executedSQLDuration += sqlExecutor.getExecutedSQLDuration() + sqlExecutor.getSqlResultDuration();
2112
2114
}
@@ -2531,7 +2533,7 @@ protected M objectVerify(RequestMethod method, String tag, int version, String n
2531
2533
// 获取指定的JSON结构 >>>>>>>>>>>>>>
2532
2534
M target = wrapRequest (method , tag , object , true );
2533
2535
// Map<String, Object> clone 浅拷贝没用,Structure.parse 会导致 structure 里面被清空,第二次从缓存里取到的就是 {}
2534
- return getVerifier ().verifyRequest (method , name , target , request , maxUpdateCount , getGlobalDatabase (), getGlobalSchema (), creator );
2536
+ return getVerifier ().setParser ( this ). verifyRequest (method , name , target , request , maxUpdateCount , getGlobalDatabase (), getGlobalSchema ());
2535
2537
}
2536
2538
2537
2539
/***
0 commit comments