KEYCLOAK-16034 Not scroll-able event queries for postgres and mssql

This commit is contained in:
Martin Kanis 2020-10-29 11:24:22 +01:00 committed by Hynek Mlnařík
parent 925f089d62
commit b494b8bb44
2 changed files with 11 additions and 3 deletions

View file

@ -35,6 +35,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.keycloak.events.jpa.JpaEventQuery.DEFAULT_MAX_RESULTS;
import static org.keycloak.utils.StreamsUtil.closing; import static org.keycloak.utils.StreamsUtil.closing;
/** /**
@ -158,9 +159,12 @@ public class JpaAdminEventQuery implements AdminEventQuery {
if (maxResults != null) { if (maxResults != null) {
query.setMaxResults(maxResults); 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));
} }
} }

View file

@ -48,6 +48,8 @@ public class JpaEventQuery implements EventQuery {
private Integer firstResult; private Integer firstResult;
private Integer maxResults; private Integer maxResults;
public static final int DEFAULT_MAX_RESULTS = Integer.MAX_VALUE >> 1;
public JpaEventQuery(EntityManager em) { public JpaEventQuery(EntityManager em) {
this.em = em; this.em = em;
@ -131,10 +133,12 @@ public class JpaEventQuery implements EventQuery {
if (maxResults != null) { if (maxResults != null) {
query.setMaxResults(maxResults); query.setMaxResults(maxResults);
} else {
// to workaround https://hibernate.atlassian.net/browse/HHH-14295
query.setMaxResults(DEFAULT_MAX_RESULTS);
} }
return closing(query.getResultStream().map(JpaEventStoreProvider::convertEvent));
return closing(query.getResultList().stream().map(JpaEventStoreProvider::convertEvent));
} }
} }