Skip to content
Snippets Groups Projects

fix: Update persistence pagination to properly respect configured limits

Merged Zachary Sabourin requested to merge persistence-pagination-fix into main
4 files
+ 100
5
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -56,8 +56,10 @@ public abstract class BaseHibernateDao implements PersistenceDao {
@ConfigProperty(name = "quarkus.micrometer.enabled")
boolean isMetricsEnabled;
// needs to be a property like this, as there are race conditions in some APIs when using object mapping
@ConfigProperty(name = PersistencePropertyNames.PERSISTENCE_PAGINATION_LIMIT, defaultValue="100")
@ConfigProperty(name = PersistencePropertyNames.PERSISTENCE_PAGINATION_LIMIT, defaultValue = "100")
int defaultPaginationLimit;
@ConfigProperty(name = PersistencePropertyNames.PERSISTENCE_PAGINATION_LIMIT_MAX, defaultValue = "1000")
int maxPaginationLimit;
@Inject
EntityManager primaryConnectionManager;
@@ -203,14 +205,19 @@ public abstract class BaseHibernateDao implements PersistenceDao {
}
/**
* Get the limit for entities returned in a single bound request.
* Get the limit for entities returned in a single bound request. Will use the default limit if no pagination is provided. Will respect
* the maximum configured limit if the provided one is set higher than allowed.
*
* @param q the query params for the current request to check for set limit in params
* @return the number of entities allowed
*/
@Override
public int getLimit(RDBMSQuery<?> q) {
return q.getLimit() > 0 ? Math.min(q.getLimit(), defaultPaginationLimit) : defaultPaginationLimit;
// If no pagesize param is provided, this will default to -1
if (q.getLimit() < 0) {
return defaultPaginationLimit;
}
return Math.min(q.getLimit(), maxPaginationLimit);
}
/**
Loading