Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Not possible to limit maximum hit size #695

Open
jdiazgon opened this issue Oct 23, 2018 · 1 comment
Open

Not possible to limit maximum hit size #695

jdiazgon opened this issue Oct 23, 2018 · 1 comment

Comments

@jdiazgon
Copy link

In our deprecated SearchCriteriaTo, from version 2.x.x, we had a method called limitMaximumPageSize(int limit) . I'm trying to replicate it on the new 3.0.0 version. However, as we are now using Pageable, there is no method to limit the maximum hit size.

The way I found to do so is by using PageableDefault, which is an annotation that can be used to limit the maximum hit size like this:

  @Query("SELECT foo FROM FooEntity foo" //
      + " WHERE foo.message = :message")
  Page<FooEntity> findByMessage(@Param("message") String message, @PageableDefault(value = MAXIMUM_HIT_LIMIT) Pageable pageable);

I would like this option to be added to the QueryUtil file from OASP4J jpa basic, something similar to this:

  public <E> Page<E> findPaginated(@PageableDefault(value = MAXIMUM_HIT_LIMIT) Pageable pageable, JPAQuery<E> query, boolean determineTotal) {

    return findPaginatedGeneric(pageable, query, determineTotal);
  }

Perhaps you can tell me another way to do it that I'm not aware of. (Or maybe completely forget about this because it is not important??)

@jdiazgon
Copy link
Author

I have found a way to limit the page size that is returned to the client by implementing on AbstractGenericEntityUtils CobiGen template:

  private long limitMaximumPageSize(long totalElements) {

    if (totalElements > MAXIMUM_HIT_LIMIT)
      return MAXIMUM_HIT_LIMIT;

    return totalElements;
  }

However, this does not change the fact that the server executes a query trying to get any number of elements.

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

No branches or pull requests

1 participant