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

Batch update return generated keys #28132

Conversation

ctailor2
Copy link
Contributor

@ctailor2 ctailor2 commented Mar 3, 2022

Add NamedParameterJdbcTemplate#batchUpdate methods taking KeyHolder and String[] keyColumnNames as counterparts to the NamedParameterJdbcTemplate#update methods of the same form.

This is in service of an enhancement to spring-data-jdbc to perform batch inserts to persist collections of entities referenced by an aggregate, when adequately supported by the database. The proposed changes to spring-data-jdbc currently include a copy of the changes being proposed here, and could be refactored to use the respective NamedParameterJdbcTemplate#batchUpdate once accepted and merged.

Related to #6530.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 3, 2022
@ctailor2 ctailor2 marked this pull request as ready for review March 3, 2022 22:33
@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Mar 4, 2022
@trisberg
Copy link
Member

trisberg commented Mar 9, 2022

I'm getting some checkstyle violations trying to build. Could you fix them so I can try this out? Thanks.

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Mar 10, 2022
This is to avoid frequent resizing of the row mapper ArrayList when extracted keys for a batch operation.
@ctailor2
Copy link
Contributor Author

@trisberg I resolved the checkstyle violations and made some other updates.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 16, 2022
@pworoniecki
Copy link

Any update on this topic? Is it abandoned or is something still to be considered?
Would be great to have this code merged (though I guess it needs some adjustment to the current state of the code).

@sabomichal
Copy link

Would be nice to have this merged already.

}
}

private PreparedStatementCallback<int[]> getPreparedStatementCallback(BatchPreparedStatementSetter pss, @Nullable KeyHolder generatedKeyHolder) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a more descriptive name:

Suggested change
private PreparedStatementCallback<int[]> getPreparedStatementCallback(BatchPreparedStatementSetter pss, @Nullable KeyHolder generatedKeyHolder) {
private PreparedStatementCallback<int[]> getPreparedStatementCallbackForBatchUpdate(BatchPreparedStatementSetter pss, @Nullable KeyHolder generatedKeyHolder) {

(Of course, also adjust this where it's used.)

@ePaul
Copy link

ePaul commented Aug 9, 2023

I just spent some hours trying to figure out how to implement this myself (or rather, how to generalize this Stack Overflow answer into something which works for my use case).

Only then I had the idea of checking whether someone already did something here, and it looks good.

@snicoll
Copy link
Member

snicoll commented Aug 27, 2023

@ctailor2 thanks for the PR, it misses some tests for the changes in NamedParameterJdbcTemplate though.

@schauder can you share your thoughts? I can see something in spring data jdbc was merged with a reference to a core framework class and I am a bit puzzled by that.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Aug 27, 2023
@schauder
Copy link
Contributor

@snicoll not sure what kind of thoughts you are looking for.

The changes in Spring Data JDBC are creating a copy of frameworks NamedParameterJdbcTemplate with the changes of this PR included, because we really needed the changes. We would be glad to go back to the official NamedParameterJdbcTemplate once this PR is merged.

@spring-projects-issues spring-projects-issues removed the status: waiting-for-feedback We need additional information before we can continue label Aug 28, 2023
@snicoll snicoll removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Sep 15, 2023
@snicoll snicoll added this to the 6.1.0-RC1 milestone Sep 15, 2023
snicoll pushed a commit that referenced this pull request Sep 15, 2023
snicoll added a commit that referenced this pull request Sep 15, 2023
@snicoll snicoll closed this in f628c60 Sep 15, 2023
@snicoll
Copy link
Member

snicoll commented Sep 15, 2023

@ctailor2 and all, thanks for your patience and please use NamedParameterJdbcTemplate proper again.

schauder added a commit to spring-projects/spring-data-relational that referenced this pull request Sep 18, 2023
BatchJdbcOperations is still there, but deprecated, and not used except for deprecated places kept for backward compatibility.

This is possible since Spring Framework made the features offered by `BatchJdbcOperations` part of `NamedParameterJdbcOperations`.

See spring-projects/spring-framework#28132
See #1191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants