Skip to content

Remove un-used code for jump-to-item queries #4207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -156,14 +156,10 @@ protected void jumpToItem(int itemIndex) throws Exception {
current = itemIndex % pageSize;
}

doJumpToPage(itemIndex);

if (logger.isDebugEnabled()) {
logger.debug("Jumping to page " + getPage() + " and index " + current);
}

}

abstract protected void doJumpToPage(int itemIndex);

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ protected void doReadPage() {

}

@Override
protected void doJumpToPage(int itemIndex) {
}

@Override
protected void doClose() throws Exception {
helper.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -254,33 +254,6 @@ public void open(ExecutionContext executionContext) {
super.open(executionContext);
}

@Override
protected void doJumpToPage(int itemIndex) {
/*
* Normally this would be false (the startAfterValue is enough information to
* restart from.
*/
// TODO: this is dead code, startAfterValues is never null - see
// #open(ExecutionContext)
if (startAfterValues == null && getPage() > 0) {

String jumpToItemSql = queryProvider.generateJumpToItemQuery(itemIndex, getPageSize());

if (logger.isDebugEnabled()) {
logger.debug("SQL used for jumping: [" + jumpToItemSql + "]");
}

if (this.queryProvider.isUsingNamedParameters()) {
startAfterValues = namedParameterJdbcTemplate.queryForMap(jumpToItemSql,
getParameterMap(parameterValues, null));
}
else {
startAfterValues = getJdbcTemplate().queryForMap(jumpToItemSql,
getParameterList(parameterValues, null).toArray());
}
}
}

private Map<String, Object> getParameterMap(Map<String, Object> values, Map<String, Object> sortKeyValues) {
Map<String, Object> parameterMap = new LinkedHashMap<>();
if (values != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -221,10 +221,6 @@ protected void doReadPage() {
} // end if
}

@Override
protected void doJumpToPage(int itemIndex) {
}

@Override
protected void doClose() throws Exception {
entityManager.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -50,18 +50,6 @@ public interface PagingQueryProvider {
*/
String generateRemainingPagesQuery(int pageSize);

/**
*
* Generate the query that will provide the jump to item query. The itemIndex provided
* could be in the middle of the page and together with the page size it will be used
* to calculate the last index of the preceding page to be able to retrieve the sort
* key for this row.
* @param itemIndex the index for the next item to be read
* @param pageSize number of rows to read for each page
* @return the generated query
*/
String generateJumpToItemQuery(int itemIndex, int pageSize);

/**
* The number of parameters that are declared in the query
* @return number of parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -221,16 +221,6 @@ public void init(DataSource dataSource) throws Exception {
@Override
public abstract String generateRemainingPagesQuery(int pageSize);

/**
* Method generating the query string to be used for jumping to a specific item
* position. This method must be implemented in sub classes.
* @param itemIndex the index of the item to jump to
* @param pageSize number of rows to read per page
* @return query string
*/
@Override
public abstract String generateJumpToItemQuery(int itemIndex, int pageSize);

private String removeKeyWord(String keyWord, String clause) {
String temp = clause.trim();
int length = keyWord.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,4 @@ private String buildLimitClause(int pageSize) {
return new StringBuilder().append("FETCH NEXT ").append(pageSize).append(" ROWS ONLY").toString();
}

@Override
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
int page = itemIndex / pageSize;
int offset = (page * pageSize) - 1;
offset = offset < 0 ? 0 : offset;

String limitClause = new StringBuilder().append("OFFSET ").append(offset).append(" ROWS FETCH NEXT 1 ROWS ONLY")
.toString();
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,4 @@ private String buildLimitClause(int pageSize) {
return new StringBuilder().append("LIMIT ").append(pageSize).toString();
}

@Override
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
int page = itemIndex / pageSize;
int offset = (page * pageSize) - 1;
offset = offset < 0 ? 0 : offset;
String limitClause = new StringBuilder().append("LIMIT 1 OFFSET ").append(offset).toString();
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -48,14 +48,4 @@ private String buildTopClause(int pageSize) {
return new StringBuilder().append("TOP ").append(pageSize).toString();
}

@Override
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
int page = itemIndex / pageSize;
int offset = (page * pageSize) - 1;
offset = offset < 0 ? 0 : offset;

String topClause = new StringBuilder().append("LIMIT ").append(offset).append(" 1").toString();
return SqlPagingQueryUtils.generateTopJumpToQuery(this, topClause);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -48,14 +48,4 @@ private String buildLimitClause(int pageSize) {
return new StringBuilder().append("LIMIT ").append(pageSize).toString();
}

@Override
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
int page = itemIndex / pageSize;
int offset = (page * pageSize) - 1;
offset = offset < 0 ? 0 : offset;

String limitClause = new StringBuilder().append("LIMIT ").append(offset).append(", 1").toString();
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2022 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.
Expand All @@ -16,10 +16,6 @@

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

import java.util.Map;

import org.springframework.batch.item.database.Order;

/**
* Oracle implementation of a
* {@link org.springframework.batch.item.database.PagingQueryProvider} using database
Expand All @@ -41,29 +37,6 @@ public String generateRemainingPagesQuery(int pageSize) {
return SqlPagingQueryUtils.generateRowNumSqlQuery(this, true, buildRowNumClause(pageSize));
}

@Override
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
int page = itemIndex / pageSize;
int offset = (page * pageSize);
offset = offset == 0 ? 1 : offset;
String sortKeySelect = this.getSortKeySelect();
return SqlPagingQueryUtils.generateRowNumSqlQueryWithNesting(this, sortKeySelect, sortKeySelect, false,
"TMP_ROW_NUM = " + offset);
}

private String getSortKeySelect() {
StringBuilder sql = new StringBuilder();
String prefix = "";

for (Map.Entry<String, Order> sortKey : this.getSortKeys().entrySet()) {
sql.append(prefix);
prefix = ", ";
sql.append(sortKey.getKey());
}

return sql.toString();
}

private String buildRowNumClause(int pageSize) {
return new StringBuilder().append("ROWNUM <= ").append(pageSize).toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -53,13 +53,4 @@ private String buildLimitClause(int pageSize) {
return new StringBuilder().append("LIMIT ").append(pageSize).toString();
}

@Override
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
int page = itemIndex / pageSize;
int offset = (page * pageSize) - 1;
offset = offset < 0 ? 0 : offset;
String limitClause = new StringBuilder().append("LIMIT 1 OFFSET ").append(offset).toString();
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -201,66 +201,6 @@ public static String generateRowNumSqlQuery(AbstractSqlPagingQueryProvider provi

}

public static String generateRowNumSqlQueryWithNesting(AbstractSqlPagingQueryProvider provider, String selectClause,
boolean remainingPageQuery, String rowNumClause) {
return generateRowNumSqlQueryWithNesting(provider, selectClause, selectClause, remainingPageQuery,
rowNumClause);
}

public static String generateRowNumSqlQueryWithNesting(AbstractSqlPagingQueryProvider provider,
String innerSelectClause, String outerSelectClause, boolean remainingPageQuery, String rowNumClause) {

StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(outerSelectClause).append(" FROM (SELECT ").append(outerSelectClause).append(", ")
.append(StringUtils.hasText(provider.getGroupClause()) ? "MIN(ROWNUM) as TMP_ROW_NUM"
: "ROWNUM as TMP_ROW_NUM");
sql.append(" FROM (SELECT ").append(innerSelectClause).append(" FROM ").append(provider.getFromClause());
buildWhereClause(provider, remainingPageQuery, sql);
buildGroupByClause(provider, sql);
sql.append(" ORDER BY ").append(buildSortClause(provider));
sql.append(")) WHERE ").append(rowNumClause);

return sql.toString();

}

/**
* Generate SQL query string using a LIMIT clause
* @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation
* specifics
* @param limitClause the implementation specific top clause to be used
* @return the generated query
*/
public static String generateLimitJumpToQuery(AbstractSqlPagingQueryProvider provider, String limitClause) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(buildSortKeySelect(provider));
sql.append(" FROM ").append(provider.getFromClause());
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
buildGroupByClause(provider, sql);
sql.append(" ORDER BY ").append(buildSortClause(provider));
sql.append(" " + limitClause);

return sql.toString();
}

/**
* Generate SQL query string using a TOP clause
* @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation
* specifics
* @param topClause the implementation specific top clause to be used
* @return the generated query
*/
public static String generateTopJumpToQuery(AbstractSqlPagingQueryProvider provider, String topClause) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(topClause).append(" ").append(buildSortKeySelect(provider));
sql.append(" FROM ").append(provider.getFromClause());
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
buildGroupByClause(provider, sql);
sql.append(" ORDER BY ").append(buildSortClause(provider));

return sql.toString();
}

/**
* Generates ORDER BY attributes based on the sort keys.
* @param provider the {@link AbstractSqlPagingQueryProvider} to be used for used for
Expand Down Expand Up @@ -352,22 +292,6 @@ public static void buildSortConditions(AbstractSqlPagingQueryProvider provider,
sql.append(")");
}

private static String buildSortKeySelect(AbstractSqlPagingQueryProvider provider) {
StringBuilder select = new StringBuilder();

String prefix = "";

for (Map.Entry<String, Order> sortKey : provider.getSortKeys().entrySet()) {
select.append(prefix);

prefix = ", ";

select.append(sortKey.getKey());
}

return select.toString();
}

private static void buildWhereClause(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery,
StringBuilder sql) {
if (remainingPageQuery) {
Expand Down
Loading