Class QueryHelper

  • Direct Known Subclasses:
    QueryUtil

    public class QueryHelper
    extends Object
    Class with utility methods for dealing with queries. Either extend this class or use QueryUtil.get().
    Since:
    3.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static String QUERY_PROPERTY_TIMEOUT
      JPA query property to configure the timeout in milliseconds.
    • Constructor Summary

      Constructors 
      Constructor Description
      QueryHelper()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void applySort​(com.querydsl.jpa.impl.JPAQuery<?> query, org.springframework.data.domain.Sort sort)  
      protected void applyTimeout​(com.querydsl.jpa.impl.JPAQuery<?> query, Number timeout)  
      protected <E> org.springframework.data.domain.Page<E> findPaginatedGeneric​(org.springframework.data.domain.Pageable pageable, com.querydsl.jpa.impl.JPAQuery<E> query, boolean determineTotal)
      Returns a Page of entities according to the supplied Pageable and JPAQuery.
      protected <T> com.querydsl.core.types.dsl.BooleanExpression newInClause​(com.querydsl.core.types.dsl.SimpleExpression<T> expression, Collection<T> inValues)  
      protected com.querydsl.core.types.dsl.BooleanExpression newLikeClause​(com.querydsl.core.types.dsl.StringExpression expression, String pattern, LikePatternSyntax syntax, boolean ignoreCase, boolean matchSubstring)  
      protected com.querydsl.core.types.dsl.BooleanExpression newLikeClause​(com.querydsl.core.types.dsl.StringExpression expression, String pattern, LikePatternSyntax syntax, boolean ignoreCase, boolean matchSubstring, boolean negate)  
      protected com.querydsl.core.types.dsl.BooleanExpression newNotLikeClause​(com.querydsl.core.types.dsl.StringExpression expression, String pattern, LikePatternSyntax syntax, boolean ignoreCase, boolean matchSubstring)  
      protected com.querydsl.core.types.dsl.BooleanExpression newStringClause​(com.querydsl.core.types.dsl.StringExpression expression, String value, StringSearchConfigTo config)  
      protected com.querydsl.core.types.dsl.BooleanExpression newStringClause​(com.querydsl.core.types.dsl.StringExpression expression, String value, StringSearchOperator operator, LikePatternSyntax syntax, boolean ignoreCase, boolean matchSubstring)  
      protected <T> void whereIn​(com.querydsl.jpa.impl.JPAQuery<?> query, com.querydsl.core.types.dsl.SimpleExpression<T> expression, Collection<T> inValues)  
      protected void whereLike​(com.querydsl.jpa.impl.JPAQuery<?> query, com.querydsl.core.types.dsl.StringExpression expression, String pattern, LikePatternSyntax syntax, boolean ignoreCase, boolean matchSubstring)  
      protected void whereNotLike​(com.querydsl.jpa.impl.JPAQuery<?> query, com.querydsl.core.types.dsl.StringExpression expression, String pattern, LikePatternSyntax syntax, boolean ignoreCase, boolean matchSubstring)  
      protected void whereString​(com.querydsl.jpa.impl.JPAQuery<?> query, com.querydsl.core.types.dsl.StringExpression expression, String value, StringSearchConfigTo config)  
    • Field Detail

      • QUERY_PROPERTY_TIMEOUT

        protected static final String QUERY_PROPERTY_TIMEOUT
        JPA query property to configure the timeout in milliseconds.
        See Also:
        Constant Field Values
    • Constructor Detail

      • QueryHelper

        public QueryHelper()
    • Method Detail

      • applyTimeout

        protected void applyTimeout​(com.querydsl.jpa.impl.JPAQuery<?> query,
                                    Number timeout)
        Parameters:
        query - the JPAQuery to modify.
        timeout - the timeout in milliseconds.
      • whereLike

        protected void whereLike​(com.querydsl.jpa.impl.JPAQuery<?> query,
                                 com.querydsl.core.types.dsl.StringExpression expression,
                                 String pattern,
                                 LikePatternSyntax syntax,
                                 boolean ignoreCase,
                                 boolean matchSubstring)
        Parameters:
        query - the JPAQuery to modify.
        expression - the StringExpression to create the LIKE-clause from.
        pattern - the pattern for the LIKE-clause to create.
        syntax - the LikePatternSyntax of the given pattern.
        ignoreCase - - true to ignore the case, false otherwise (to search case-sensitive).
        matchSubstring - - true to match also if the given pattern shall also match substrings on the given StringExpression.
      • whereNotLike

        protected void whereNotLike​(com.querydsl.jpa.impl.JPAQuery<?> query,
                                    com.querydsl.core.types.dsl.StringExpression expression,
                                    String pattern,
                                    LikePatternSyntax syntax,
                                    boolean ignoreCase,
                                    boolean matchSubstring)
        Parameters:
        query - the JPAQuery to modify.
        expression - the StringExpression to create the NOT LIKE-clause from.
        pattern - the pattern for the NOT LIKE-clause to create.
        syntax - the LikePatternSyntax of the given pattern.
        ignoreCase - - true to ignore the case, false otherwise (to search case-sensitive).
        matchSubstring - - true to match also if the given pattern shall also match substrings on the given StringExpression.
      • newLikeClause

        protected com.querydsl.core.types.dsl.BooleanExpression newLikeClause​(com.querydsl.core.types.dsl.StringExpression expression,
                                                                              String pattern,
                                                                              LikePatternSyntax syntax,
                                                                              boolean ignoreCase,
                                                                              boolean matchSubstring)
        Parameters:
        expression - the StringExpression to create the LIKE-clause from.
        pattern - the pattern for the LIKE-clause to create.
        syntax - the LikePatternSyntax of the given pattern.
        ignoreCase - - true to ignore the case, false otherwise (to search case-sensitive).
        matchSubstring - - true to match also if the given pattern shall also match substrings on the given StringExpression.
        Returns:
        the LIKE-clause as BooleanExpression.
      • newNotLikeClause

        protected com.querydsl.core.types.dsl.BooleanExpression newNotLikeClause​(com.querydsl.core.types.dsl.StringExpression expression,
                                                                                 String pattern,
                                                                                 LikePatternSyntax syntax,
                                                                                 boolean ignoreCase,
                                                                                 boolean matchSubstring)
        Parameters:
        expression - the StringExpression to create the NOT LIKE-clause from.
        pattern - the pattern for the NOT LIKE-clause to create.
        syntax - the LikePatternSyntax of the given pattern.
        ignoreCase - - true to ignore the case, false otherwise (to search case-sensitive).
        matchSubstring - - true to match also if the given pattern shall also match substrings on the given StringExpression.
        Returns:
        the NOT LIKE-clause as BooleanExpression.
      • newLikeClause

        protected com.querydsl.core.types.dsl.BooleanExpression newLikeClause​(com.querydsl.core.types.dsl.StringExpression expression,
                                                                              String pattern,
                                                                              LikePatternSyntax syntax,
                                                                              boolean ignoreCase,
                                                                              boolean matchSubstring,
                                                                              boolean negate)
        Parameters:
        expression - the StringExpression to create the LIKE-clause from.
        pattern - the pattern for the LIKE-clause to create.
        syntax - the LikePatternSyntax of the given pattern.
        ignoreCase - - true to ignore the case, false otherwise (to search case-sensitive).
        matchSubstring - - true to match also if the given pattern shall also match substrings on the given StringExpression.
        negate - - true for NOT LIKE, false for LIKE.
        Returns:
        the LIKE-clause as BooleanExpression.
      • newStringClause

        protected com.querydsl.core.types.dsl.BooleanExpression newStringClause​(com.querydsl.core.types.dsl.StringExpression expression,
                                                                                String value,
                                                                                StringSearchConfigTo config)
        Parameters:
        expression - the StringExpression to search on.
        value - the string value or pattern to search for.
        config - the StringSearchConfigTo to configure the search. May be null for regular equals search as default fallback.
        Returns:
        the new BooleanExpression for the specified string comparison clause.
      • newStringClause

        protected com.querydsl.core.types.dsl.BooleanExpression newStringClause​(com.querydsl.core.types.dsl.StringExpression expression,
                                                                                String value,
                                                                                StringSearchOperator operator,
                                                                                LikePatternSyntax syntax,
                                                                                boolean ignoreCase,
                                                                                boolean matchSubstring)
        Parameters:
        expression - the StringExpression to search on.
        value - the string value or pattern to search for.
        syntax - the LikePatternSyntax of the given pattern.
        operator - the StringSearchOperator used to compare the search string value.
        ignoreCase - - true to ignore the case, false otherwise (to search case-sensitive).
        matchSubstring - - true to match also if the given pattern shall also match substrings on the given StringExpression.
        Returns:
        the new BooleanExpression for the specified string comparison clause.
      • whereString

        protected void whereString​(com.querydsl.jpa.impl.JPAQuery<?> query,
                                   com.querydsl.core.types.dsl.StringExpression expression,
                                   String value,
                                   StringSearchConfigTo config)
        Parameters:
        query - the JPAQuery to modify.
        expression - the StringExpression to search on.
        value - the string value or pattern to search for.
        config - the StringSearchConfigTo to configure the search. May be null for regular equals search.
      • newInClause

        protected <T> com.querydsl.core.types.dsl.BooleanExpression newInClause​(com.querydsl.core.types.dsl.SimpleExpression<T> expression,
                                                                                Collection<T> inValues)
        Type Parameters:
        T - generic type of the Collection values for the IN-clause(s).
        Parameters:
        expression - the SimpleExpression used to create the IN-clause(s).
        inValues - the Collection of values for the IN-clause(s).
        Returns:
        the BooleanExpression for the IN-clause(s) oder null if inValues is null or empty.
      • whereIn

        protected <T> void whereIn​(com.querydsl.jpa.impl.JPAQuery<?> query,
                                   com.querydsl.core.types.dsl.SimpleExpression<T> expression,
                                   Collection<T> inValues)
        Type Parameters:
        T - generic type of the Collection values for the IN-clause(s).
        Parameters:
        query - the JPAQuery where to add the IN-clause(s) from the other given parameters.
        expression - the SimpleExpression used to create the IN-clause(s).
        inValues - the Collection of values for the IN-clause(s).
        See Also:
        newInClause(SimpleExpression, Collection)
      • findPaginatedGeneric

        protected <E> org.springframework.data.domain.Page<E> findPaginatedGeneric​(org.springframework.data.domain.Pageable pageable,
                                                                                   com.querydsl.jpa.impl.JPAQuery<E> query,
                                                                                   boolean determineTotal)
        Returns a Page of entities according to the supplied Pageable and JPAQuery.
        Type Parameters:
        E - generic type of the entity.
        Parameters:
        pageable - contains information about the requested page and sorting.
        query - is a query which is pre-configured with the desired conditions for the search.
        determineTotal - - true to determine the total number of hits, false otherwise.
        Returns:
        a paginated list.
      • applySort

        protected void applySort​(com.querydsl.jpa.impl.JPAQuery<?> query,
                                 org.springframework.data.domain.Sort sort)
        Parameters:
        query - the JPAQuery to apply the Sort to.
        sort - the Sort to apply as ORDER BY to the given JPAQuery.