Skip to content

Commit 36b1d0a

Browse files
committed
Remove unused parameter in SqlPagingQueryUtils#generateLimitGroupedSqlQuery
1 parent 497438a commit 36b1d0a

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

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

Lines changed: 3 additions & 2 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-2021 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,6 +25,7 @@
2525
*
2626
* @author Thomas Risberg
2727
* @author Michael Minella
28+
* @author Mahmoud Ben Hassine
2829
* @since 2.0
2930
*/
3031
public class Db2PagingQueryProvider extends SqlWindowingPagingQueryProvider {
@@ -37,7 +38,7 @@ public String generateFirstPageQuery(int pageSize) {
3738
@Override
3839
public String generateRemainingPagesQuery(int pageSize) {
3940
if(StringUtils.hasText(getGroupClause())) {
40-
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, true, buildLimitClause(pageSize));
41+
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, buildLimitClause(pageSize));
4142
}
4243
else {
4344
return SqlPagingQueryUtils.generateLimitSqlQuery(this, true, buildLimitClause(pageSize));

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

Lines changed: 3 additions & 2 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-2021 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.
@@ -24,6 +24,7 @@
2424
*
2525
* @author Thomas Risberg
2626
* @author Michael Minella
27+
* @author Mahmoud Ben Hassine
2728
* @since 2.0
2829
*/
2930
public class MySqlPagingQueryProvider extends AbstractSqlPagingQueryProvider {
@@ -36,7 +37,7 @@ public String generateFirstPageQuery(int pageSize) {
3637
@Override
3738
public String generateRemainingPagesQuery(int pageSize) {
3839
if(StringUtils.hasText(getGroupClause())) {
39-
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, true, buildLimitClause(pageSize));
40+
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, buildLimitClause(pageSize));
4041
}
4142
else {
4243
return SqlPagingQueryUtils.generateLimitSqlQuery(this, true, buildLimitClause(pageSize));

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

Lines changed: 3 additions & 2 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-2021 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.
@@ -26,6 +26,7 @@
2626
*
2727
* @author Thomas Risberg
2828
* @author Michael Minella
29+
* @author Mahmoud Ben Hassine
2930
* @since 2.0
3031
*/
3132
public class PostgresPagingQueryProvider extends AbstractSqlPagingQueryProvider {
@@ -38,7 +39,7 @@ public String generateFirstPageQuery(int pageSize) {
3839
@Override
3940
public String generateRemainingPagesQuery(int pageSize) {
4041
if(StringUtils.hasText(getGroupClause())) {
41-
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, true, buildLimitClause(pageSize));
42+
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, buildLimitClause(pageSize));
4243
}
4344
else {
4445
return SqlPagingQueryUtils.generateLimitSqlQuery(this, true, buildLimitClause(pageSize));

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @author Thomas Risberg
3232
* @author Dave Syer
3333
* @author Michael Minella
34+
* @author Mahmoud Ben Hassine
3435
* @since 2.0
3536
*/
3637
public class SqlPagingQueryUtils {
@@ -67,7 +68,9 @@ public static String generateLimitSqlQuery(AbstractSqlPagingQueryProvider provid
6768
* opposed to the first page (false)
6869
* @param limitClause the implementation specific limit clause to be used
6970
* @return the generated query
71+
* @deprecated in favor of {@link #generateLimitGroupedSqlQuery(AbstractSqlPagingQueryProvider, java.lang.String)}
7072
*/
73+
@Deprecated
7174
public static String generateLimitGroupedSqlQuery(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery,
7275
String limitClause) {
7376
StringBuilder sql = new StringBuilder();
@@ -86,6 +89,31 @@ public static String generateLimitGroupedSqlQuery(AbstractSqlPagingQueryProvider
8689
return sql.toString();
8790
}
8891

92+
/**
93+
* Generate SQL query string using a LIMIT clause
94+
*
95+
* @param provider {@link AbstractSqlPagingQueryProvider} providing the
96+
* implementation specifics
97+
* @param limitClause the implementation specific limit clause to be used
98+
* @return the generated query
99+
*/
100+
public static String generateLimitGroupedSqlQuery(AbstractSqlPagingQueryProvider provider, String limitClause) {
101+
StringBuilder sql = new StringBuilder();
102+
sql.append("SELECT * ");
103+
sql.append(" FROM (");
104+
sql.append("SELECT ").append(provider.getSelectClause());
105+
sql.append(" FROM ").append(provider.getFromClause());
106+
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
107+
buildGroupByClause(provider, sql);
108+
sql.append(") AS MAIN_QRY ");
109+
sql.append("WHERE ");
110+
buildSortConditions(provider, sql);
111+
sql.append(" ORDER BY ").append(buildSortClause(provider));
112+
sql.append(" " + limitClause);
113+
114+
return sql.toString();
115+
}
116+
89117
/**
90118
* Generate SQL query string using a TOP clause
91119
*

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2021 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.
@@ -23,6 +23,7 @@
2323
* features.
2424
*
2525
* @author Luke Taylor
26+
* @author Mahmoud Ben Hassine
2627
* @since 3.0.0
2728
*/
2829
public class SqlitePagingQueryProvider extends AbstractSqlPagingQueryProvider {
@@ -40,7 +41,7 @@ public String generateFirstPageQuery(int pageSize) {
4041
@Override
4142
public String generateRemainingPagesQuery(int pageSize) {
4243
if(StringUtils.hasText(getGroupClause())) {
43-
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, true, buildLimitClause(pageSize));
44+
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, buildLimitClause(pageSize));
4445
}
4546
else {
4647
return SqlPagingQueryUtils.generateLimitSqlQuery(this, true, buildLimitClause(pageSize));

0 commit comments

Comments
 (0)