|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2019 the original author or authors. |
| 2 | + * Copyright 2016-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
35 | 35 | * @author Glenn Renfro
|
36 | 36 | * @author Drummond Dawson
|
37 | 37 | * @author Mahmoud Ben Hassine
|
| 38 | + * @author Ankur Trapasiya |
38 | 39 | * @since 4.0
|
39 | 40 | */
|
40 | 41 | public class JdbcCursorItemReaderBuilder<T> {
|
@@ -69,6 +70,8 @@ public class JdbcCursorItemReaderBuilder<T> {
|
69 | 70 |
|
70 | 71 | private int currentItemCount;
|
71 | 72 |
|
| 73 | + private boolean connectionAutoCommit; |
| 74 | + |
72 | 75 | /**
|
73 | 76 | * Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
|
74 | 77 | * should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
|
@@ -321,6 +324,20 @@ public JdbcCursorItemReaderBuilder<T> beanRowMapper(Class<T> mappedClass) {
|
321 | 324 | return this;
|
322 | 325 | }
|
323 | 326 |
|
| 327 | + /** |
| 328 | + * Set whether "autoCommit" should be overridden for the connection used by the cursor. |
| 329 | + * If not set, defaults to Connection / Datasource default configuration. |
| 330 | + * |
| 331 | + * @param connectionAutoCommit value to set on underlying JDBC connection |
| 332 | + * @return this instance for method chaining |
| 333 | + * @see JdbcCursorItemReader#setConnectionAutoCommit(boolean) |
| 334 | + */ |
| 335 | + public JdbcCursorItemReaderBuilder<T> connectionAutoCommit(boolean connectionAutoCommit) { |
| 336 | + this.connectionAutoCommit = connectionAutoCommit; |
| 337 | + |
| 338 | + return this; |
| 339 | + } |
| 340 | + |
324 | 341 | /**
|
325 | 342 | * Validates configuration and builds a new reader instance.
|
326 | 343 | *
|
@@ -356,6 +373,7 @@ public JdbcCursorItemReader<T> build() {
|
356 | 373 | reader.setQueryTimeout(this.queryTimeout);
|
357 | 374 | reader.setUseSharedExtendedConnection(this.useSharedExtendedConnection);
|
358 | 375 | reader.setVerifyCursorPosition(this.verifyCursorPosition);
|
| 376 | + reader.setConnectionAutoCommit(this.connectionAutoCommit); |
359 | 377 |
|
360 | 378 | return reader;
|
361 | 379 | }
|
|
0 commit comments