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

Add support for isOnlyMatchPrefix in EntityQuery#89

Open
kkakareko wants to merge 2 commits intotlaukkan:masterfrom
kkakareko:master
Open

Add support for isOnlyMatchPrefix in EntityQuery#89
kkakareko wants to merge 2 commits intotlaukkan:masterfrom
kkakareko:master

Conversation

@kkakareko
Copy link

OnlyMatchPrefix in SimpleStringFilter

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