Skip to content

Commit 5b46c91

Browse files
committed
Deprecate ListPreparedStatementSetter in favor of ArgumentPreparedStatementSetter
ListPreparedStatementSetter is almost a duplicate of ArgumentPreparedStatementSetter except that it accepts a List of arguments instead of an array of arguments. Resolves BATCH-2796
1 parent 2306141 commit 5b46c91

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2009 the original author or authors.
2+
* Copyright 2008-2019 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.
@@ -25,8 +25,8 @@
2525

2626
import org.springframework.batch.item.ExecutionContext;
2727
import org.springframework.batch.item.database.JdbcCursorItemReader;
28-
import org.springframework.batch.item.database.support.ListPreparedStatementSetter;
2928
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
3030
import org.springframework.test.context.ContextConfiguration;
3131
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3232
import org.springframework.transaction.annotation.Transactional;
@@ -64,7 +64,7 @@ public void onSetUpInTransaction() throws Exception {
6464
List<Long> parameters = new ArrayList<>();
6565
parameters.add(1L);
6666
parameters.add(4L);
67-
ListPreparedStatementSetter pss = new ListPreparedStatementSetter(parameters);
67+
ArgumentPreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters.toArray());
6868

6969
itemReader.setPreparedStatementSetter(pss);
7070
}

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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.
@@ -20,8 +20,6 @@
2020

2121
import org.springframework.batch.item.database.AbstractCursorItemReader;
2222
import org.springframework.batch.item.database.JdbcCursorItemReader;
23-
import org.springframework.batch.item.database.support.ListPreparedStatementSetter;
24-
import org.springframework.beans.factory.InitializingBean;
2523
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
2624
import org.springframework.jdbc.core.ArgumentTypePreparedStatementSetter;
2725
import org.springframework.jdbc.core.BeanPropertyRowMapper;
@@ -36,6 +34,7 @@
3634
* @author Michael Minella
3735
* @author Glenn Renfro
3836
* @author Drummond Dawson
37+
* @author Mahmoud Ben Hassine
3938
* @since 4.0
4039
*/
4140
public class JdbcCursorItemReaderBuilder<T> {
@@ -274,14 +273,10 @@ public JdbcCursorItemReaderBuilder<T> queryArguments(Object[] args, int[] types)
274273
*
275274
* @param args values to set on the query
276275
* @return this instance for method chaining
277-
* @throws Exception from {@link InitializingBean#afterPropertiesSet()}
278276
*/
279-
public JdbcCursorItemReaderBuilder<T> queryArguments(List<?> args) throws Exception {
280-
ListPreparedStatementSetter listPreparedStatementSetter = new ListPreparedStatementSetter(args);
281-
282-
listPreparedStatementSetter.afterPropertiesSet();
283-
284-
this.preparedStatementSetter = listPreparedStatementSetter;
277+
public JdbcCursorItemReaderBuilder<T> queryArguments(List<?> args) {
278+
Assert.notNull(args, "The list of arguments must not be null");
279+
this.preparedStatementSetter = new ArgumentPreparedStatementSetter(args.toArray());
285280

286281
return this;
287282
}

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/ListPreparedStatementSetter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2019 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.
@@ -35,9 +35,14 @@
3535
* item in the list will be the first bind variable set. (i.e. it will
3636
* correspond to the first '?' in the SQL statement)
3737
*
38+
* @deprecated use {@link org.springframework.jdbc.core.ArgumentPreparedStatementSetter}
39+
* instead.
40+
*
3841
* @author Lucas Ward
42+
* @author Mahmoud Ben Hassine
3943
*
4044
*/
45+
@Deprecated
4146
public class ListPreparedStatementSetter implements
4247
PreparedStatementSetter, InitializingBean {
4348

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2019 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.
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.batch.item.database.builder;
1717

18-
import java.util.Collections;
1918
import javax.sql.DataSource;
2019

2120
import org.junit.After;
@@ -28,13 +27,13 @@
2827
import org.springframework.batch.item.ExecutionContext;
2928
import org.springframework.batch.item.database.FooRowMapper;
3029
import org.springframework.batch.item.database.StoredProcedureItemReader;
31-
import org.springframework.batch.item.database.support.ListPreparedStatementSetter;
3230
import org.springframework.batch.item.sample.Foo;
3331
import org.springframework.context.ConfigurableApplicationContext;
3432
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3533
import org.springframework.context.annotation.Bean;
3634
import org.springframework.context.annotation.Configuration;
3735
import org.springframework.core.io.ClassPathResource;
36+
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
3837
import org.springframework.jdbc.core.SqlParameter;
3938
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
4039
import org.springframework.test.util.ReflectionTestUtils;
@@ -47,6 +46,7 @@
4746

4847
/**
4948
* @author Michael Minella
49+
* @author Mahmoud Ben Hassine
5050
*/
5151
public class StoredProcedureItemReaderBuilderTests {
5252

@@ -87,7 +87,7 @@ public void testSunnyScenario() throws Exception {
8787

8888
@Test
8989
public void testConfiguration() {
90-
ListPreparedStatementSetter preparedStatementSetter = new ListPreparedStatementSetter(Collections.EMPTY_LIST);
90+
ArgumentPreparedStatementSetter preparedStatementSetter = new ArgumentPreparedStatementSetter(null);
9191

9292
SqlParameter[] parameters = new SqlParameter[0];
9393

0 commit comments

Comments
 (0)