From b494b8bb44aa0b67ed08126d4075da5e24995cf0 Mon Sep 17 00:00:00 2001 From: Martin Kanis Date: Thu, 29 Oct 2020 11:24:22 +0100 Subject: [PATCH] KEYCLOAK-16034 Not scroll-able event queries for postgres and mssql --- .../java/org/keycloak/events/jpa/JpaAdminEventQuery.java | 6 +++++- .../main/java/org/keycloak/events/jpa/JpaEventQuery.java | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java b/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java index 90ae955577..54a5a8b269 100755 --- a/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java +++ b/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java @@ -35,6 +35,7 @@ import java.util.LinkedList; import java.util.List; import java.util.stream.Stream; +import static org.keycloak.events.jpa.JpaEventQuery.DEFAULT_MAX_RESULTS; import static org.keycloak.utils.StreamsUtil.closing; /** @@ -158,9 +159,12 @@ public class JpaAdminEventQuery implements AdminEventQuery { if (maxResults != null) { query.setMaxResults(maxResults); + } else { + // to workaround https://hibernate.atlassian.net/browse/HHH-14295 + query.setMaxResults(DEFAULT_MAX_RESULTS); } - return closing(query.getResultList().stream().map(JpaEventStoreProvider::convertAdminEvent)); + return closing(query.getResultStream().map(JpaEventStoreProvider::convertAdminEvent)); } } diff --git a/model/jpa/src/main/java/org/keycloak/events/jpa/JpaEventQuery.java b/model/jpa/src/main/java/org/keycloak/events/jpa/JpaEventQuery.java index f6f96cc3a9..fa86050009 100644 --- a/model/jpa/src/main/java/org/keycloak/events/jpa/JpaEventQuery.java +++ b/model/jpa/src/main/java/org/keycloak/events/jpa/JpaEventQuery.java @@ -48,6 +48,8 @@ public class JpaEventQuery implements EventQuery { private Integer firstResult; private Integer maxResults; + public static final int DEFAULT_MAX_RESULTS = Integer.MAX_VALUE >> 1; + public JpaEventQuery(EntityManager em) { this.em = em; @@ -131,10 +133,12 @@ public class JpaEventQuery implements EventQuery { if (maxResults != null) { query.setMaxResults(maxResults); + } else { + // to workaround https://hibernate.atlassian.net/browse/HHH-14295 + query.setMaxResults(DEFAULT_MAX_RESULTS); } - - return closing(query.getResultList().stream().map(JpaEventStoreProvider::convertEvent)); + return closing(query.getResultStream().map(JpaEventStoreProvider::convertEvent)); } }