diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java index 8ce8d3d2d..b136d3259 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2018 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. @@ -24,6 +24,7 @@ import org.springframework.batch.item.database.support.ListPreparedStatementSett import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; import org.springframework.jdbc.core.ArgumentTypePreparedStatementSetter; +import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.RowMapper; import org.springframework.util.Assert; @@ -310,6 +311,20 @@ public class JdbcCursorItemReaderBuilder { return this; } + /** + * Creates a {@link BeanPropertyRowMapper} to be used as your + * {@link RowMapper}. + * + * @param mappedClass the class for the row mapper + * @return this instance for method chaining + * @see BeanPropertyRowMapper + */ + public JdbcCursorItemReaderBuilder beanRowMapper(Class mappedClass) { + this.rowMapper = new BeanPropertyRowMapper<>(mappedClass); + + return this; + } + /** * Validates configuration and builds a new reader instance. * diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java index 3b8b7609f..d98ec9839 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2018 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. @@ -301,15 +301,7 @@ public class JdbcCursorItemReaderBuilderTests { .ignoreWarnings(true) .driverSupportsAbsolute(true) .useSharedExtendedConnection(true) - .rowMapper((rs, rowNum) -> { - Foo foo = new Foo(); - - foo.setFirst(rs.getInt("FIRST")); - foo.setSecond(rs.getString("SECOND")); - foo.setThird(rs.getString("THIRD")); - - return foo; - }) + .beanRowMapper(Foo.class) .build(); assertEquals(1, ReflectionTestUtils.getField(reader, "fetchSize"));