Skip to content

Commit

Permalink
Changing the for loops to dynamically add brackets to SQL, so that th…
Browse files Browse the repository at this point in the history
…ey start at 0
  • Loading branch information
BojithaPiyathilake committed Jul 8, 2022
1 parent 0ee56a7 commit 29594d0
Showing 1 changed file with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3733,12 +3733,14 @@ protected SqlBuilder getQueryString(boolean isGroupFiltering, boolean isUsername
(isGroupFiltering && totalMultiGroupFilters > 1)) {
// Handle multi attribute filtering.
StringBuilder brackets = new StringBuilder(") AS R");
// x = 2 --> Any DB2 query will begin with 2 opening brackets
// (totalFilters * 2) --> totalFilters are multiplied by 2 as 2 new opening
// brackets are created for every new filter.
// (totalFilters * 2) - 1 --> Deducted by 1, as there is 1 closing brackets in the setTail
// section below.
for (int x = 2; x <= (totalFilters * 2) - 1; x++) {
/*
* x is used to count the number of brackets
* (totalFilters * 2) --> totalFilters are multiplied by 2 as 2 new opening
* brackets are created for every new filter, which needs to be closed at the right position
* (totalMultiClaimFilters * 2) - 3 is deducted as there are 2 opening brackets in the SQL
* query and 1 closing brackets in the setTail section below.
*/
for (int x = 0; x <= (totalFilters * 2) - 3; x++) {
brackets.append(" ) AS R");
}
sqlBuilder.setTail(brackets.toString().concat(") AS p WHERE p.rn BETWEEN 1 AND ?"),
Expand All @@ -3751,8 +3753,9 @@ protected SqlBuilder getQueryString(boolean isGroupFiltering, boolean isUsername
(isGroupFiltering && totalMultiGroupFilters > 1)) {
// Handle multi attribute filtering.
StringBuilder brackets = new StringBuilder(") AS R");
// - 1 as the remainder of the query within setTail() includes a single )
for (int x = 2; x <= (totalFilters * 2) - 1; x++) {
// - 3 due to 2 opening brackets and the remainder of the query within setTail() includes
// a single )
for (int x = 0; x <= (totalFilters * 2) - 3; x++) {
brackets.append(" ) AS R");
}
sqlBuilder.setTail(brackets.toString().concat(") AS p WHERE p.rn BETWEEN 1 AND ? " +
Expand All @@ -3768,8 +3771,9 @@ protected SqlBuilder getQueryString(boolean isGroupFiltering, boolean isUsername
(isGroupFiltering && totalMultiGroupFilters > 1)) {
// Handle multi attribute filtering.
StringBuilder brackets = new StringBuilder(") AS R");
// - 1 as the remainder of the query within setTail() includes a single )
for (int x = 2; x <= (totalFilters * 2) - 1; x++) {
// - 3 due to 2 opening brackets and the remainder of the query within setTail() includes
// a single )
for (int x = 0; x <= (totalFilters * 2) - 3; x++) {
brackets.append(" ) AS R");
}
sqlBuilder.setTail(brackets.toString().concat(") AS P WHERE P.RowNum BETWEEN 1 AND ?"),
Expand All @@ -3780,9 +3784,10 @@ protected SqlBuilder getQueryString(boolean isGroupFiltering, boolean isUsername
} else if (UserCoreConstants.PaginationDirection.PREVIOUS == direction) {
if ((isClaimFiltering && totalMultiClaimFilters > 1) ||
(isGroupFiltering && totalMultiGroupFilters > 1)) {
// Handle multi attribute filtering.
// - 3 due to 2 opening brackets and the remainder of the query within setTail() includes
// a single )
StringBuilder brackets = new StringBuilder(") AS R");
for (int x = 2; x <= (totalFilters * 2) - 1; x++) {
for (int x = 0; x <= (totalFilters * 2) - 3; x++) {
brackets.append(" ) AS R");
}
sqlBuilder.setTail(brackets.toString().concat(") AS P WHERE P.RowNum " +
Expand All @@ -3797,8 +3802,9 @@ protected SqlBuilder getQueryString(boolean isGroupFiltering, boolean isUsername
if ((isClaimFiltering && totalMultiClaimFilters > 1) ||
(isGroupFiltering && totalMultiGroupFilters > 1)) {
StringBuilder brackets = new StringBuilder(")");
// - 2 as the remainder of the query within setTail() includes two )
for (int x = 2; x <= (totalFilters * 2) - 2; x++) {
// - 3 due to 2 opening brackets and the remainder of the query within setTail() includes
// 2 closing brackets.
for (int x = 0; x <= (totalFilters * 2) - 4; x++) {
brackets.append(" )");
}
// Handle multi attribute filtering.
Expand All @@ -3811,9 +3817,9 @@ protected SqlBuilder getQueryString(boolean isGroupFiltering, boolean isUsername
if ((isClaimFiltering && totalMultiClaimFilters > 1) ||
(isGroupFiltering && totalMultiGroupFilters > 1)) {
StringBuilder brackets = new StringBuilder(")");
// Still - 2 because this is a query to get results in the previous direction which has
// an additional opening ( in the SQL
for (int x = 2; x <= (totalFilters * 2) - 2; x++) {
// Still - 4 because this is a query to get results in the previous direction which has
// an additional opening ( in the SQL and an additional ) in the setTail section.
for (int x = 0; x <= (totalFilters * 2) - 4; x++) {
brackets.append(" )");
}
// Handle multi attribute filtering.
Expand Down

0 comments on commit 29594d0

Please sign in to comment.