Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Add support for isOnlyMatchPrefix in EntityQuery #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kkakareko
Copy link

OnlyMatchPrefix in SimpleStringFilter

@@ -321,9 +321,11 @@ private Predicate setFilter(final Container.Filter filter, final CriteriaBuilder
final SimpleStringFilter simpleStringFilter = (SimpleStringFilter) filter;
final Expression<String> property = (Expression) getPropertyPath(root, simpleStringFilter.getPropertyId());
if (simpleStringFilter.isIgnoreCase()) {
return cb.like(cb.lower(property), "%" + simpleStringFilter.getFilterString() + "%");
return cb.like(cb.lower(property), (simpleStringFilter.isOnlyMatchPrefix() ? "" : "%")

Choose a reason for hiding this comment

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

Why duplicate the logic if you can do it once before the if?

  final String filterExpression = (simpleStringFilter.isOnlyMatchPrefix() ? "" : "%") 
          + simpleStringFilter.getFilterString() + "%";
  if (...) {
        return cb.like(cb.lower(property), filterExpression);
  } else {
        return cb.like(property, filterExpression);
  }

@kkakareko
Copy link
Author

@KyleRogers Good point.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants