Class HqlAndParametersBuilder<E extends TopiaEntity>

java.lang.Object
org.nuiton.topia.persistence.HqlAndParametersBuilder<E>

public class HqlAndParametersBuilder<E extends TopiaEntity> extends Object
A builder to create syntactically correct HQL and associated parameters given properties or after various constraint adds. It may be used in a Dao to ease dynamic construction of queries.
Since:
3.0
  • Field Details

    • hqlClausesJoiner

      protected com.google.common.base.Joiner hqlClausesJoiner
    • entityClass

      protected Class<E extends TopiaEntity> entityClass
    • selectClause

      protected String selectClause
    • whereClauses

      protected Set<String> whereClauses
    • orderByArguments

      protected LinkedHashSet<String> orderByArguments
    • parameters

      protected Map<String,Object> parameters
    • fetchProperties

      protected Set<String> fetchProperties
  • Constructor Details

    • HqlAndParametersBuilder

      public HqlAndParametersBuilder(Class<E> entityClass)
    • HqlAndParametersBuilder

      public HqlAndParametersBuilder(Class<E> entityClass, String alias)
    • HqlAndParametersBuilder

      public HqlAndParametersBuilder(Class<E> entityClass, FilterRuleGroupOperator filterRuleGroupOperator)
    • HqlAndParametersBuilder

      public HqlAndParametersBuilder(Class<E> entityClass, String alias, FilterRuleGroupOperator filterRuleGroupOperator)
  • Method Details

    • getAlias

      public String getAlias()
    • getFilterRuleGroupOperator

      public FilterRuleGroupOperator getFilterRuleGroupOperator()
    • getHqlSelectClause

      public String getHqlSelectClause(boolean includeFetch)
    • setSelectClause

      public void setSelectClause(String selectClause)
    • addNull

      public void addNull(String property)
    • addNotNull

      public void addNotNull(String property)
    • addEquals

      public void addEquals(String property, Object value)
    • addNotEquals

      public void addNotEquals(String property, Object value)
    • addIn

      public void addIn(String property, Collection<?> values)
    • addNotIn

      public void addNotIn(String property, Collection<?> values)
    • addIn

      public <T extends Comparable<T>> void addIn(String property, org.apache.commons.lang3.Range<T> range)
    • addNotIn

      public <T extends Comparable<T>> void addNotIn(String property, org.apache.commons.lang3.Range<T> range)
    • addIn

      public <T extends Comparable<T>> void addIn(String property, org.apache.commons.lang3.Range<T> range, boolean in)
    • addIn

      public <T extends Comparable<T>> void addIn(String property, com.google.common.collect.Range<T> range)
    • addNotIn

      public <T extends Comparable<T>> void addNotIn(String property, com.google.common.collect.Range<T> range)
    • addIn

      public <T extends Comparable<T>> void addIn(String property, com.google.common.collect.Range<T> range, boolean in)
    • addInOrNotIn

      protected void addInOrNotIn(String property, Collection<?> values, boolean in)
      Parameters:
      property - FIXME
      values - FIXME
      in - true if property value must be in given collection, false if value must not be in given collection
    • addTopiaIdEquals

      public void addTopiaIdEquals(String property, String topiaId)
      Parameters:
      property - FIXME
      topiaId - FIXME
      See Also:
    • addTopiaIdIn

      public void addTopiaIdIn(String property, Collection<String> topiaIds)
      Parameters:
      property - FIXME
      topiaIds - FIXME
      See Also:
    • addTopiaIdNotEquals

      public void addTopiaIdNotEquals(String property, String topiaId)
      Parameters:
      property - FIXME
      topiaId - FIXME
      See Also:
    • addTopiaIdNotIn

      public void addTopiaIdNotIn(String property, Collection<String> topiaIds)
      Parameters:
      property - FIXME
      topiaIds - FIXME
      See Also:
    • addContains

      public void addContains(String property, Object value)
    • addNotContains

      public void addNotContains(String property, Object value)
    • addLike

      public void addLike(String property, String pattern)
    • addNotLike

      public void addNotLike(String property, String pattern)
    • addLowerThan

      public void addLowerThan(String property, Date date)
    • addLowerOrEquals

      public void addLowerOrEquals(String property, Date date)
    • addGreaterThan

      public void addGreaterThan(String property, Date date)
    • addGreaterOrEquals

      public void addGreaterOrEquals(String property, Date date)
    • addLowerThan

      public void addLowerThan(String property, Number number)
    • addLowerOrEquals

      public void addLowerOrEquals(String property, Number number)
    • addGreaterThan

      public void addGreaterThan(String property, Number number)
    • addGreaterOrEquals

      public void addGreaterOrEquals(String property, Number number)
    • addLowerThan

      public void addLowerThan(String property, String string)
    • addLowerOrEquals

      public void addLowerOrEquals(String property, String string)
    • addGreaterThan

      public void addGreaterThan(String property, String string)
    • addGreaterOrEquals

      public void addGreaterOrEquals(String property, String string)
    • addLowerThan

      public void addLowerThan(String property, LocalDate localDate)
    • addLowerOrEquals

      public void addLowerOrEquals(String property, LocalDate localDate)
    • addGreaterThan

      public void addGreaterThan(String property, LocalDate localDate)
    • addGreaterOrEquals

      public void addGreaterOrEquals(String property, LocalDate localDate)
    • addLowerThan

      public void addLowerThan(String property, LocalDateTime localDateTime)
    • addLowerOrEquals

      public void addLowerOrEquals(String property, LocalDateTime localDateTime)
    • addGreaterThan

      public void addGreaterThan(String property, LocalDateTime localDateTime)
    • addGreaterOrEquals

      public void addGreaterOrEquals(String property, LocalDateTime localDateTime)
    • doAddLowerThan

      protected void doAddLowerThan(String property, Object value)
    • doAddLowerOrEquals

      protected void doAddLowerOrEquals(String property, Object value)
    • doAddGreaterThan

      protected void doAddGreaterThan(String property, Object value)
    • doAddGreaterOrEquals

      protected void doAddGreaterOrEquals(String property, Object value)
    • addWhereClause

      public void addWhereClause(String whereClause)
    • addCollectionIsEmpty

      public void addCollectionIsEmpty(String property)
    • addCollectionIsNotEmpty

      public void addCollectionIsNotEmpty(String property)
    • addWhereClause

      public void addWhereClause(String whereClause, Map<String,Object> hqlParameters)
    • setWhereClauses

      public void setWhereClauses(Set<String> whereClauses)
    • getWhereClauses

      public Set<String> getWhereClauses()
    • setParameters

      public void setParameters(Map<String,Object> parameters)
    • setOrderByArguments

      public void setOrderByArguments(LinkedHashSet<String> orderByArguments)
    • setOrderByArguments

      public void setOrderByArguments(String... orderByArguments)
    • setOrderByArguments

      public void setOrderByArguments(Collection<org.nuiton.util.pagination.PaginationOrder> paginationOrders)
    • addAllFetches

      public void addAllFetches(Collection<String> properties)
    • addAllFetches

      public void addAllFetches(String property, String... otherProperties)
    • addFetch

      public void addFetch(String property)
    • hasFetchProperties

      public boolean hasFetchProperties()
    • getHqlFromClause

      protected String getHqlFromClause(boolean includeFetch)
    • getHqlWhereClause

      public String getHqlWhereClause()
    • getHqlOrderByClause

      public String getHqlOrderByClause()
    • getHql

      public String getHql()
    • getHqlForFetchStep1

      public String getHqlForFetchStep1()
    • getHqlForFetchStep2

      public String getHqlForFetchStep2()
    • getParameterName

      protected String getParameterName(String propertyName)
      Converts a (nested) property name to an HQL argument name. For example getParameterName("yearlyDeclaration.survey.topiaId") → "yearlyDeclarationSurveyTopiaId"
      Parameters:
      propertyName - the name of a property, can be a path to a nested property
      Returns:
      a string that can syntactically be used as an HQL parameter name, not prefixed by ':'
    • putHqlParameterWithAvailableName

      protected String putHqlParameterWithAvailableName(String propertyName, Object value)
      Add a parameter in the parameters map searching with the suitable parameter name in order to prevent conflicts.
      Parameters:
      propertyName - FIXME
      value - FIXME
      Returns:
      the found key where the parameter has been added, suitable to use in the where clause
    • getHqlParameters

      public Map<String,Object> getHqlParameters()
    • isOrderByClausePresent

      public boolean isOrderByClausePresent()
    • toString

      public String toString()
      Overrides:
      toString in class Object