Skip to content

Add connectionAutoCommit property in JdbcCursorItemReaderBuilder #3719

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ allprojects {
springVersionDefault = '5.3.0-SNAPSHOT'
springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault
springRetryVersion = '1.2.5.RELEASE'
springAmqpVersion = '2.3.0.BUILD-SNAPSHOT' // TODO update to 2.3.0-SNAPSHOT when available
springAmqpVersion = '2.3.0-SNAPSHOT'
springDataCommonsVersion = '2.4.0-SNAPSHOT'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to upgrade this version because my local build was failing

* What went wrong:
Execution failed for task ':spring-batch-infrastructure:compileJava'.
> Could not resolve all files for configuration ':spring-batch-infrastructure:compileClasspath'.
   > Could not find org.springframework.amqp:spring-amqp:2.2.7.

springDataGemfireVersion = '2.4.0-SNAPSHOT'
springDataJpaVersion = '2.4.0-SNAPSHOT'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author Glenn Renfro
* @author Drummond Dawson
* @author Mahmoud Ben Hassine
* @author Ankur Trapasiya
* @since 4.0
*/
public class JdbcCursorItemReaderBuilder<T> {
Expand Down Expand Up @@ -69,6 +70,8 @@ public class JdbcCursorItemReaderBuilder<T> {

private int currentItemCount;

private boolean connectionAutoCommit;

/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
Expand Down Expand Up @@ -321,6 +324,20 @@ public JdbcCursorItemReaderBuilder<T> beanRowMapper(Class<T> mappedClass) {
return this;
}

/**
* Set whether "autoCommit" should be overridden for the connection used by the cursor. If not set, defaults to
* Connection / Datasource default configuration.
*
* @param connectionAutoCommit value to set on underlying JDBC connection
* @return this instance for method chaining
* @see JdbcCursorItemReader#setConnectionAutoCommit(boolean)
*/
public JdbcCursorItemReaderBuilder<T> connectionAutoCommit(boolean connectionAutoCommit) {
this.connectionAutoCommit = connectionAutoCommit;

return this;
}

/**
* Validates configuration and builds a new reader instance.
*
Expand Down Expand Up @@ -356,6 +373,7 @@ public JdbcCursorItemReader<T> build() {
reader.setQueryTimeout(this.queryTimeout);
reader.setUseSharedExtendedConnection(this.useSharedExtendedConnection);
reader.setVerifyCursorPosition(this.verifyCursorPosition);
reader.setConnectionAutoCommit(this.connectionAutoCommit);

return reader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,15 @@ public void testOtherProperties() {
.ignoreWarnings(true)
.driverSupportsAbsolute(true)
.useSharedExtendedConnection(true)
.connectionAutoCommit(true)
.beanRowMapper(Foo.class)
.build();

assertEquals(1, ReflectionTestUtils.getField(reader, "fetchSize"));
assertEquals(2, ReflectionTestUtils.getField(reader, "queryTimeout"));
assertTrue((boolean) ReflectionTestUtils.getField(reader, "ignoreWarnings"));
assertTrue((boolean) ReflectionTestUtils.getField(reader, "driverSupportsAbsolute"));
assertTrue((boolean) ReflectionTestUtils.getField(reader, "connectionAutoCommit"));
}

@Test
Expand Down