Skip to content

Case insensitive Constraints via ignoreCase method per Constraint subtype that can support it #1006

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

njr-11
Copy link
Contributor

@njr-11 njr-11 commented Mar 6, 2025

Option 2 for case insensitive Constraints:
Add .ignoreCase() to specific subtypes of Constraint that are capable of case insensitive comparisons when operating on String values. This includes Like, NotLike, EqualTo, NotEqualTo, Between, NotBetween, and the various GT/LT/GTE/LTE constraints. If a user ever invokes ignoreCase() on a constraint that has a non-String value, it will raise UnsupportedOperationException.
Provide an isCaseSensitive() method for each of these same subtypes to determine if a Constraint performs case insensitive comparisons, defaulting it based on whether the value is a String (true for String and false for others). When it starts as true, an instance with false can be obtained by invoking ignoreCase().

Example usage:

List<Book> booksTitled(Constraint<String> title);

found = library.booksTitled(Constraint.equalTo("Developing with Jakarta Data").ignoreCase());

We should choose between this PR or #1005 (or if someone thinks of another way) for case-insensitive constraints

@njr-11 njr-11 added the enhancement New feature or request label Mar 6, 2025
@njr-11 njr-11 added this to the 1.1 milestone Mar 6, 2025
@njr-11 njr-11 changed the title Case insensitive Constraints via common getter, separate ignoreCase methods Case insensitive Constraints via ignoreCase method per Constraint subtype that can support it Mar 6, 2025
@njr-11 njr-11 force-pushed the 829-case-insensitive-constraints-option-2 branch from 4cf77a0 to 20536d4 Compare March 7, 2025 19:47
@njr-11
Copy link
Contributor Author

njr-11 commented Apr 2, 2025

Now that TextExpression.upper/lower went in and provided an alternative to ignoreCase for Restriction, we had a discussion on today's Jakarta Data call about how to cover case insensitive for the pattern of Constraint parameters being supplied to repository methods. The other solution under #1005 was preferred by all 5 participants on the call instead of the solution under this PR, so at this time, I am not planning to resolve the merge conflicts within this PR.

@gavinking
Copy link
Contributor

gavinking commented Apr 2, 2025

Sorry I could not make it to the call today, I had an exam at the same time.

I am not planning to resolve the merge conflicts within this PR.

I'm not particularly a fan of either approach, so I agree that we don't need to move forward with this one, which adds quite a lot of complexity for something of really quite marginal value.

Seems to me that the most parsimonious thing to do — supposing we need to even do anything at this stage — would be to add the concept of case-insensitivity back to Like, where it is quite commonly used, and just forget about the other comparisons. That option:

  • adds only a teensy bit of incremental complexity, and no new API concepts,
  • covers upward of 95% of usage patterns, and
  • is highly discoverable for users.

Note that for the cases which are not covered by Like, users have the escape hatch of writing the query in JDQL. We don't need to dupe every feature of JDQL in @Find methods.

@njr-11
Copy link
Contributor Author

njr-11 commented Apr 29, 2025

Closing this in favor of #1005

@njr-11 njr-11 closed this Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants