Skip to content

Commit

Permalink
Add connectionAutoCommit property in JdbcCursorItemReaderBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurtrapasiya authored and fmbenhassine committed Jun 2, 2020
1 parent 8a6a2bd commit bbabe02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,6 +47,7 @@
/**
* @author Michael Minella
* @author Drummond Dawson
* @author Ankur Trapasiya
*/
public class JdbcCursorItemReaderBuilderTests {

Expand Down Expand Up @@ -302,13 +303,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

0 comments on commit bbabe02

Please sign in to comment.