Refactored to keep column aliases in certain conditions
The solution for BATCH-2079 was too agressive in that it removed table references from columns in places that ended up in where clauses. Since SQL does not support the use of column aliases in where clauses, the table references are needed. This fix should address adding the aliases back where needed, while keeping them out in the windowing paging query use cases where they were problematic. BATCH-2360
This commit is contained in:
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.springframework.batch.item.database.support;
|
||||
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Utility class that generates the actual SQL statements used by query
|
||||
* providers.
|
||||
@@ -246,7 +246,7 @@ public class SqlPagingQueryUtils {
|
||||
* @return a String that can be appended to an ORDER BY clause.
|
||||
*/
|
||||
public static String buildSortClause(AbstractSqlPagingQueryProvider provider) {
|
||||
return buildSortClause(provider.getSortKeysWithoutAliases());
|
||||
return buildSortClause(provider.getSortKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,7 +285,7 @@ public class SqlPagingQueryUtils {
|
||||
*/
|
||||
public static void buildSortConditions(
|
||||
AbstractSqlPagingQueryProvider provider, StringBuilder sql) {
|
||||
List<Map.Entry<String, Order>> keys = new ArrayList<Map.Entry<String,Order>>(provider.getSortKeysWithoutAliases().entrySet());
|
||||
List<Map.Entry<String, Order>> keys = new ArrayList<Map.Entry<String,Order>>(provider.getSortKeys().entrySet());
|
||||
List<String> clauses = new ArrayList<String>();
|
||||
|
||||
for(int i = 0; i < keys.size(); i++) {
|
||||
@@ -336,7 +336,7 @@ public class SqlPagingQueryUtils {
|
||||
|
||||
String prefix = "";
|
||||
|
||||
for (Map.Entry<String, Order> sortKey : provider.getSortKeysWithoutAliases().entrySet()) {
|
||||
for (Map.Entry<String, Order> sortKey : provider.getSortKeys().entrySet()) {
|
||||
select.append(prefix);
|
||||
|
||||
prefix = ", ";
|
||||
|
||||
@@ -149,7 +149,7 @@ public class SqlWindowingPagingQueryProvider extends AbstractSqlPagingQueryProvi
|
||||
protected String getOverClause() {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
|
||||
sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
|
||||
sql.append(" ORDER BY ").append(buildSortClause(this));
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
@@ -161,4 +161,16 @@ public class SqlWindowingPagingQueryProvider extends AbstractSqlPagingQueryProvi
|
||||
protected String getOverSubstituteClauseEnd() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates ORDER BY attributes based on the sort keys.
|
||||
*
|
||||
* @param provider
|
||||
* @return a String that can be appended to an ORDER BY clause.
|
||||
*/
|
||||
private String buildSortClause(AbstractSqlPagingQueryProvider provider) {
|
||||
return SqlPagingQueryUtils.buildSortClause(provider.getSortKeysWithoutAliases());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user