Skip to content

BATCH-2849 Account For Different Whitespaces In Keyword Removal #738

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 3 commits 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-2018 the original author or authors.
* Copyright 2006-2020 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,6 +50,7 @@
* @author Dave Syer
* @author Michael Minella
* @author Mahmoud Ben Hassine
* @author Benjamin Hetz
* @since 2.0
*/
public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvider {
Expand Down Expand Up @@ -242,9 +243,9 @@ public void init(DataSource dataSource) throws Exception {

private String removeKeyWord(String keyWord, String clause) {
String temp = clause.trim();
String keyWordString = keyWord + " ";
if (temp.toLowerCase().startsWith(keyWordString) && temp.length() > keyWordString.length()) {
return temp.substring(keyWordString.length());
int len = keyWord.length();
if (temp.toLowerCase().startsWith(keyWord) && Character.isWhitespace(temp.charAt(len)) && temp.length() > len + 1) {
return temp.substring(len + 1);
}
else {
return temp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,51 @@ public void testGenerateJumpToItemQueryForFirstPageWithMultipleSortKeys() {
assertEquals(getJumpToItemQueryForFirstPageWithMultipleSortKeys(), s);
}

@Test
public void testRemoveKeyWordsFollowedBySpaceChar() {
String selectClause = "SELECT id, 'yes', false";
String fromClause = "FROM test.verification_table";
String whereClause = "WHERE TRUE";
pagingQueryProvider.setSelectClause( selectClause );
pagingQueryProvider.setFromClause( fromClause );
pagingQueryProvider.setWhereClause( whereClause );


assertEquals("id, 'yes', false", pagingQueryProvider.getSelectClause());
assertEquals("test.verification_table", pagingQueryProvider.getFromClause());
assertEquals("TRUE", pagingQueryProvider.getWhereClause());
}

@Test
public void testRemoveKeyWordsFollowedByTabChar() {
String selectClause = "SELECT\tid, 'yes', false";
String fromClause = "FROM\ttest.verification_table";
String whereClause = "WHERE\tTRUE";
pagingQueryProvider.setSelectClause( selectClause );
pagingQueryProvider.setFromClause( fromClause );
pagingQueryProvider.setWhereClause( whereClause );


assertEquals("id, 'yes', false", pagingQueryProvider.getSelectClause());
assertEquals("test.verification_table", pagingQueryProvider.getFromClause());
assertEquals("TRUE", pagingQueryProvider.getWhereClause());
}

@Test
public void testRemoveKeyWordsFollowedByNewLineChar() {
String selectClause = "SELECT\nid, 'yes', false";
String fromClause = "FROM\ntest.verification_table";
String whereClause = "WHERE\nTRUE";
pagingQueryProvider.setSelectClause( selectClause );
pagingQueryProvider.setFromClause( fromClause );
pagingQueryProvider.setWhereClause( whereClause );


assertEquals("id, 'yes', false", pagingQueryProvider.getSelectClause());
assertEquals("test.verification_table", pagingQueryProvider.getFromClause());
assertEquals("TRUE", pagingQueryProvider.getWhereClause());
}

@Test
public abstract void testGenerateFirstPageQuery();

Expand Down