Skip to content

Commit

Permalink
workaround for negative results
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Feb 18, 2024
1 parent 28c5ccc commit 7f09d48
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,20 @@ public List<T> getSearchResults(@Nonnull SearchParameterMap theParams) {

TypedQuery<T> executableQuery = (TypedQuery<T>) criteriaContext.getEntityManager()
.createQuery(criteriaContext.getCriteriaQuery());

executableQuery.setFirstResult(theParams.getFromIndex());
if (theParams.getToIndex() != Integer.MAX_VALUE) {
int maxResults = theParams.getToIndex() - theParams.getFromIndex();
executableQuery.setMaxResults(maxResults);
if (maxResults >= 0) {
executableQuery.setMaxResults(maxResults);
} else {
// TODO: this is really just a workaround, we can find a better way of handling the negative results
int negative = theParams.getFromIndex() - theParams.getToIndex();
executableQuery.setMaxResults(negative);
}
}



if (hasDistinctResults()) {
results = (List<T>) criteriaContext.getEntityManager().createQuery(criteriaContext.getCriteriaQuery())
.getResultList();
Expand Down

0 comments on commit 7f09d48

Please sign in to comment.