Class QueryBuilder


  • public class QueryBuilder
    extends Object
    A class for incrementally building a HQL query.
    • Constructor Detail

      • QueryBuilder

        public QueryBuilder​(String entityName,
                            String alias,
                            SessionFactoryImplementor sessionFactory)
        Parameters:
        entityName - Main entity which should be selected.
        alias - Alias of the entity
        sessionFactory - Session factory
    • Method Detail

      • getAlias

        public String getAlias()
        Returns:
        the main alias of this query builder
      • addFrom

        public void addFrom​(String entityName,
                            String alias,
                            boolean select)
        Add an entity from which to select.
        Parameters:
        entityName - Name of the entity from which to select.
        alias - Alias of the entity. Should be different than all other aliases.
        select - whether the entity should be selected
      • generateAlias

        public String generateAlias()
      • newSubQueryBuilder

        public QueryBuilder newSubQueryBuilder​(String entityName,
                                               String alias)
        Parameters:
        entityName - Entity name, which will be the main entity for the sub-query.
        alias - Alias of the entity, which can later be used in parameters.
        Returns:
        A sub-query builder for the given entity, with the given alias. The sub-query can be later used as a value of a parameter.
      • getRootParameters

        public Parameters getRootParameters()
      • addOrderFragment

        public void addOrderFragment​(String alias,
                                     String orderByCollectionRole)
      • addProjection

        public void addProjection​(String function,
                                  String alias,
                                  String propertyName,
                                  boolean distinct)
      • build

        public void build​(StringBuilder sb,
                          Map<String,​Object> queryParamValues)
        Builds the given query, appending results to the given string buffer, and adding all query parameter values that are used to the map provided.
        Parameters:
        sb - String builder to which the query will be appended.
        queryParamValues - Map to which name and values of parameters used in the query should be added.
      • getRootAlias

        public String getRootAlias()