-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Differentiate between JPQL and native queries in count query derivation #2777
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
Conversation
We now consider whether a query is a native one when deriving a count query for pagination. Previously, the generated queries used JPQL syntax that doesn't comply with native SQL syntax rules.
De-duplicate code, use parametrized tests instead of test methods to verify individual fixtures. Ensure all variants are tested with JSQLparser and the default enhancer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put in some naming suggestions. But apart from that, it looks great. Like the TCK tactic.
} | ||
|
||
@Test // GH-2578 | ||
void deeplyNestedcomplexSetOperationListWorks() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps make it deeplyNestedComplexSetOperationListWorks
?
} | ||
|
||
@Test // GH-2578 | ||
void valuesStatementsWorks() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps valuesStatementWorks
?
} | ||
|
||
@Test // GH-2578 | ||
void withStatementsWorks() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps withStatementWorks
?
} | ||
|
||
@Test // GH-2578 | ||
void multipleWithStatementsWorks() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps multipleWithStatementsWork
?
* @return a query String to be used a count query for pagination. Guaranteed to be not {@literal null}. | ||
* @since 2.7.8 | ||
*/ | ||
static String createCountQueryFor(String originalQuery, @Nullable String countProjection, boolean nativeQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer two separate methods createCountQueryForNative
and createCountQueryForJpql
plus extracting the common parts into a new method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My gut feeling is that we should rethink QueryUtils
entirely and eventually eliminate the most methods (or create delegates). Therefore, I would want to refrain from introducing additional methods for the time being unless new methods heavily improve the code.
That's merged and back ported to 3.0.x |
String alias = QueryUtils.detectAlias(originalQuery); | ||
if ("*".equals(variable) && alias != null) { | ||
replacement = alias; | ||
if (nativeQuery && (variable.contains(",") || "*".equals(variable))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it is a native query and the variable is null 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you run into a bug or you can reproduce such a case, please file a bug report.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already present #2812
will it be back ported to 2.7.x? |
Yes, we will backport the fix to 2.7.x. |
We now consider whether a query is a native one when deriving a count query for pagination. Previously, the generated queries used JPQL syntax that doesn't comply with native SQL syntax rules.
Also, cleanup tests, deduplicate test code, and rearrange test cases into a maintainable form.
Closes #2773