java.lang.Object
org.keycloak.models.sessions.infinispan.query.QueryHelper

public final class QueryHelper extends Object
  • Field Details

    • SINGLE_PROJECTION_TO_LONG

      public static final Function<Object[],Long> SINGLE_PROJECTION_TO_LONG
      Converts a single projection results into a long value.
    • SINGLE_PROJECTION_TO_STRING

      public static final Function<Object[],String> SINGLE_PROJECTION_TO_STRING
      Converts a single projection value into a String.
    • PROJECTION_TO_STRING_LONG_ENTRY

      public static final Function<Object[],Map.Entry<String,Long>> PROJECTION_TO_STRING_LONG_ENTRY
      Converts a projection with two values into a Map.Entry of String and Long, where the key is the first projection, and the second is the second project.
  • Method Details

    • fetchSingle

      public static <T, R> Optional<R> fetchSingle(org.infinispan.commons.api.query.Query<T> query, Function<T,R> mapping)
      Fetches a single value from the query.

      This method changes the Query state to return just a single value.

      Type Parameters:
      T - The Query response type.
      R - The Optional type.
      Parameters:
      query - The Query instance.
      mapping - The Function that maps the query results (projection) into the result.
      Returns:
      An Optional with the Query results mapped.
    • streamAll

      public static <T, R> Stream<R> streamAll(org.infinispan.commons.api.query.Query<T> query, int batchSize, Function<T,R> mapping)
      Streams using batching over all results from the Query.

      If a large result set is expected, this method is recommended to avoid loading downloading a lot of data in a single request.

      The results are fetched on demand.

      Warning: This method changes ignores the start offset and the max results. It will return everything.

      Type Parameters:
      T - The Query response type.
      R - The Stream type.
      Parameters:
      query - The Query instance.
      batchSize - The number of results to fetch for each remote request.
      mapping - The Function that maps the query results (projection) into the result.
      Returns:
      A Stream with the results.
    • toCollection

      public static <T, R> Collection<R> toCollection(org.infinispan.commons.api.query.Query<T> query, Function<T,R> mapping)
      Performs the Query and returns the results.

      This method is preferred to Query.list() since it does not have to compute an accurate hit count (affects Indexed query performance).

      If a large dataset is expected, use streamAll(Query, int, Function).

      Type Parameters:
      T - The Query response type.
      R - The Collection type.
      Parameters:
      query - The Query instance.
      mapping - The Function that maps the query results (projection) into the result.
      Returns:
      A Collection with the results.