Interface QueryUtils


public interface QueryUtils
  • Method Details

    • queryOneToOne

      static <ID, R, IDC extends Collection<ID>, RC extends Collection<R>, EX extends Throwable> Map<ID,R> queryOneToOne(IDC ids, CheckedFunction1<IDC,RC,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults) throws EX
      Throws:
      EX extends Throwable
    • queryOneToOne

      static <ID, R, IDC extends Collection<ID>, RC extends Collection<R>, EX extends Throwable> Map<ID,R> queryOneToOne(IDC ids, CheckedFunction1<IDC,RC,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults, MapFactory<ID,R> mapFactory) throws EX
      Throws:
      EX extends Throwable
    • queryOneToOne

      static <ID, R, IDC extends Collection<ID>, RC extends Collection<R>, EX extends Throwable> Map<ID,R> queryOneToOne(IDC ids, CheckedFunction1<IDC,RC,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults, Function<ID,R> defaultResultProvider) throws EX
      Throws:
      EX extends Throwable
    • queryOneToOne

      static <ID, R, IDC extends Collection<ID>, RC extends Collection<R>, EX extends Throwable> Map<ID,R> queryOneToOne(IDC ids, CheckedFunction1<IDC,RC,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults, Function<ID,R> defaultResultProvider, MapFactory<ID,R> mapFactory) throws EX
      Throws:
      EX extends Throwable
    • queryOneToManyAsList

      static <ID, R, IDC extends Collection<ID>, EX extends Throwable> Map<ID,List<R>> queryOneToManyAsList(IDC ids, CheckedFunction1<IDC,List<R>,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults) throws EX
      Throws:
      EX extends Throwable
    • queryOneToManyAsList

      static <ID, R, IDC extends Collection<ID>, EX extends Throwable> Map<ID,List<R>> queryOneToManyAsList(IDC ids, CheckedFunction1<IDC,List<R>,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults, MapFactory<ID,List<R>> mapFactory) throws EX
      Throws:
      EX extends Throwable
    • queryOneToManyAsSet

      static <ID, R, IDC extends Collection<ID>, EX extends Throwable> Map<ID,Set<R>> queryOneToManyAsSet(IDC ids, CheckedFunction1<IDC,Set<R>,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults) throws EX
      Throws:
      EX extends Throwable
    • queryOneToManyAsSet

      static <ID, R, IDC extends Collection<ID>, EX extends Throwable> Map<ID,Set<R>> queryOneToManyAsSet(IDC ids, CheckedFunction1<IDC,Set<R>,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults, MapFactory<ID,Set<R>> mapFactory) throws EX
      Throws:
      EX extends Throwable
    • queryOneToMany

      static <ID, R, IDC extends Collection<ID>, RC extends Collection<R>, EX extends Throwable> Map<ID,RC> queryOneToMany(IDC ids, CheckedFunction1<IDC,RC,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults, Supplier<RC> collectionFactory) throws EX
      Throws:
      EX extends Throwable
    • queryOneToMany

      static <ID, R, IDC extends Collection<ID>, RC extends Collection<R>, EX extends Throwable> Map<ID,RC> queryOneToMany(IDC ids, CheckedFunction1<IDC,RC,EX> queryFunction, Function<R,ID> idExtractorFromQueryResults, Supplier<RC> collectionFactory, MapFactory<ID,RC> mapFactory) throws EX
      Throws:
      EX extends Throwable
    • query

      static <V, ID, R, IDC extends Collection<ID>, RC extends Collection<R>, EX extends Throwable> Map<ID,V> query(IDC ids, CheckedFunction1<IDC,RC,EX> queryFunction, Function<ID,V> defaultResultProvider, Collector<R,?,Map<ID,V>> mapCollector) throws EX
      Type Parameters:
      V - Type of each value representing the result from queryFunction associated with each ID, will map to either <R> when called from queryOneToOne or <RC> when called from queryOneToMany i.e. a collection of <R>. This is conceptually a union type <R> | <RC>
      ID - Type of the ids passed to queryFunction e.g. Long, String
      R - Type of individual results returned from the queryFunction
      IDC - Type of the Collection containing the ids of type <ID> e.g. List<Long>, Set<String>, etc.
      RC - Type of the Collection containing the results of type <R> e.g. List<Customer>, Set<Order>, etc.
      EX - Type of the exception that can be thrown by the queryFunction
      Parameters:
      ids - The collection of ids to pass to the queryFunction
      queryFunction - The query function to call (rest call, spring data repository method call, etc.)
      defaultResultProvider - The default value to generate if no result for a specific id passed to the queryFunction e.g. an empty collection, a default value, an empty string, etc.
      mapCollector - The collector used to collect the stream of results returned by queryFunction. It will transform a stream of results to a Map<ID, V>
      Returns:
      A Map of the results from invoking the queryFunction with key = correlation ID, value = result associated with ID
      Throws:
      EX - If queryFunction throws an exception, that exception will be propagated to the caller of this method
    • safeApply

      static <T, R, C extends Collection<? extends T>, RC extends Collection<? extends R>, EX extends Throwable> Stream<? extends R> safeApply(C coll, CheckedFunction1<C,RC,EX> queryFunction)
      Type Parameters:
      T -
      R -
      C -
      RC -
      EX -
      Parameters:
      coll - The list of arguments to pass to the queryFunction e.g. List<Long> for passing a list of IDs to query a database
      queryFunction - The function to apply the list of arguments
      Returns: