diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java index d52ac900c..ae26762b7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2009 the original author or authors. + * Copyright 2008-2019 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. @@ -25,8 +25,8 @@ import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.JdbcCursorItemReader; -import org.springframework.batch.item.database.support.ListPreparedStatementSetter; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -64,7 +64,7 @@ public class JdbcCursorItemReaderPreparedStatementIntegrationTests { List parameters = new ArrayList<>(); parameters.add(1L); parameters.add(4L); - ListPreparedStatementSetter pss = new ListPreparedStatementSetter(parameters); + ArgumentPreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters.toArray()); itemReader.setPreparedStatementSetter(pss); } 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 8789fe85c..9d56869b1 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-2018 the original author or authors. + * Copyright 2016-2019 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. @@ -20,8 +20,6 @@ import javax.sql.DataSource; import org.springframework.batch.item.database.AbstractCursorItemReader; import org.springframework.batch.item.database.JdbcCursorItemReader; -import org.springframework.batch.item.database.support.ListPreparedStatementSetter; -import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; import org.springframework.jdbc.core.ArgumentTypePreparedStatementSetter; import org.springframework.jdbc.core.BeanPropertyRowMapper; @@ -36,6 +34,7 @@ import org.springframework.util.StringUtils; * @author Michael Minella * @author Glenn Renfro * @author Drummond Dawson + * @author Mahmoud Ben Hassine * @since 4.0 */ public class JdbcCursorItemReaderBuilder { @@ -274,14 +273,10 @@ public class JdbcCursorItemReaderBuilder { * * @param args values to set on the query * @return this instance for method chaining - * @throws Exception from {@link InitializingBean#afterPropertiesSet()} */ - public JdbcCursorItemReaderBuilder queryArguments(List args) throws Exception { - ListPreparedStatementSetter listPreparedStatementSetter = new ListPreparedStatementSetter(args); - - listPreparedStatementSetter.afterPropertiesSet(); - - this.preparedStatementSetter = listPreparedStatementSetter; + public JdbcCursorItemReaderBuilder queryArguments(List args) { + Assert.notNull(args, "The list of arguments must not be null"); + this.preparedStatementSetter = new ArgumentPreparedStatementSetter(args.toArray()); return this; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/ListPreparedStatementSetter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/ListPreparedStatementSetter.java index c9fc1f396..b5c60c9f2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/ListPreparedStatementSetter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/ListPreparedStatementSetter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2019 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,9 +35,14 @@ import org.springframework.util.Assert; * item in the list will be the first bind variable set. (i.e. it will * correspond to the first '?' in the SQL statement) * + * @deprecated use {@link org.springframework.jdbc.core.ArgumentPreparedStatementSetter} + * instead. + * * @author Lucas Ward + * @author Mahmoud Ben Hassine * */ +@Deprecated public class ListPreparedStatementSetter implements PreparedStatementSetter, InitializingBean { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java index 1bc206af5..4637a0207 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2019 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. @@ -15,7 +15,6 @@ */ package org.springframework.batch.item.database.builder; -import java.util.Collections; import javax.sql.DataSource; import org.junit.After; @@ -28,13 +27,13 @@ import test.jdbc.datasource.DerbyShutdownBean; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.FooRowMapper; import org.springframework.batch.item.database.StoredProcedureItemReader; -import org.springframework.batch.item.database.support.ListPreparedStatementSetter; import org.springframework.batch.item.sample.Foo; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.test.util.ReflectionTestUtils; @@ -47,6 +46,7 @@ import static org.junit.Assert.fail; /** * @author Michael Minella + * @author Mahmoud Ben Hassine */ public class StoredProcedureItemReaderBuilderTests { @@ -87,7 +87,7 @@ public class StoredProcedureItemReaderBuilderTests { @Test public void testConfiguration() { - ListPreparedStatementSetter preparedStatementSetter = new ListPreparedStatementSetter(Collections.EMPTY_LIST); + ArgumentPreparedStatementSetter preparedStatementSetter = new ArgumentPreparedStatementSetter(null); SqlParameter[] parameters = new SqlParameter[0];