BATCH-2328: PagingQueryProvider implementations should add parenthesis

around where clause
This commit is contained in:
jpraet
2015-01-16 22:08:48 +01:00
committed by Michael Minella
parent 652ca038f9
commit b90dfa904c
10 changed files with 32 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2015 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.
@@ -352,8 +352,9 @@ public class SqlPagingQueryUtils {
if (remainingPageQuery) {
sql.append(" WHERE ");
if (provider.getWhereClause() != null) {
sql.append("(");
sql.append(provider.getWhereClause());
sql.append(" AND ");
sql.append(") AND ");
}
buildSortConditions(provider, sql);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2015 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.
@@ -40,7 +40,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
@Test
@Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC FETCH FIRST 100 ROWS ONLY";
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC FETCH FIRST 100 ROWS ONLY";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -104,7 +104,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC FETCH FIRST 100 ROWS ONLY";
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC FETCH FIRST 100 ROWS ONLY";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2015 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.
@@ -40,7 +40,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
@Test @Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC";
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -72,7 +72,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
@Test
public void testGenerateRemainingPagesQueryWithGroupBy() {
pagingQueryProvider.setGroupClause("dep");
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) GROUP BY dep ORDER BY id ASC";
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) GROUP BY dep ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -102,7 +102,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
return "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2015 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.
@@ -39,7 +39,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
@Test @Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC";
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -101,7 +101,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
return "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2015 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.
@@ -39,7 +39,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
@Test @Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC LIMIT 100";
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC LIMIT 100";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -101,7 +101,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2015 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.
@@ -39,7 +39,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
@Test @Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC LIMIT 100";
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC LIMIT 100";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -101,7 +101,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2015 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.
@@ -53,7 +53,7 @@ public class SqlPagingQueryUtilsTests {
qp.setWhereClause("BAZ IS NOT NULL");
assertEquals("SELECT FOO FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID ASC LIMIT 100", SqlPagingQueryUtils
.generateLimitSqlQuery(qp, false, "LIMIT 100"));
assertEquals("SELECT FOO FROM BAR WHERE BAZ IS NOT NULL AND ((ID > ?)) ORDER BY ID ASC LIMIT 100",
assertEquals("SELECT FOO FROM BAR WHERE (BAZ IS NOT NULL) AND ((ID > ?)) ORDER BY ID ASC LIMIT 100",
SqlPagingQueryUtils.generateLimitSqlQuery(qp, true, "LIMIT 100"));
}
@@ -67,7 +67,7 @@ public class SqlPagingQueryUtilsTests {
qp.setWhereClause("BAZ IS NOT NULL");
assertEquals("SELECT TOP 100 FOO FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID ASC", SqlPagingQueryUtils
.generateTopSqlQuery(qp, false, "TOP 100"));
assertEquals("SELECT TOP 100 FOO FROM BAR WHERE BAZ IS NOT NULL AND ((ID > ?)) ORDER BY ID ASC",
assertEquals("SELECT TOP 100 FOO FROM BAR WHERE (BAZ IS NOT NULL) AND ((ID > ?)) ORDER BY ID ASC",
SqlPagingQueryUtils.generateTopSqlQuery(qp, true, "TOP 100"));
}
@@ -108,7 +108,7 @@ public class SqlPagingQueryUtilsTests {
qp.setWhereClause("BAZ IS NOT NULL");
assertEquals("SELECT TOP 100 FOO FROM BAR WHERE BAZ IS NOT NULL ORDER BY ID DESC", SqlPagingQueryUtils
.generateTopSqlQuery(qp, false, "TOP 100"));
assertEquals("SELECT TOP 100 FOO FROM BAR WHERE BAZ IS NOT NULL AND ((ID < ?)) ORDER BY ID DESC",
assertEquals("SELECT TOP 100 FOO FROM BAR WHERE (BAZ IS NOT NULL) AND ((ID < ?)) ORDER BY ID DESC",
SqlPagingQueryUtils.generateTopSqlQuery(qp, true, "TOP 100"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2015 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.
@@ -40,7 +40,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
@Test
@Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC";
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -104,7 +104,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
return "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 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.
@@ -40,7 +40,7 @@ public class SqlitePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
@Test @Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC LIMIT 100";
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC LIMIT 100";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals(sql, s);
}
@@ -102,7 +102,7 @@ public class SqlitePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2015 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.
@@ -40,7 +40,7 @@ public class SybasePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
@Test
@Override
public void testGenerateRemainingPagesQuery() {
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((id > ?)) ORDER BY id ASC";
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC";
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
assertEquals("", sql, s);
}
@@ -104,7 +104,7 @@ public class SybasePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
@Override
public String getRemainingSqlWithMultipleSortKeys() {
return "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
return "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
}
@Override