Skip to content

Commit 6a93f6e

Browse files
committed
Rename MongoItemReader to MongoPagingItemReader
Resolves #4341
1 parent e6c2727 commit 6a93f6e

File tree

6 files changed

+400
-56
lines changed

6 files changed

+400
-56
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -77,26 +77,29 @@
7777
* @author Takaaki Iida
7878
* @author Mahmoud Ben Hassine
7979
* @author Parikshit Dutta
80+
* @deprecated Use {@link MongoPagingItemReader} instead. Scheduled for removal in v5.3 or
81+
* later.
8082
*/
83+
@Deprecated(since = "5.1", forRemoval = true)
8184
public class MongoItemReader<T> extends AbstractPaginatedDataItemReader<T> implements InitializingBean {
8285

83-
private MongoOperations template;
86+
protected MongoOperations template;
8487

85-
private Query query;
88+
protected Query query;
8689

87-
private String queryString;
90+
protected String queryString;
8891

89-
private Class<? extends T> type;
92+
protected Class<? extends T> type;
9093

91-
private Sort sort;
94+
protected Sort sort;
9295

93-
private String hint;
96+
protected String hint;
9497

95-
private String fields;
98+
protected String fields;
9699

97-
private String collection;
100+
protected String collection;
98101

99-
private List<Object> parameterValues = new ArrayList<>();
102+
protected List<Object> parameterValues = new ArrayList<>();
100103

101104
public MongoItemReader() {
102105
super();
@@ -243,14 +246,14 @@ public void afterPropertiesSet() throws Exception {
243246
}
244247
}
245248

246-
private String replacePlaceholders(String input, List<Object> values) {
249+
protected String replacePlaceholders(String input, List<Object> values) {
247250
ParameterBindingJsonReader reader = new ParameterBindingJsonReader(input, values.toArray());
248251
DecoderContext decoderContext = DecoderContext.builder().build();
249252
Document document = new ParameterBindingDocumentCodec().decode(reader, decoderContext);
250253
return document.toJson();
251254
}
252255

253-
private Sort convertToSort(Map<String, Sort.Direction> sorts) {
256+
protected Sort convertToSort(Map<String, Sort.Direction> sorts) {
254257
List<Sort.Order> sortValues = new ArrayList<>(sorts.size());
255258

256259
for (Map.Entry<String, Sort.Direction> curSort : sorts.entrySet()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.item.data;
17+
18+
import org.springframework.batch.item.ExecutionContext;
19+
import org.springframework.batch.item.ItemReader;
20+
import org.springframework.data.mongodb.core.query.Query;
21+
import org.springframework.util.ClassUtils;
22+
23+
/**
24+
* <p>
25+
* Restartable {@link ItemReader} that reads documents from MongoDB via a paging
26+
* technique.
27+
* </p>
28+
*
29+
* <p>
30+
* If you set JSON String query {@link #setQuery(String)} then it executes the JSON to
31+
* retrieve the requested documents.
32+
* </p>
33+
*
34+
* <p>
35+
* If you set Query object {@link #setQuery(Query)} then it executes the Query to retrieve
36+
* the requested documents.
37+
* </p>
38+
*
39+
* <p>
40+
* The query is executed using paged requests specified in the {@link #setPageSize(int)}.
41+
* Additional pages are requested as needed to provide data when the {@link #read()}
42+
* method is called.
43+
* </p>
44+
*
45+
* <p>
46+
* The JSON String query provided supports parameter substitution via ?&lt;index&gt;
47+
* placeholders where the &lt;index&gt; indicates the index of the parameterValue to
48+
* substitute.
49+
* </p>
50+
*
51+
* <p>
52+
* The implementation is thread-safe between calls to {@link #open(ExecutionContext)}, but
53+
* remember to use <code>saveState=false</code> if used in a multi-threaded client (no
54+
* restart available).
55+
* </p>
56+
*
57+
* @param <T> type of items to read
58+
* @since 5.1
59+
* @author Michael Minella
60+
* @author Takaaki Iida
61+
* @author Mahmoud Ben Hassine
62+
* @author Parikshit Dutta
63+
*/
64+
public class MongoPagingItemReader<T> extends MongoItemReader<T> {
65+
66+
/**
67+
* Create a new {@link MongoPagingItemReader}.
68+
*/
69+
public MongoPagingItemReader() {
70+
setName(ClassUtils.getShortName(MongoPagingItemReader.class));
71+
}
72+
73+
}

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2022 the original author or authors.
2+
* Copyright 2017-2023 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.
@@ -37,36 +37,39 @@
3737
* @author Parikshit Dutta
3838
* @since 4.0
3939
* @see MongoItemReader
40+
* @deprecated Use {@link MongoPagingItemReaderBuilder} instead. Scheduled for removal in
41+
* v5.3 or later.
4042
*/
43+
@Deprecated(since = "5.1", forRemoval = true)
4144
public class MongoItemReaderBuilder<T> {
4245

43-
private MongoOperations template;
46+
protected MongoOperations template;
4447

45-
private String jsonQuery;
48+
protected String jsonQuery;
4649

47-
private Class<? extends T> targetType;
50+
protected Class<? extends T> targetType;
4851

49-
private Map<String, Sort.Direction> sorts;
52+
protected Map<String, Sort.Direction> sorts;
5053

51-
private String hint;
54+
protected String hint;
5255

53-
private String fields;
56+
protected String fields;
5457

55-
private String collection;
58+
protected String collection;
5659

57-
private List<Object> parameterValues = new ArrayList<>();
60+
protected List<Object> parameterValues = new ArrayList<>();
5861

5962
protected int pageSize = 10;
6063

61-
private boolean saveState = true;
64+
protected boolean saveState = true;
6265

63-
private String name;
66+
protected String name;
6467

65-
private int maxItemCount = Integer.MAX_VALUE;
68+
protected int maxItemCount = Integer.MAX_VALUE;
6669

67-
private int currentItemCount;
70+
protected int currentItemCount;
6871

69-
private Query query;
72+
protected Query query;
7073

7174
/**
7275
* Configure if the state of the

0 commit comments

Comments
 (0)