Add connectionAutoCommit property in JdbcCursorItemReaderBuilder

Issue #3717
This commit is contained in:
Ankur Trapasiya
2020-05-26 18:43:20 -04:00
committed by Mahmoud Ben Hassine
parent 8a6a2bd19a
commit bbabe0263a
2 changed files with 23 additions and 2 deletions

View File

@@ -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.
@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
* @author Glenn Renfro
* @author Drummond Dawson
* @author Mahmoud Ben Hassine
* @author Ankur Trapasiya
* @since 4.0
*/
public class JdbcCursorItemReaderBuilder<T> {
@@ -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}
@@ -321,6 +324,20 @@ public class JdbcCursorItemReaderBuilder<T> {
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.
*
@@ -356,6 +373,7 @@ public class JdbcCursorItemReaderBuilder<T> {
reader.setQueryTimeout(this.queryTimeout);
reader.setUseSharedExtendedConnection(this.useSharedExtendedConnection);
reader.setVerifyCursorPosition(this.verifyCursorPosition);
reader.setConnectionAutoCommit(this.connectionAutoCommit);
return reader;
}