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 #4863
Conversation
原pr ##4457 落后太多了,已close |
Codecov Report
@@ Coverage Diff @@
## develop #4863 +/- ##
=============================================
+ Coverage 49.15% 49.30% +0.15%
- Complexity 4094 4118 +24
=============================================
Files 737 737
Lines 25750 25778 +28
Branches 3181 3187 +6
=============================================
+ Hits 12658 12711 +53
+ Misses 11737 11720 -17
+ Partials 1355 1347 -8
|
* @return | ||
* @throws SQLException | ||
*/ | ||
public List<Object> getGeneratedKeys() throws SQLException { | ||
public List<Object> getGeneratedKeys(String pkKey) throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议改成方法重载方式,避免涉及太多改动
1.在线验证,update,delete不受insert多主键支持影响,生成的后镜像where条件是准的 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Test pass.
简单说一下实现思路:
首先,多主键只会在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,不允许出现函数(这块跟上面有冲突,抽空验证后再觉得是否要去掉上述函数类型分支)