Skip to content

Commit 32692f9

Browse files
drumoniifmbenhassine
authored andcommitted
Add beanRowMapper to JdbcCursorItemReaderBuilder
Sets the rowMapper of the JdbcCursorItemReader as a BeanPropertyRowMapper. Resolves BATCH-2710
1 parent 24ab792 commit 32692f9

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import org.springframework.beans.factory.InitializingBean;
2525
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
2626
import org.springframework.jdbc.core.ArgumentTypePreparedStatementSetter;
27+
import org.springframework.jdbc.core.BeanPropertyRowMapper;
2728
import org.springframework.jdbc.core.PreparedStatementSetter;
2829
import org.springframework.jdbc.core.RowMapper;
2930
import org.springframework.util.Assert;
@@ -310,6 +311,20 @@ public JdbcCursorItemReaderBuilder<T> rowMapper(RowMapper<T> rowMapper) {
310311
return this;
311312
}
312313

314+
/**
315+
* Creates a {@link BeanPropertyRowMapper} to be used as your
316+
* {@link RowMapper}.
317+
*
318+
* @param mappedClass the class for the row mapper
319+
* @return this instance for method chaining
320+
* @see BeanPropertyRowMapper
321+
*/
322+
public JdbcCursorItemReaderBuilder<T> beanRowMapper(Class<T> mappedClass) {
323+
this.rowMapper = new BeanPropertyRowMapper<>(mappedClass);
324+
325+
return this;
326+
}
327+
313328
/**
314329
* Validates configuration and builds a new reader instance.
315330
*

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -301,15 +301,7 @@ public void testOtherProperties() {
301301
.ignoreWarnings(true)
302302
.driverSupportsAbsolute(true)
303303
.useSharedExtendedConnection(true)
304-
.rowMapper((rs, rowNum) -> {
305-
Foo foo = new Foo();
306-
307-
foo.setFirst(rs.getInt("FIRST"));
308-
foo.setSecond(rs.getString("SECOND"));
309-
foo.setThird(rs.getString("THIRD"));
310-
311-
return foo;
312-
})
304+
.beanRowMapper(Foo.class)
313305
.build();
314306

315307
assertEquals(1, ReflectionTestUtils.getField(reader, "fetchSize"));

0 commit comments

Comments
 (0)