incubator-seata icon indicating copy to clipboard operation
incubator-seata copied to clipboard

optimize: Enhance TCC annotation `@BusinessActionContextParameter`

Open wangliang181230 opened this issue 3 years ago • 5 comments

optimize: Enhance TCC annotation @BusinessActionContextParameter

  1. @BusinessActionContextParameter(paramName) becomes optional
  2. @BusinessActionContextParameter(index) supports used to the Array param or field
  3. @BusinessActionContextParameter: add new property fecther, it can custom the parameter fetcher. The default fetcher is DefaultParameterFetcher.

优化:增强TCC注解@BusinessActionContextParameter的功能。

  1. @BusinessActionContextParameterparamNamevalue变为可选项。可以不用设置了,未设置时,TCC会自动读取方法参数名属性名 // 注:要想自动获取到方法参数名,前提是源码编译命令需加上-parameters参数进行编译。

  2. @BusinessActionContextParameterindex支持使用在Array类型的参数或属性上。 // 注:现已添加ParameterFetcher的功能,建议使用该功能来自定义获取列表或数组的数据。

  3. @BusinessActionContextParameter(isParamInProperty = true)时,提取context的方法设置成了一个接口ParameterFetcher,并可自定义实现。原来的fetch代码转移到默认接口实现DefaultParameterFetcher中。

    目前,设想的fetcher的使用场景有以下两种:

    1. 默认的DefaultParameterFetcher,使用的是反射来提取context,部分对性能要求比较高的用户,可自定义实现,来提升性能。
    2. 默认的DefaultParameterFetcher无法满足需求时,可自定义实现来特殊处理。
  4. @BusinessActionContextParameter(isParamInProperty = true),同时paramNamevalue设置了值,那么从对象里读取到map会以paramName为key,添加到context中,而不是以每个属性名为key,属性值为value,逐个设置进去。 // 警告:此改动,会影响同时使用paramNameisParamInProperty属性的用户。但实际上,原来的功能,设置了isParamInProperty=true后,再设置paramName也是没有意义的(正因为这样使用没有意义,所以才想到扩展这种使用方式)。

    伪代码讲解优化4的变化:

    1. 优化后:actionContext.put(paramName, map)
    2. 优化前:map.forEach((key, value) -> { actionContext.put(key, value); });

wangliang181230 avatar May 13 '21 09:05 wangliang181230

Codecov Report

Merging #3728 (e1f7bb6) into develop (61349de) will decrease coverage by 0.18%. The diff coverage is 62.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

Impacted file tree graph

@@              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

codecov-commenter avatar May 13 '21 10:05 codecov-commenter

@tanzzj @long187 PTAL

wangliang181230 avatar May 14 '21 05:05 wangliang181230

@tanzzj ,先review #3730 吧。这个PR拆分成2个PR了。

wangliang181230 avatar May 19 '21 19:05 wangliang181230

看错pr,同3730

tanzzj avatar May 24 '21 17:05 tanzzj

看错pr,同3730

这么晚还没睡啊。辛苦了。我明天看下。

wangliang181230 avatar May 24 '21 17:05 wangliang181230

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Dec 12 '22 13:12 CLAassistant