Skip to content

Replace derived CriteriaQuery with String-based queries #3653

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 5 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Oct 28, 2024

Closes #3588

@mp911de mp911de added the type: enhancement A general enhancement label Oct 28, 2024
@mp911de mp911de linked an issue Oct 28, 2024 that may be closed by this pull request
5 tasks
@mp911de mp911de force-pushed the issues/string-part-tree branch from f027352 to b881020 Compare October 28, 2024 08:09
Comment on lines 237 to 247
switch (type) {
case STARTING_WITH:
return String.format("%s%%", escape.escape(value.toString()));
case ENDING_WITH:
return String.format("%%%s", escape.escape(value.toString()));
case CONTAINING:
case NOT_CONTAINING:
return String.format("%%%s%%", escape.escape(value.toString()));
default:
return value;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch (type) {
case STARTING_WITH:
return String.format("%s%%", escape.escape(value.toString()));
case ENDING_WITH:
return String.format("%%%s", escape.escape(value.toString()));
case CONTAINING:
case NOT_CONTAINING:
return String.format("%%%s%%", escape.escape(value.toString()));
default:
return value;
}
String escapedValue = escape.escape(value.toString());
return switch (type) {
case STARTING_WITH -> escapedValue + "%";
case ENDING_WITH -> "%" + escapedValue;
case CONTAINING, NOT_CONTAINING -> "%" + escapedValue + "%";
default -> value;
};

Consider leveraging the switch expression for its readability and declaring escapedValue once to avoid redundancy.

Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of minor complains and questions

lock.unlock();
protected JpqlQueryCreator createCreator(Sort sort, JpaParametersParameterAccessor accessor) {

synchronized (cache) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be less error prone to make the cache implementation synchronized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It likely does make sense, also the count query requires a revision of its caching to consider nullable values. Good catch!

mp911de and others added 3 commits November 20, 2024 14:28
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.
Make usage of ParameterExpression more explicit. Add JPQL rendering tests.
Favor Metamodel over From for building jpql queries.
Align IsNull and IsNotNull handling.
Support Derived Delete and Exists, consider null values when caching queries.
@mp911de mp911de force-pushed the issues/string-part-tree branch from 8969f54 to 87b700b Compare November 20, 2024 13:41
@mp911de mp911de changed the base branch from main to 4.0.x November 20, 2024 13:45
@mp911de mp911de added this to the 4.0 M1 (2025.1.0) milestone Nov 21, 2024
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.
@mp911de mp911de force-pushed the issues/string-part-tree branch from 87b700b to 801e007 Compare November 21, 2024 09:38
@mp911de mp911de changed the title Replace CriteriaQuery with String-based queries Replace derived CriteriaQuery with String-based queries Nov 22, 2024
mp911de added a commit that referenced this pull request Nov 22, 2024
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.

Closes #3588
Original pull request: #3653
mp911de pushed a commit that referenced this pull request Nov 22, 2024
Make usage of ParameterExpression more explicit. Add JPQL rendering tests.
Favor Metamodel over From for building jpql queries.
Align IsNull and IsNotNull handling.
Support Derived Delete and Exists, consider null values when caching queries.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Nov 22, 2024
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Nov 22, 2024
See #3588
Original pull request: #3653
@mp911de mp911de closed this Nov 22, 2024
@mp911de mp911de deleted the issues/string-part-tree branch November 22, 2024 08:54
mp911de added a commit that referenced this pull request Nov 22, 2024
See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Nov 29, 2024
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.

Closes #3588
Original pull request: #3653
mp911de pushed a commit that referenced this pull request Nov 29, 2024
Make usage of ParameterExpression more explicit. Add JPQL rendering tests.
Favor Metamodel over From for building jpql queries.
Align IsNull and IsNotNull handling.
Support Derived Delete and Exists, consider null values when caching queries.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Nov 29, 2024
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Nov 29, 2024
See #3588
Original pull request: #3653
@mp911de mp911de self-assigned this Dec 10, 2024
mp911de added a commit that referenced this pull request Dec 11, 2024
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.

Closes #3588
Original pull request: #3653
mp911de pushed a commit that referenced this pull request Dec 11, 2024
Make usage of ParameterExpression more explicit. Add JPQL rendering tests.
Favor Metamodel over From for building jpql queries.
Align IsNull and IsNotNull handling.
Support Derived Delete and Exists, consider null values when caching queries.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Dec 11, 2024
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Dec 11, 2024
See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Jan 14, 2025
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.

Closes #3588
Original pull request: #3653
mp911de pushed a commit that referenced this pull request Jan 14, 2025
Make usage of ParameterExpression more explicit. Add JPQL rendering tests.
Favor Metamodel over From for building jpql queries.
Align IsNull and IsNotNull handling.
Support Derived Delete and Exists, consider null values when caching queries.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Jan 14, 2025
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Jan 14, 2025
See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Mar 17, 2025
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.

Closes #3588
Original pull request: #3653
mp911de pushed a commit that referenced this pull request Mar 17, 2025
Make usage of ParameterExpression more explicit. Add JPQL rendering tests.
Favor Metamodel over From for building jpql queries.
Align IsNull and IsNotNull handling.
Support Derived Delete and Exists, consider null values when caching queries.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Mar 17, 2025
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Mar 17, 2025
See #3588
Original pull request: #3653
christophstrobl pushed a commit that referenced this pull request Mar 19, 2025
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.

Closes #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Apr 14, 2025
Introduce new DSL to construct JPQL queries. Refactor ParameterMetadata to PartTreeParameterBinding.

Disable Keyset pagination with projections for Eclipselink as Eclipselink doesn't consider type hints for JPQL queries.

Closes #3588
Original pull request: #3653
mp911de pushed a commit that referenced this pull request Apr 14, 2025
Make usage of ParameterExpression more explicit. Add JPQL rendering tests.
Favor Metamodel over From for building jpql queries.
Align IsNull and IsNotNull handling.
Support Derived Delete and Exists, consider null values when caching queries.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Apr 14, 2025
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.

See #3588
Original pull request: #3653
mp911de added a commit that referenced this pull request Apr 14, 2025
See #3588
Original pull request: #3653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace derived CriteriaQuery with String-based queries
4 participants