Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support oracle and postgresql multi primary key #4457

Merged
merged 0 commits into from Aug 12, 2022
Merged

feature: support oracle and postgresql multi primary key #4457

merged 0 commits into from Aug 12, 2022

Conversation

tuwenlin
Copy link
Contributor

@tuwenlin tuwenlin commented Mar 10, 2022

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

support oracle and postgresql multi primary key
oracle和postgersql支持复合主键,请告知测试用例如何提供

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@funky-eyes
Copy link
Contributor

这是我们贡献者的钉钉群,你方便加一下吗,这样也方便交流
33774360

@tuwenlin
Copy link
Contributor Author

这是我们贡献者的钉钉群,你方便加一下吗,这样也方便交流 33774360

好的,稍后会加进去

@funky-eyes funky-eyes changed the title future:support oracle and postgresql multi primary key feature: support oracle and postgresql multi primary key Mar 11, 2022
@funky-eyes funky-eyes requested a review from jsbxyyx March 11, 2022 01:58
@funky-eyes funky-eyes modified the milestones: 1.5.0, 2.0.0 Mar 12, 2022
@tuwenlin
Copy link
Contributor Author

这是我们贡献者的钉钉群,你方便加一下吗,这样也方便交流 33774360

oracle和postgresql测试项目https://github.com/tuwenlin/seata-multi-pk-demo.git

@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2022

Codecov Report

Merging #4457 (234a24c) into develop (a05e5d9) will decrease coverage by 0.00%.
The diff coverage is 41.86%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #4457      +/-   ##
=============================================
- Coverage      49.45%   49.44%   -0.01%     
- Complexity      4071     4077       +6     
=============================================
  Files            732      732              
  Lines          25521    25517       -4     
  Branches        3153     3154       +1     
=============================================
- Hits           12621    12618       -3     
- Misses         11554    11564      +10     
+ Partials        1346     1335      -11     
Impacted Files Coverage Δ
...ta/rm/datasource/exec/AbstractDMLBaseExecutor.java 52.94% <ø> (-1.78%) ⬇️
.../rm/datasource/exec/mysql/MySQLInsertExecutor.java 69.14% <ø> (ø)
...source/exec/mysql/MySQLInsertOrUpdateExecutor.java 31.07% <0.00%> (ø)
...boot/autoconfigure/properties/SeataProperties.java 35.55% <0.00%> (-5.48%) ⬇️
...ing/boot/autoconfigure/SeataAutoConfiguration.java 0.00% <0.00%> (ø)
...ta/spring/annotation/GlobalTransactionScanner.java 30.65% <0.00%> (ø)
...o/seata/rm/datasource/exec/BaseInsertExecutor.java 72.19% <50.00%> (+1.06%) ⬆️
...urce/exec/postgresql/PostgresqlInsertExecutor.java 66.66% <57.14%> (+22.91%) ⬆️
...m/datasource/exec/oracle/OracleInsertExecutor.java 73.68% <69.23%> (+11.18%) ⬆️
...o/seata/server/coordinator/DefaultCoordinator.java 47.95% <0.00%> (-6.15%) ⬇️
... and 14 more

@slievrly slievrly added the module/rm-datasource rm-datasource module label Apr 3, 2022
@tuwenlin
Copy link
Contributor Author

tuwenlin commented May 5, 2022

这是我们贡献者的钉钉群,你方便加一下吗,这样也方便交流 33774360

oracle和postgresql测试项目https://github.com/tuwenlin/seata-multi-pk-demo.git

简单说一下实现思路:
首先,多主键只会在insert时用到,因为回滚要根据主键delete数据
Oracle主键分为四种类型处理:1.写在Insert语句中的主键.2.序列3.函数.4.NULL
1.写在Insert语句中的主键,通过解析sql获取,同时获取其他主键的类型
2.序列,通过getPkValuesBySequence方法获取,方法新增了参数pkKey,为主键的列名,先通过getGeneratedKeys方法中获取,这个方法也增加了参数pkKey,为什么要这么做,因为原getGeneratedKeys方法中,调用了targetStatement.getGeneratedKeys(),并默认获取了ResultSet中第一个作为主键,应该根据列名去获取主键,所以这两个方法增加了pkKey参数,如果无法通过targetStatement.getGeneratedKeys()获取主键value,执行对应的Sequence,去获取当前序列的值;
3.函数,函数类型的主键只能通过getGeneratedKeys方法去获取主键的value,获取不到value,则抛出不支持异常
4.NULL,NULL值的主键value也通过targetStatement.getGeneratedKeys()获取
PGSQL主键没有NULL值,有Default值,其余三种和Oracle获取value一样
PGSQL的Default类型通过getPkValuesByDefault方法获取,先通过metadata获取默认值,再根据默认值,按照3种类型再去解析

最终,多主键最多允许一个为NULL,不允许出现函数(这块跟上面有冲突,抽空验证后再觉得是否要去掉上述函数类型分支)

@slievrly slievrly self-requested a review June 1, 2022 02:57
@funky-eyes funky-eyes modified the milestones: 2.0.0, 1.6.0 Aug 11, 2022
@funky-eyes funky-eyes added the type: feature Category issues or prs related to feature request. label Aug 11, 2022
@tuwenlin tuwenlin merged commit 61349de into apache:develop Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/rm-datasource rm-datasource module type: feature Category issues or prs related to feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants