Class PersistenceHelper


  • public class PersistenceHelper
    extends java.lang.Object
    Class implementing helper methods for the persistence layer.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> javax.persistence.criteria.Predicate toLikePredicate​(javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.Root<T> root, java.lang.String attributeName, java.lang.String pattern, org.hibernate.criterion.MatchMode matchMode, boolean caseSensitive)
      Creates a Predicate representing a "like", which matches the given attributeName (of the EntityType got by executing Root.getModel() from the given Root) with the given pattern.
      static <T> void validatePageable​(org.springframework.data.domain.Pageable pageable, java.lang.Class<T> klass)
      Validates that the given Pageable is valid for querying entities of the given klass.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PersistenceHelper

        public PersistenceHelper()
    • Method Detail

      • toLikePredicate

        public static <T> javax.persistence.criteria.Predicate toLikePredicate​(javax.persistence.criteria.CriteriaBuilder cb,
                                                                               javax.persistence.criteria.Root<T> root,
                                                                               java.lang.String attributeName,
                                                                               java.lang.String pattern,
                                                                               org.hibernate.criterion.MatchMode matchMode,
                                                                               boolean caseSensitive)
        Creates a Predicate representing a "like", which matches the given attributeName (of the EntityType got by executing Root.getModel() from the given Root) with the given pattern.
        Type Parameters:
        T - The concrete type of EntityType to which this predicate is applied.
        Parameters:
        cb - The CriteriaBuilder used to build the Predicate.
        root - The Root from where the Predicate will be used.
        attributeName - The attribute name from the given EntityType to match
        pattern - The pattern to match.
        matchMode - The MatchMode to be applied (i.e exact, start, end or anywhere).
        caseSensitive - A flag indicating if the match must be case sensitive.
        Returns:
        The resulting Predicate.
      • validatePageable

        public static <T> void validatePageable​(org.springframework.data.domain.Pageable pageable,
                                                java.lang.Class<T> klass)
                                         throws com.bellotapps.webapps_commons.exceptions.InvalidPropertiesException
        Validates that the given Pageable is valid for querying entities of the given klass.
        Type Parameters:
        T - The concrete type of the entities.
        Parameters:
        pageable - The Pageable to be validated.
        klass - The class representing the entity.
        Throws:
        com.bellotapps.webapps_commons.exceptions.InvalidPropertiesException - If it has a Sort with invalid properties.