Class EntityUtils

java.lang.Object
com.broadleafcommerce.common.jpa.EntityUtils

public final class EntityUtils extends Object
  • Method Details

    • findByFieldInUsingPartitioning

      public static <I, O> List<O> findByFieldInUsingPartitioning(List<I> fieldValues, int partitionSize, I pad, Function<List<I>,List<O>> baseFindByFieldValues)
      Partition a list of values to be run through the provided function in `baseFindByFieldValues` and return a List of items retrieved from the function call. The returned List will be the total combined items found from the partitions.

      This can be useful when a function attempts to grab information from another location and the input values are greater than limit of the call. Often this should be utilized for a custom JpaRepository function. For example, if an IN clause is utilized in a repository call, a particular DB may only hold ~1000 input entries for the query.

      The provided `pad` field will add entries into a list if there are not enough entries to meet the `partitionSize`. In order for padding to work, it should be set to a value that is known to not conflict with the input values. An example of a valid pad value is "-" when the input value is an ID of known character set and length. Padding the lists aids in keeping list sizes equal. This optimizes the prepared statement compilation to reduce variation.

      Type Parameters:
      I - Arbitrary type used for the input fields
      O - Arbitrary type used for the entries of the list to return
      Parameters:
      fieldValues - input values which need to be partitioned
      partitionSize - provided size to partition the field values
      pad - value used to pad the partitions; padding keeps partitioned lists the same size
      baseFindByFieldValues - function run utilizing the partitioned field values
      Returns:
      a list of the provided values
    • findByFieldInUsingPartitioningToMap

      public static <I, O, P> Map<O,P> findByFieldInUsingPartitioningToMap(List<I> fieldValues, int partitionSize, I pad, Function<List<I>,Map<O,P>> baseFindByFieldValues)
      Partition a list of values to be run through the provided function in `baseFindByFieldValues` and return a Map of items retrieved from the function call. The returned Map will be the total combined items found from the partitions.

      This can be useful when a function attempts to grab information from another location and the input values are greater than limit of the call. Often this should be utilized for a custom JpaRepository function. For example, if an IN clause is utilized in a repository call, a particular DB may only hold ~1000 input entries for the query.

      The provided `pad` field will add entries into a list if there are not enough entries to meet the `partitionSize`. In order for padding to work, it should be set to a value that is known to not conflict with the input values. An example of a valid pad value is "-" when the input value is an ID of known character set and length. Padding the lists aids in keeping list sizes equal. This optimizes the prepared statement compilation to reduce variation.

      Type Parameters:
      I - Arbitrary type used for the input fields
      O - Arbitrary type used for the key entries of the map to return
      P - Arbitrary type used for the value entries of the map to return
      Parameters:
      fieldValues - input values which need to be partitioned
      partitionSize - provided size to partition the field values
      pad - value used to pad the partitions; padding keeps partitioned lists the same size
      baseFindByFieldValues - function run utilizing the partitioned field values
      Returns:
      a map of the provided <O, P> values
    • partitionWithPadding

      public static <T> List<List<T>> partitionWithPadding(List<T> fieldValues, int partitionSize, T pad)
      Partition the list of provided `fieldValues` into a nested list containing partitions of size `partitionSize`.

      The provided `pad` field will add entries into a list if there are not enough entries to meet the `partitionSize`. In order for padding to work, it should be set to a value that is known to not conflict with the input values. An example of a valid pad value is "-" when the input value is an ID of known character set and length. Padding the lists aids in keeping list sizes equal. This optimizes the prepared statement compilation to reduce variation.

      Type Parameters:
      T - Arbitrary type used for the input fields
      Parameters:
      fieldValues - input values which need to be partitioned
      partitionSize - provided size to partition the field values
      pad - value used to pad the partitions; padding keeps partitioned lists the same size
      Returns:
      List of List typed partitions of `partitionSize` size