Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BATCH-1691: Updated to correct order by processing

  • Loading branch information...
commit 6380491187fe28059379c9a7edd84ff7837f7d62 1 parent ea4fdfd
Michael Minella mminella authored
Showing with 83 additions and 75 deletions.
  1. +1 −1  ...astructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingQueryIntegrationTests.java
  2. +1 −0  ...tructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java
  3. +6 −1 ...structure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java
  4. +1 −1  ...-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java
  5. +0 −1  ...infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java
  6. +4 −4 ...batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java
  7. +4 −1 ...tructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java
  8. +7 −7 ...frastructure/src/test/java/org/springframework/batch/item/database/support/Db2PagingQueryProviderTests.java
  9. +13 −13 ...astructure/src/test/java/org/springframework/batch/item/database/support/DerbyPagingQueryProviderTests.java
  10. +1 −1  ...rastructure/src/test/java/org/springframework/batch/item/database/support/HsqlPagingQueryProviderTests.java
  11. +1 −1  ...astructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java
  12. +9 −9 ...structure/src/test/java/org/springframework/batch/item/database/support/OraclePagingQueryProviderTests.java
  13. +1 −1  ...ructure/src/test/java/org/springframework/batch/item/database/support/PostgresPagingQueryProviderTests.java
  14. +8 −8 ...-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryUtilsTests.java
  15. +7 −7 ...ucture/src/test/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProviderTests.java
  16. +12 −12 ...ure/src/test/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProviderTests.java
  17. +7 −7 ...structure/src/test/java/org/springframework/batch/item/database/support/SybasePagingQueryProviderTests.java
2  ...ructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingQueryIntegrationTests.java
View
@@ -82,7 +82,7 @@ public void testInit() {
@After
public void destroy() {
- jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
+ jdbcTemplate.update("DELETE from T_FOOS");
}
@Test
1  ...cture-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java
View
@@ -76,6 +76,7 @@ public void init() {
for (int i = itemCount; i > maxId; i--) {
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
}
+
assertEquals(itemCount, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
}
7 ...ucture/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java
View
@@ -71,7 +71,12 @@
* @param SQL GROUP BY clause part of the SQL query string
*/
public void setGroupClause(String groupClause) {
- this.groupClause = groupClause;
+ if (StringUtils.hasText(groupClause)) {
+ this.groupClause = removeKeyWord("group by", groupClause);
+ }
+ else {
+ this.groupClause = null;
+ }
}
/**
2  ...frastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java
View
@@ -62,7 +62,7 @@ protected String getOverSubstituteClauseStart() {
}
protected String getOverSubstituteClauseEnd() {
- return " " + super.getOverClause() + ") AS " + getOrderedQueryAlias();
+ return " ) AS " + getOrderedQueryAlias();
}
}
1  ...rastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java
View
@@ -32,7 +32,6 @@
@Override
public String generateFirstPageQuery(int pageSize) {
return SqlPagingQueryUtils.generateRowNumSqlQuery(this, false, buildRowNumClause(pageSize));
-
}
@Override
8 ...ch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java
View
@@ -76,10 +76,10 @@ public static String generateLimitGroupedSqlQuery(AbstractSqlPagingQueryProvider
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(") AS MAIN_QRY ");
sql.append("WHERE ");
buildSortConditions(provider, sql);
+ sql.append(" ORDER BY ").append(buildSortClause(provider));
sql.append(" " + limitClause);
return sql.toString();
@@ -125,10 +125,10 @@ public static String generateGroupedTopSqlQuery(AbstractSqlPagingQueryProvider p
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(") AS MAIN_QRY ");
sql.append("WHERE ");
buildSortConditions(provider, sql);
+ sql.append(" ORDER BY ").append(buildSortClause(provider));
return sql.toString();
}
@@ -163,7 +163,7 @@ public static String generateRowNumSqlQuery(AbstractSqlPagingQueryProvider provi
public static String generateRowNumSqlQuery(AbstractSqlPagingQueryProvider provider, String selectClause,
boolean remainingPageQuery, String rowNumClause) {
StringBuilder sql = new StringBuilder();
- sql.append("SELECT * FROM (SELECT ").append(selectClause).append(", ROWNUM as TMP_ROW_NUM");
+ sql.append("SELECT * FROM (SELECT ").append(selectClause);
sql.append(" FROM ").append(provider.getFromClause());
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
buildGroupByClause(provider, sql);
@@ -188,7 +188,7 @@ public static String generateRowNumSqlQueryWithNesting(AbstractSqlPagingQueryPro
StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(outerSelectClause).append(" FROM (SELECT ").append(outerSelectClause)
- .append(", ROWNUM as TMP_ROW_NUM");
+ .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);
5 ...cture/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java
View
@@ -45,7 +45,8 @@ public String generateFirstPageQuery(int pageSize) {
sql.append(getOverSubstituteClauseEnd());
sql.append(") ").append(getSubQueryAlias()).append("WHERE ").append(extractTableAlias()).append(
"ROW_NUMBER <= ").append(pageSize);
-
+ sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
+
return sql.toString();
}
@@ -85,6 +86,7 @@ public String generateRemainingPagesQuery(int pageSize) {
"ROW_NUMBER <= ").append(pageSize);
sql.append(" AND ");
SqlPagingQueryUtils.buildSortConditions(this, sql);
+ sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
return sql.toString();
}
@@ -112,6 +114,7 @@ public String generateJumpToItemQuery(int itemIndex, int pageSize) {
sql.append(getOverSubstituteClauseEnd());
sql.append(") ").append(getSubQueryAlias()).append("WHERE ").append(extractTableAlias()).append(
"ROW_NUMBER = ").append(lastRowNum);
+ sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
return sql.toString();
}
14 ...structure/src/test/java/org/springframework/batch/item/database/support/Db2PagingQueryProviderTests.java
View
@@ -48,7 +48,7 @@ public void testGenerateRemainingPagesQuery() {
@Test
@Override
public void testGenerateJumpToItemQuery() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -56,7 +56,7 @@ public void testGenerateJumpToItemQuery() {
@Test
@Override
public void testGenerateJumpToItemQueryForFirstPage() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@@ -74,7 +74,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Override
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS MAIN_QRY WHERE ((id > ?)) FETCH FIRST 100 ROWS ONLY";
+ String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC FETCH FIRST 100 ROWS ONLY";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -83,7 +83,7 @@ public void testGenerateRemainingPagesQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -92,7 +92,7 @@ public void testGenerateJumpToItemQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@@ -109,11 +109,11 @@ public String getRemainingSqlWithMultipleSortKeys() {
@Override
public String getJumpToItemQueryWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
}
@Override
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
}
}
26 ...ructure/src/test/java/org/springframework/batch/item/database/support/DerbyPagingQueryProviderTests.java
View
@@ -41,7 +41,7 @@
public DerbyPagingQueryProviderTests() {
pagingQueryProvider = new DerbyPagingQueryProvider();
}
-
+
@Test
public void testInit() throws Exception {
DataSource ds = createMock(DataSource.class);
@@ -85,7 +85,7 @@ public void testInitWithUnsupportedVErsion() throws Exception {
@Test
@Override
public void testGenerateFirstPageQuery() {
- String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100";
+ String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
Assert.assertEquals(sql, s);
}
@@ -93,7 +93,7 @@ public void testGenerateFirstPageQuery() {
@Test
@Override
public void testGenerateRemainingPagesQuery() {
- String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?))";
+ String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
Assert.assertEquals(sql, s);
}
@@ -101,7 +101,7 @@ public void testGenerateRemainingPagesQuery() {
@Test
@Override
public void testGenerateJumpToItemQuery() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
Assert.assertEquals(sql, s);
}
@@ -109,7 +109,7 @@ public void testGenerateJumpToItemQuery() {
@Test
@Override
public void testGenerateJumpToItemQueryForFirstPage() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
Assert.assertEquals(sql, s);
}
@@ -139,7 +139,7 @@ public void testQueryContainsSortKeyDesc() {
@Test
public void testGenerateFirstPageQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100";
+ String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
assertEquals(sql, s);
}
@@ -148,7 +148,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Test
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?))";
+ String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -157,7 +157,7 @@ public void testGenerateRemainingPagesQueryWithGroupBy() {
@Test
public void testGenerateJumpToItemQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -166,28 +166,28 @@ public void testGenerateJumpToItemQueryWithGroupBy() {
@Test
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@Override
public String getFirstPageSqlWithMultipleSortKeys() {
- return "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100";
+ return "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY name ASC, id DESC";
}
@Override
public String getRemainingSqlWithMultipleSortKeys() {
- return "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((name > ?) OR (name = ? AND id < ?))";
+ return "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
}
@Override
public String getJumpToItemQueryWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
}
@Override
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
}
}
2  ...tructure/src/test/java/org/springframework/batch/item/database/support/HsqlPagingQueryProviderTests.java
View
@@ -71,7 +71,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Test
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS MAIN_QRY WHERE ((id > ?))";
+ String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
2  ...ructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java
View
@@ -71,7 +71,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Test
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS MAIN_QRY WHERE ((id > ?)) LIMIT 100";
+ String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC LIMIT 100";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
18 ...ucture/src/test/java/org/springframework/batch/item/database/support/OraclePagingQueryProviderTests.java
View
@@ -32,18 +32,18 @@ public OraclePagingQueryProviderTests() {
@Test
@Override
public void testGenerateFirstPageQuery() {
- String sql = "SELECT * FROM (SELECT id, name, age, ROWNUM as TMP_ROW_NUM FROM foo WHERE bar = 1 ORDER BY id ASC) WHERE ROWNUM <= 100";
+ String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) WHERE ROWNUM <= 100";
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
assertEquals(sql, s);
pagingQueryProvider.setWhereClause("");
- String sql2 = "SELECT * FROM (SELECT id, name, age, ROWNUM as TMP_ROW_NUM FROM foo ORDER BY id ASC) WHERE ROWNUM <= 100";
+ String sql2 = "SELECT * FROM (SELECT id, name, age FROM foo ORDER BY id ASC) WHERE ROWNUM <= 100";
String s2 = pagingQueryProvider.generateFirstPageQuery(pageSize);
assertEquals(sql2, s2);
}
@Test @Override
public void testGenerateRemainingPagesQuery() {
- String sql = "SELECT * FROM (SELECT id, name, age, ROWNUM as TMP_ROW_NUM FROM foo WHERE bar = 1 ORDER BY id ASC) WHERE ROWNUM <= 100 AND ((id > ?))";
+ String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) WHERE ROWNUM <= 100 AND ((id > ?))";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -66,7 +66,7 @@ public void testGenerateJumpToItemQueryForFirstPage() {
@Test
public void testGenerateFirstPageQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM (SELECT id, name, age, ROWNUM as TMP_ROW_NUM FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) WHERE ROWNUM <= 100";
+ String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) WHERE ROWNUM <= 100";
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
assertEquals(sql, s);
}
@@ -75,7 +75,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Test
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM (SELECT id, name, age, ROWNUM as TMP_ROW_NUM FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) WHERE ROWNUM <= 100 AND ((id > ?))";
+ String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) WHERE ROWNUM <= 100 AND ((id > ?))";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -84,7 +84,7 @@ public void testGenerateRemainingPagesQueryWithGroupBy() {
@Test
public void testGenerateJumpToItemQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM (SELECT id, ROWNUM as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC)) WHERE TMP_ROW_NUM = 100";
+ String sql = "SELECT id FROM (SELECT id, MIN(ROWNUM) as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC)) WHERE TMP_ROW_NUM = 100";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -93,19 +93,19 @@ public void testGenerateJumpToItemQueryWithGroupBy() {
@Test
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM (SELECT id, ROWNUM as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC)) WHERE TMP_ROW_NUM = 1";
+ String sql = "SELECT id FROM (SELECT id, MIN(ROWNUM) as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC)) WHERE TMP_ROW_NUM = 1";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@Override
public String getFirstPageSqlWithMultipleSortKeys() {
- return "SELECT * FROM (SELECT id, name, age, ROWNUM as TMP_ROW_NUM FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) WHERE ROWNUM <= 100";
+ return "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) WHERE ROWNUM <= 100";
}
@Override
public String getRemainingSqlWithMultipleSortKeys() {
- return "SELECT * FROM (SELECT id, name, age, ROWNUM as TMP_ROW_NUM FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) WHERE ROWNUM <= 100 AND ((name > ?) OR (name = ? AND id < ?))";
+ return "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) WHERE ROWNUM <= 100 AND ((name > ?) OR (name = ? AND id < ?))";
}
@Override
2  ...ture/src/test/java/org/springframework/batch/item/database/support/PostgresPagingQueryProviderTests.java
View
@@ -71,7 +71,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Test
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("id, dep");
- String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY id, dep ORDER BY id ASC) AS MAIN_QRY WHERE ((id > ?)) LIMIT 100";
+ String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY id, dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC LIMIT 100";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
16 ...frastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryUtilsTests.java
View
@@ -74,17 +74,17 @@ public void testGenerateTopSqlQuery() {
public void testGenerateRowNumSqlQuery() {
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR ORDER BY ID ASC) WHERE ROWNUMBER <= 100",
+ "SELECT * FROM (SELECT FOO FROM BAR ORDER BY ID ASC) WHERE ROWNUMBER <= 100",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, false, "ROWNUMBER <= 100"));
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR ORDER BY ID ASC) WHERE ROWNUMBER <= 100 AND ((ID > ?))",
+ "SELECT * FROM (SELECT FOO FROM BAR ORDER BY ID ASC) WHERE ROWNUMBER <= 100 AND ((ID > ?))",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, true, "ROWNUMBER <= 100"));
qp.setWhereClause("BAZ IS NOT NULL");
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID ASC) WHERE ROWNUMBER <= 100",
+ "SELECT * FROM (SELECT FOO FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID ASC) WHERE ROWNUMBER <= 100",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, false, "ROWNUMBER <= 100"));
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID ASC) WHERE ROWNUMBER <= 100 AND ((ID > ?))",
+ "SELECT * FROM (SELECT FOO FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID ASC) WHERE ROWNUMBER <= 100 AND ((ID > ?))",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, true, "ROWNUMBER <= 100"));
}
@@ -116,17 +116,17 @@ public void testGenerateRowNumSqlQueryDescending() {
sortKeys.put("ID", Order.DESCENDING);
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR ORDER BY ID DESC) WHERE ROWNUMBER <= 100",
+ "SELECT * FROM (SELECT FOO FROM BAR ORDER BY ID DESC) WHERE ROWNUMBER <= 100",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, false, "ROWNUMBER <= 100"));
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR ORDER BY ID DESC) WHERE ROWNUMBER <= 100 AND ((ID < ?))",
+ "SELECT * FROM (SELECT FOO FROM BAR ORDER BY ID DESC) WHERE ROWNUMBER <= 100 AND ((ID < ?))",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, true, "ROWNUMBER <= 100"));
qp.setWhereClause("BAZ IS NOT NULL");
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID DESC) WHERE ROWNUMBER <= 100",
+ "SELECT * FROM (SELECT FOO FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID DESC) WHERE ROWNUMBER <= 100",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, false, "ROWNUMBER <= 100"));
assertEquals(
- "SELECT * FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID DESC) WHERE ROWNUMBER <= 100 AND ((ID < ?))",
+ "SELECT * FROM (SELECT FOO FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID DESC) WHERE ROWNUMBER <= 100 AND ((ID < ?))",
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, true, "ROWNUMBER <= 100"));
}
14 ...ure/src/test/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProviderTests.java
View
@@ -48,7 +48,7 @@ public void testGenerateRemainingPagesQuery() {
@Test
@Override
public void testGenerateJumpToItemQuery() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -56,7 +56,7 @@ public void testGenerateJumpToItemQuery() {
@Test
@Override
public void testGenerateJumpToItemQueryForFirstPage() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@@ -74,7 +74,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Override
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS MAIN_QRY WHERE ((id > ?))";
+ String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -83,7 +83,7 @@ public void testGenerateRemainingPagesQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -92,7 +92,7 @@ public void testGenerateJumpToItemQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@@ -109,11 +109,11 @@ public String getRemainingSqlWithMultipleSortKeys() {
@Override
public String getJumpToItemQueryWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
}
@Override
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
}
}
24 .../src/test/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProviderTests.java
View
@@ -33,7 +33,7 @@ public SqlWindowingPagingQueryProviderTests() {
@Test
@Override
public void testGenerateFirstPageQuery() {
- String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100";
+ String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
assertEquals("", sql, s);
}
@@ -41,7 +41,7 @@ public void testGenerateFirstPageQuery() {
@Test
@Override
public void testGenerateRemainingPagesQuery() {
- String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?))";
+ String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals("", sql, s);
}
@@ -49,7 +49,7 @@ public void testGenerateRemainingPagesQuery() {
@Test
@Override
public void testGenerateJumpToItemQuery() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals("", sql, s);
}
@@ -57,7 +57,7 @@ public void testGenerateJumpToItemQuery() {
@Test
@Override
public void testGenerateJumpToItemQueryForFirstPage() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
Assert.assertEquals("", sql, s);
}
@@ -66,7 +66,7 @@ public void testGenerateJumpToItemQueryForFirstPage() {
@Override
public void testGenerateFirstPageQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100";
+ String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
assertEquals(sql, s);
}
@@ -75,7 +75,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Override
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?))";
+ String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -84,7 +84,7 @@ public void testGenerateRemainingPagesQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -93,28 +93,28 @@ public void testGenerateJumpToItemQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@Override
public String getFirstPageSqlWithMultipleSortKeys() {
- return "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100";
+ return "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY name ASC, id DESC";
}
@Override
public String getRemainingSqlWithMultipleSortKeys() {
- return "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((name > ?) OR (name = ? AND id < ?))";
+ return "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
}
@Override
public String getJumpToItemQueryWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
}
@Override
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
}
}
14 ...ucture/src/test/java/org/springframework/batch/item/database/support/SybasePagingQueryProviderTests.java
View
@@ -48,7 +48,7 @@ public void testGenerateRemainingPagesQuery() {
@Test
@Override
public void testGenerateJumpToItemQuery() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals("", sql, s);
}
@@ -56,7 +56,7 @@ public void testGenerateJumpToItemQuery() {
@Test
@Override
public void testGenerateJumpToItemQueryForFirstPage() {
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals("", sql, s);
}
@@ -74,7 +74,7 @@ public void testGenerateFirstPageQueryWithGroupBy() {
@Override
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) AS MAIN_QRY WHERE ((id > ?))";
+ String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -83,7 +83,7 @@ public void testGenerateRemainingPagesQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) WHERE ROW_NUMBER = 100";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) WHERE ROW_NUMBER = 100 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
assertEquals(sql, s);
}
@@ -92,7 +92,7 @@ public void testGenerateJumpToItemQueryWithGroupBy() {
@Override
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
- String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) WHERE ROW_NUMBER = 1";
+ String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) WHERE ROW_NUMBER = 1 ORDER BY id ASC";
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
assertEquals(sql, s);
}
@@ -109,11 +109,11 @@ public String getRemainingSqlWithMultipleSortKeys() {
@Override
public String getJumpToItemQueryWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 100";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
}
@Override
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
- return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 1";
+ return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.