incubator-seata
incubator-seata copied to clipboard
optimize: Enhance TCC annotation `@BusinessActionContextParameter`
optimize: Enhance TCC annotation @BusinessActionContextParameter
-
@BusinessActionContextParameter(paramName)
becomes optional -
@BusinessActionContextParameter(index)
supports used to theArray
param or field -
@BusinessActionContextParameter
: add new propertyfecther
, it can custom the parameter fetcher. The defaultfetcher
isDefaultParameterFetcher
.
优化:增强TCC注解@BusinessActionContextParameter
的功能。
-
@BusinessActionContextParameter
的paramName
或value
变为可选项。可以不用设置了,未设置时,TCC会自动读取方法参数名
或属性名
。 // 注:要想自动获取到方法参数名
,前提是源码编译命令需加上-parameters
参数进行编译。 -
@BusinessActionContextParameter
的index
支持使用在Array
类型的参数或属性上。 // 注:现已添加ParameterFetcher
的功能,建议使用该功能来自定义获取列表或数组的数据。 -
当
@BusinessActionContextParameter(isParamInProperty = true)
时,提取context的方法设置成了一个接口ParameterFetcher
,并可自定义实现。原来的fetch代码转移到默认接口实现DefaultParameterFetcher
中。目前,设想的
fetcher
的使用场景有以下两种:-
默认的
DefaultParameterFetcher
,使用的是反射来提取context,部分对性能要求比较高的用户,可自定义实现,来提升性能。 -
默认的
DefaultParameterFetcher
无法满足需求时,可自定义实现来特殊处理。
-
默认的
-
当
@BusinessActionContextParameter(isParamInProperty = true)
,同时paramName
或value
设置了值,那么从对象里读取到map会以paramName为key,添加到context中,而不是以每个属性名为key,属性值为value,逐个设置进去。 // 警告:此改动,会影响同时使用paramName
和isParamInProperty
属性的用户。但实际上,原来的功能,设置了isParamInProperty=true
后,再设置paramName
也是没有意义的(正因为这样使用没有意义,所以才想到扩展这种使用方式)。伪代码讲解优化4的变化:
-
优化后:
actionContext.put(paramName, map)
-
优化前:
map.forEach((key, value) -> { actionContext.put(key, value); });
-
优化后:
Codecov Report
Merging #3728 (e1f7bb6) into develop (61349de) will decrease coverage by
0.18%
. The diff coverage is62.29%
.
:exclamation: Current head e1f7bb6 differs from pull request most recent head d1e2281. Consider uploading reports for the commit d1e2281 to get more accurate results
@@ Coverage Diff @@
## develop #3728 +/- ##
=============================================
- Coverage 49.42% 49.23% -0.19%
+ Complexity 4115 4102 -13
=============================================
Files 736 737 +1
Lines 25721 25771 +50
Branches 3176 3186 +10
=============================================
- Hits 12713 12689 -24
- Misses 11662 11729 +67
- Partials 1346 1353 +7
Impacted Files | Coverage Δ | |
---|---|---|
...a/rm/tcc/interceptor/ActionInterceptorHandler.java | 13.97% <36.36%> (+1.93%) |
:arrow_up: |
...io/seata/rm/tcc/interceptor/ActionContextUtil.java | 39.83% <56.75%> (+5.42%) |
:arrow_up: |
...main/java/io/seata/common/util/ReflectionUtil.java | 67.25% <100.00%> (+1.81%) |
:arrow_up: |
...a/io/seata/rm/tcc/api/DefaultParameterFetcher.java | 100.00% <100.00%> (ø) |
|
...va/io/seata/server/console/vo/GlobalSessionVO.java | 22.05% <0.00%> (-33.83%) |
:arrow_down: |
...java/io/seata/server/storage/SessionConverter.java | 80.00% <0.00%> (-9.10%) |
:arrow_down: |
...n/src/main/java/io/seata/common/util/IdWorker.java | 77.08% <0.00%> (-6.25%) |
:arrow_down: |
...rage/redis/store/RedisTransactionStoreManager.java | 63.17% <0.00%> (-4.54%) |
:arrow_down: |
...ta/rm/datasource/exec/AbstractDMLBaseExecutor.java | 54.71% <0.00%> (-4.11%) |
:arrow_down: |
.../rm/datasource/exec/BaseTransactionalExecutor.java | 55.26% <0.00%> (-0.66%) |
:arrow_down: |
... and 2 more |
@tanzzj @long187 PTAL
@tanzzj ,先review #3730 吧。这个PR拆分成2个PR了。
看错pr,同3730
看错pr,同3730
这么晚还没睡啊。辛苦了。我明天看下。