Class DaoHelpers

java.lang.Object
org.kiwiproject.beta.dao.DaoHelpers

@Beta public final class DaoHelpers extends Object
Some simple utilities useful to data access code that is building queries, for example, structured query languages such as SQL or HQL.

This is useful in situations where you have a relatively static query, but you need to add dynamically defined sorting/ordering.

  • Method Details

    • addSorts

      public static void addSorts(StringBuilder query, AllowedFields allowedSortFields, org.kiwiproject.spring.data.PagingRequest pagingRequest)
      Add sorts to the query restricting by the AllowedFields for the PagingRequest.
    • addSort

      public static void addSort(StringBuilder query, AllowedFields allowedSortFields, org.kiwiproject.spring.data.KiwiSort sort)
      Add a sort to the query restricting by the AllowedFields for the KiwiSort.
    • addSort

      public static void addSort(StringBuilder query, AllowedFields allowedSortFields, String sortField, @Nullable org.kiwiproject.spring.data.KiwiSort.Direction sortDirection)
      Add a sort to the query restricting by the AllowedFields for the sort field and direction.
    • addSorts

      public static void addSorts(StringBuilder query, AllowedFields allowedSortFields, org.kiwiproject.spring.data.KiwiSort primarySort, org.kiwiproject.spring.data.KiwiSort secondarySort)
      Add sorts to the query restricting by the AllowedFields for the primary and secondary sort criteria.
    • addSorts

      public static void addSorts(StringBuilder query, AllowedFields allowedSortFields, @Nullable String primarySortField, @Nullable org.kiwiproject.spring.data.KiwiSort.Direction primarySortDirection, @Nullable String secondarySortField, @Nullable org.kiwiproject.spring.data.KiwiSort.Direction secondarySortDirection)
      Add sorts to the query restricting by the AllowedFields for the primary and secondary sort fields and directions.

      This allows for the possibility that there are no sort criteria, in which case the query is not modified.

      Implementation Note:
      If a secondary sort is specified but not a primary sort, then a warning is logged, the secondary sort is ignored, and therefore the query is not modified.
    • addSorts

      public static void addSorts(StringBuilder query, AllowedFields allowedSortFields, org.kiwiproject.spring.data.KiwiSort... sorts)
      Adds sorts to the query restricting by the AllowedFields for all the specified sorts.

      This allows for the possibility that there are no sort criteria, in which case the query is not modified.

      Implementation Note:
      Any null values in the sorts array are filtered out
    • addSorts

      public static void addSorts(StringBuilder query, AllowedFields allowedSortFields, List<org.kiwiproject.spring.data.KiwiSort> sorts)
      Adds sorts to the query restricting by the AllowedFields for all the specified sorts.

      This allows for the possibility that there are no sort criteria, in which case the query is not modified.

      Implementation Note:
      Any null values in the sorts list are filtered out