Skip to content

Added AbstractCursorItemReader.connectionAutoCommit #446

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

Conversation

gdarmont
Copy link
Contributor

@gdarmont gdarmont commented Jan 6, 2017

This PR is a follow up of discussion in PR spring-projects/spring-boot#7866

The use case was to use a JdbcCursorItemReader with PostgreSQL (nothing fancy here).
From https://jdbc.postgresql.org/documentation/94/query.html, section "Getting results based on a cursor", the connection must not be in auto commit mode.
But JdbcCursorItemReader does not allow to explicity set connection mode to autoCommit = false.

As discussed in the Spring Boot PR, configuring the JDBC pool to force all connection to autoCommit=false is not an optimal way to workaround the problem.

So here's a little PR that allows configuration of autocommit mode for the connection used by a CursorItemReader.

I validated the use of a Boolean wrapper against https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java#L65, to keep Spring philosophy.

Hope this helps,
Guillaume

@@ -424,6 +444,9 @@ protected void initializeConnection() {
else {
this.con = dataSource.getConnection();
}
if (this.connectionAutoCommit != null && this.con.getAutoCommit() != this.connectionAutoCommit) {
this.con.setAutoCommit(this.connectionAutoCommit);
}
Copy link
Member

Choose a reason for hiding this comment

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

If we allow this, we need to set it back to what it was once we're done with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review.
I added the necessary code and amended the commit.

@gdarmont gdarmont force-pushed the pr-cursoritemreader-autocommit branch 3 times, most recently from 65ce40b to 9d8e033 Compare January 9, 2017 22:02
… of cursor connection autoCommit value

autoCommit value is restored after connection use.
@gdarmont gdarmont force-pushed the pr-cursoritemreader-autocommit branch from 9d8e033 to 281b387 Compare January 9, 2017 22:04
@gdarmont
Copy link
Contributor Author

Hi Spring Batch Team,

Do you think there is additional work to to on this PR ? I'd be happy to help.

Guillaume

@mminella
Copy link
Member

Rebased and merged as dca726a. Also created Jira issue BATCH-2661 for this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants