Class PersistenceHelper
- java.lang.Object
-
- com.bellotapps.webapps_commons.persistence.PersistenceHelper
-
public class PersistenceHelper extends java.lang.ObjectClass implementing helper methods for the persistence layer.
-
-
Constructor Summary
Constructors Constructor Description PersistenceHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> javax.persistence.criteria.PredicatetoLikePredicate(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 aPredicaterepresenting a "like", which matches the givenattributeName(of theEntityTypegot by executingRoot.getModel()from the givenRoot) with the givenpattern.static <T> voidvalidatePageable(org.springframework.data.domain.Pageable pageable, java.lang.Class<T> klass)Validates that the givenPageableis valid for querying entities of the givenklass.
-
-
-
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 aPredicaterepresenting a "like", which matches the givenattributeName(of theEntityTypegot by executingRoot.getModel()from the givenRoot) with the givenpattern.- Type Parameters:
T- The concrete type ofEntityTypeto which this predicate is applied.- Parameters:
cb- TheCriteriaBuilderused to build thePredicate.root- TheRootfrom where thePredicatewill be used.attributeName- The attribute name from the givenEntityTypeto matchpattern- The pattern to match.matchMode- TheMatchModeto 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.InvalidPropertiesExceptionValidates that the givenPageableis valid for querying entities of the givenklass.- Type Parameters:
T- The concrete type of the entities.- Parameters:
pageable- ThePageableto be validated.klass- The class representing the entity.- Throws:
com.bellotapps.webapps_commons.exceptions.InvalidPropertiesException- If it has aSortwith invalid properties.
-
-