Skip to content

Commit 9bd7c1b

Browse files
committed
BATCH-2465: add note about the importance to have a unique key
constraint on the sortKey This PR is for BATCH-2465. It updates the reference documentation and the Javadoc to mention explicitly the importance to have a unique key constraint on the sortKey when using paging item readers. I deliberately used "It is important" and not "It is required" (or mandatory) because in the end this is not required but in that case there is no guarantee to not lose data between executions. Please let me know if the wording should be updated.
1 parent 8684ff9 commit 9bd7c1b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

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

Lines changed: 3 additions & 2 deletions
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-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.
@@ -51,7 +51,8 @@
5151
* needed as {@link #read()} method is called, returning an object corresponding
5252
* to current position. On restart it uses the last sort key value to locate the
5353
* first page to read (so it doesn't matter if the successfully processed items
54-
* have been removed or modified).
54+
* have been removed or modified). It is important to have a unique key constraint on the
55+
* sort key to guarantee that no data is lost between executions.
5556
* </p>
5657
*
5758
* <p>

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
package org.springframework.batch.item.database.support;
1818

19+
import java.util.ArrayList;
20+
import java.util.LinkedHashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
import javax.sql.DataSource;
24+
1925
import org.springframework.batch.item.database.JdbcParameterUtils;
2026
import org.springframework.batch.item.database.Order;
2127
import org.springframework.batch.item.database.PagingQueryProvider;
2228
import org.springframework.dao.InvalidDataAccessApiUsageException;
2329
import org.springframework.util.Assert;
2430
import org.springframework.util.StringUtils;
2531

26-
import javax.sql.DataSource;
27-
import java.util.ArrayList;
28-
import java.util.LinkedHashMap;
29-
import java.util.List;
30-
import java.util.Map;
31-
3232
/**
3333
* Abstract SQL Paging Query Provider to serve as a base class for all provided
3434
* SQL paging query providers.
@@ -42,7 +42,9 @@
4242
* Provides properties and preparation for the mandatory "selectClause" and
4343
* "fromClause" as well as for the optional "whereClause". Also provides
4444
* property for the mandatory "sortKeys". <b>Note:</b> The columns that make up
45-
* the sort key must be a true key and not just a column to order by.
45+
* the sort key must be a true key and not just a column to order by. It is important
46+
* to have a unique key constraint on the sort key to guarantee that no data is lost
47+
* between executions.
4648
*
4749
* @author Thomas Risberg
4850
* @author Dave Syer

src/site/docbook/reference/readersAndWriters.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,9 @@ itemReader.close(executionContext);</programlisting>
21922192
also provide an optional where clause. These clauses will be used to
21932193
build an SQL statement combined with the required sortKey.</para>
21942194

2195+
<note>It is important to have a unique key constraint on the `sortKey` to
2196+
guarantee that no data is lost between executions.</note>
2197+
21952198
<para>After the reader has been opened, it will pass back one item per
21962199
call to <methodname>read</methodname> in the same basic fashion as any
21972200
other <classname>ItemReader</classname>. The paging happens behind the

0 commit comments

Comments
 (0)