snoopdave commented on code in PR #222:
URL: https://github.com/apache/roller/pull/222#discussion_r4419618189
##########
app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java:
##########
@@ -289,6 +289,36 @@ public List<User> getUsersStartingWith(String startsWith,
Boolean enabled,
return query.getResultList();
}
+ @Override
+ public List<User> getUsersWithUserNameStartingWith(String startsWith,
Boolean enabled,
+ int offset, int length) throws WebloggerException {
+ TypedQuery<User> query;
+ if (enabled != null) {
+ query =
strategy.getNamedQuery("User.getByEnabled&UserNameStartsWith", User.class);
+ query.setParameter(1, enabled);
+ query.setParameter(2, likePrefix(startsWith == null ? "" :
startsWith));
+ } else {
+ query = strategy.getNamedQuery("User.getByUserNameStartsWith",
User.class);
+ query.setParameter(1, likePrefix(startsWith == null ? "" :
startsWith));
+ }
+ if (offset != 0) {
+ query.setFirstResult(offset);
+ }
+ if (length != -1) {
+ query.setMaxResults(length);
+ }
+ return query.getResultList();
+ }
+
+ /**
+ * LIKE pattern that matches values starting with the given text. The
+ * named queries use '!' as the escape character, so '%' and '_' in the
+ * text match only themselves.
+ */
+ static String likePrefix(String startsWith) {
Review Comment:
This is package-private and pure, so it's easy to unit-test directly.
Nothing tests `!` yet: `a!b` gives `a!!b%`, `a%b` gives `a!%b%`, `""` gives `%`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]