Skip to content

Commit 220de61

Browse files
hpoettkerfmbenhassine
authored andcommitted
Remove un-used code for jump-to-item queries
1 parent 1a65c00 commit 220de61

33 files changed

+14
-1023
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -156,14 +156,10 @@ protected void jumpToItem(int itemIndex) throws Exception {
156156
current = itemIndex % pageSize;
157157
}
158158

159-
doJumpToPage(itemIndex);
160-
161159
if (logger.isDebugEnabled()) {
162160
logger.debug("Jumping to page " + getPage() + " and index " + current);
163161
}
164162

165163
}
166164

167-
abstract protected void doJumpToPage(int itemIndex);
168-
169165
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ protected void doReadPage() {
157157

158158
}
159159

160-
@Override
161-
protected void doJumpToPage(int itemIndex) {
162-
}
163-
164160
@Override
165161
protected void doClose() throws Exception {
166162
helper.close();

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -254,33 +254,6 @@ public void open(ExecutionContext executionContext) {
254254
super.open(executionContext);
255255
}
256256

257-
@Override
258-
protected void doJumpToPage(int itemIndex) {
259-
/*
260-
* Normally this would be false (the startAfterValue is enough information to
261-
* restart from.
262-
*/
263-
// TODO: this is dead code, startAfterValues is never null - see
264-
// #open(ExecutionContext)
265-
if (startAfterValues == null && getPage() > 0) {
266-
267-
String jumpToItemSql = queryProvider.generateJumpToItemQuery(itemIndex, getPageSize());
268-
269-
if (logger.isDebugEnabled()) {
270-
logger.debug("SQL used for jumping: [" + jumpToItemSql + "]");
271-
}
272-
273-
if (this.queryProvider.isUsingNamedParameters()) {
274-
startAfterValues = namedParameterJdbcTemplate.queryForMap(jumpToItemSql,
275-
getParameterMap(parameterValues, null));
276-
}
277-
else {
278-
startAfterValues = getJdbcTemplate().queryForMap(jumpToItemSql,
279-
getParameterList(parameterValues, null).toArray());
280-
}
281-
}
282-
}
283-
284257
private Map<String, Object> getParameterMap(Map<String, Object> values, Map<String, Object> sortKeyValues) {
285258
Map<String, Object> parameterMap = new LinkedHashMap<>();
286259
if (values != null) {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -221,10 +221,6 @@ protected void doReadPage() {
221221
} // end if
222222
}
223223

224-
@Override
225-
protected void doJumpToPage(int itemIndex) {
226-
}
227-
228224
@Override
229225
protected void doClose() throws Exception {
230226
entityManager.close();

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2012 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -50,18 +50,6 @@ public interface PagingQueryProvider {
5050
*/
5151
String generateRemainingPagesQuery(int pageSize);
5252

53-
/**
54-
*
55-
* Generate the query that will provide the jump to item query. The itemIndex provided
56-
* could be in the middle of the page and together with the page size it will be used
57-
* to calculate the last index of the preceding page to be able to retrieve the sort
58-
* key for this row.
59-
* @param itemIndex the index for the next item to be read
60-
* @param pageSize number of rows to read for each page
61-
* @return the generated query
62-
*/
63-
String generateJumpToItemQuery(int itemIndex, int pageSize);
64-
6553
/**
6654
* The number of parameters that are declared in the query
6755
* @return number of parameters

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -221,16 +221,6 @@ public void init(DataSource dataSource) throws Exception {
221221
@Override
222222
public abstract String generateRemainingPagesQuery(int pageSize);
223223

224-
/**
225-
* Method generating the query string to be used for jumping to a specific item
226-
* position. This method must be implemented in sub classes.
227-
* @param itemIndex the index of the item to jump to
228-
* @param pageSize number of rows to read per page
229-
* @return query string
230-
*/
231-
@Override
232-
public abstract String generateJumpToItemQuery(int itemIndex, int pageSize);
233-
234224
private String removeKeyWord(String keyWord, String clause) {
235225
String temp = clause.trim();
236226
int length = keyWord.length();

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,4 @@ private String buildLimitClause(int pageSize) {
4141
return new StringBuilder().append("FETCH NEXT ").append(pageSize).append(" ROWS ONLY").toString();
4242
}
4343

44-
@Override
45-
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
46-
int page = itemIndex / pageSize;
47-
int offset = (page * pageSize) - 1;
48-
offset = offset < 0 ? 0 : offset;
49-
50-
String limitClause = new StringBuilder().append("OFFSET ").append(offset).append(" ROWS FETCH NEXT 1 ROWS ONLY")
51-
.toString();
52-
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
53-
}
54-
5544
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,4 @@ private String buildLimitClause(int pageSize) {
4747
return new StringBuilder().append("LIMIT ").append(pageSize).toString();
4848
}
4949

50-
@Override
51-
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
52-
int page = itemIndex / pageSize;
53-
int offset = (page * pageSize) - 1;
54-
offset = offset < 0 ? 0 : offset;
55-
String limitClause = new StringBuilder().append("LIMIT 1 OFFSET ").append(offset).toString();
56-
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
57-
}
58-
5950
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2012 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -48,14 +48,4 @@ private String buildTopClause(int pageSize) {
4848
return new StringBuilder().append("TOP ").append(pageSize).toString();
4949
}
5050

51-
@Override
52-
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
53-
int page = itemIndex / pageSize;
54-
int offset = (page * pageSize) - 1;
55-
offset = offset < 0 ? 0 : offset;
56-
57-
String topClause = new StringBuilder().append("LIMIT ").append(offset).append(" 1").toString();
58-
return SqlPagingQueryUtils.generateTopJumpToQuery(this, topClause);
59-
}
60-
6151
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -48,14 +48,4 @@ private String buildLimitClause(int pageSize) {
4848
return new StringBuilder().append("LIMIT ").append(pageSize).toString();
4949
}
5050

51-
@Override
52-
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
53-
int page = itemIndex / pageSize;
54-
int offset = (page * pageSize) - 1;
55-
offset = offset < 0 ? 0 : offset;
56-
57-
String limitClause = new StringBuilder().append("LIMIT ").append(offset).append(", 1").toString();
58-
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
59-
}
60-
6151
}

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2012 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -16,10 +16,6 @@
1616

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

19-
import java.util.Map;
20-
21-
import org.springframework.batch.item.database.Order;
22-
2319
/**
2420
* Oracle implementation of a
2521
* {@link org.springframework.batch.item.database.PagingQueryProvider} using database
@@ -41,29 +37,6 @@ public String generateRemainingPagesQuery(int pageSize) {
4137
return SqlPagingQueryUtils.generateRowNumSqlQuery(this, true, buildRowNumClause(pageSize));
4238
}
4339

44-
@Override
45-
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
46-
int page = itemIndex / pageSize;
47-
int offset = (page * pageSize);
48-
offset = offset == 0 ? 1 : offset;
49-
String sortKeySelect = this.getSortKeySelect();
50-
return SqlPagingQueryUtils.generateRowNumSqlQueryWithNesting(this, sortKeySelect, sortKeySelect, false,
51-
"TMP_ROW_NUM = " + offset);
52-
}
53-
54-
private String getSortKeySelect() {
55-
StringBuilder sql = new StringBuilder();
56-
String prefix = "";
57-
58-
for (Map.Entry<String, Order> sortKey : this.getSortKeys().entrySet()) {
59-
sql.append(prefix);
60-
prefix = ", ";
61-
sql.append(sortKey.getKey());
62-
}
63-
64-
return sql.toString();
65-
}
66-
6740
private String buildRowNumClause(int pageSize) {
6841
return new StringBuilder().append("ROWNUM <= ").append(pageSize).toString();
6942
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -53,13 +53,4 @@ private String buildLimitClause(int pageSize) {
5353
return new StringBuilder().append("LIMIT ").append(pageSize).toString();
5454
}
5555

56-
@Override
57-
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
58-
int page = itemIndex / pageSize;
59-
int offset = (page * pageSize) - 1;
60-
offset = offset < 0 ? 0 : offset;
61-
String limitClause = new StringBuilder().append("LIMIT 1 OFFSET ").append(offset).toString();
62-
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
63-
}
64-
6556
}

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

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -201,66 +201,6 @@ public static String generateRowNumSqlQuery(AbstractSqlPagingQueryProvider provi
201201

202202
}
203203

204-
public static String generateRowNumSqlQueryWithNesting(AbstractSqlPagingQueryProvider provider, String selectClause,
205-
boolean remainingPageQuery, String rowNumClause) {
206-
return generateRowNumSqlQueryWithNesting(provider, selectClause, selectClause, remainingPageQuery,
207-
rowNumClause);
208-
}
209-
210-
public static String generateRowNumSqlQueryWithNesting(AbstractSqlPagingQueryProvider provider,
211-
String innerSelectClause, String outerSelectClause, boolean remainingPageQuery, String rowNumClause) {
212-
213-
StringBuilder sql = new StringBuilder();
214-
sql.append("SELECT ").append(outerSelectClause).append(" FROM (SELECT ").append(outerSelectClause).append(", ")
215-
.append(StringUtils.hasText(provider.getGroupClause()) ? "MIN(ROWNUM) as TMP_ROW_NUM"
216-
: "ROWNUM as TMP_ROW_NUM");
217-
sql.append(" FROM (SELECT ").append(innerSelectClause).append(" FROM ").append(provider.getFromClause());
218-
buildWhereClause(provider, remainingPageQuery, sql);
219-
buildGroupByClause(provider, sql);
220-
sql.append(" ORDER BY ").append(buildSortClause(provider));
221-
sql.append(")) WHERE ").append(rowNumClause);
222-
223-
return sql.toString();
224-
225-
}
226-
227-
/**
228-
* Generate SQL query string using a LIMIT clause
229-
* @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation
230-
* specifics
231-
* @param limitClause the implementation specific top clause to be used
232-
* @return the generated query
233-
*/
234-
public static String generateLimitJumpToQuery(AbstractSqlPagingQueryProvider provider, String limitClause) {
235-
StringBuilder sql = new StringBuilder();
236-
sql.append("SELECT ").append(buildSortKeySelect(provider));
237-
sql.append(" FROM ").append(provider.getFromClause());
238-
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
239-
buildGroupByClause(provider, sql);
240-
sql.append(" ORDER BY ").append(buildSortClause(provider));
241-
sql.append(" " + limitClause);
242-
243-
return sql.toString();
244-
}
245-
246-
/**
247-
* Generate SQL query string using a TOP clause
248-
* @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation
249-
* specifics
250-
* @param topClause the implementation specific top clause to be used
251-
* @return the generated query
252-
*/
253-
public static String generateTopJumpToQuery(AbstractSqlPagingQueryProvider provider, String topClause) {
254-
StringBuilder sql = new StringBuilder();
255-
sql.append("SELECT ").append(topClause).append(" ").append(buildSortKeySelect(provider));
256-
sql.append(" FROM ").append(provider.getFromClause());
257-
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
258-
buildGroupByClause(provider, sql);
259-
sql.append(" ORDER BY ").append(buildSortClause(provider));
260-
261-
return sql.toString();
262-
}
263-
264204
/**
265205
* Generates ORDER BY attributes based on the sort keys.
266206
* @param provider the {@link AbstractSqlPagingQueryProvider} to be used for used for
@@ -352,22 +292,6 @@ public static void buildSortConditions(AbstractSqlPagingQueryProvider provider,
352292
sql.append(")");
353293
}
354294

355-
private static String buildSortKeySelect(AbstractSqlPagingQueryProvider provider) {
356-
StringBuilder select = new StringBuilder();
357-
358-
String prefix = "";
359-
360-
for (Map.Entry<String, Order> sortKey : provider.getSortKeys().entrySet()) {
361-
select.append(prefix);
362-
363-
prefix = ", ";
364-
365-
select.append(sortKey.getKey());
366-
}
367-
368-
return select.toString();
369-
}
370-
371295
private static void buildWhereClause(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery,
372296
StringBuilder sql) {
373297
if (remainingPageQuery) {

0 commit comments

Comments
 (0)