Interface FullQueryBuilder<T,​X extends FullQueryBuilder<T,​X>>

Type Parameters:
T - The query result type
X - The concrete builder type
All Superinterfaces:
BaseQueryBuilder<T,​X>, BaseWhereBuilder<X>, CommonQueryBuilder<X>, ConfigurationSource, CorrelationQueryBuilder<X>, FetchBuilder<X>, FromBaseBuilder<X>, FromBuilder<X>, FromProvider, KeysetQueryBuilder<X>, OrderByBuilder<X>, ParameterHolder<X>, Queryable<T,​X>, QueryBuilder<T,​X>, SelectBuilder<X>, ServiceProvider, WhereBuilder<X>, WindowContainerBuilder<X>
All Known Subinterfaces:
CriteriaBuilder<T>, PaginatedCriteriaBuilder<T>

public interface FullQueryBuilder<T,​X extends FullQueryBuilder<T,​X>>
extends QueryBuilder<T,​X>, FetchBuilder<X>
A base interface for builders that support normal query functionality. This interface is shared between the criteria builder and paginated criteria builder.
Since:
1.1.0
Author:
Christian Beikov
  • Method Details

    • copy

      <Y> FullQueryBuilder<Y,​?> copy​(Class<Y> resultClass)
      Copies this query builder into a new one, using it's projection as an overridable default.
      Type Parameters:
      Y - The type of the result class
      Parameters:
      resultClass - The result class of the query
      Returns:
      A new query builder
      Since:
      1.2.0
    • getCountQuery

      javax.persistence.TypedQuery<Long> getCountQuery()
      Returns a query that counts the results that would be produced if the current query was run.
      Returns:
      A query for determining the count of the result list represented by this query builder
      Since:
      1.2.0
    • getCountQueryString

      String getCountQueryString()
      Returns the query string that selects the count of elements.
      Returns:
      The query string
      Since:
      1.3.0
    • getCountQuery

      javax.persistence.TypedQuery<Long> getCountQuery​(long maximumCount)
      Returns a query that counts the results and counts up to the maximum value that is given that would be produced if the current query was run.
      Parameters:
      maximumCount - the maximum value up to which should be counted
      Returns:
      A query for determining the count of the result list represented by this query builder
      Since:
      1.5.0
    • getCountQueryString

      String getCountQueryString​(long maximumCount)
      Returns the query string that selects the count of elements and counts up to the maximum value that is given.
      Parameters:
      maximumCount - the maximum value up to which should be counted
      Returns:
      The query string
      Since:
      1.5.0
    • page

      PaginatedCriteriaBuilder<T> page​(int firstResult, int maxResults)
      Invokes pageBy(int, int, String, String...) with the identifiers of the query root entity.
      Parameters:
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      Returns:
      This query builder as paginated query builder
    • page

      @Deprecated PaginatedCriteriaBuilder<T> page​(Object entityId, int maxResults)
      Deprecated.
      This method causes a method resolution ambiguity. Use {pageAndNavigate(Object, int)} instead.
      Invokes pageByAndNavigate(Object, int, String, String...) with the identifiers of the query root entity.
      Parameters:
      entityId - The id of the entity which should be located on the page
      maxResults - The maximum number of results to retrieve
      Returns:
      This query builder as paginated query builder
    • pageAndNavigate

      PaginatedCriteriaBuilder<T> pageAndNavigate​(Object entityId, int maxResults)
      Invokes pageByAndNavigate(Object, int, String, String...) with the identifiers of the query root entity.
      Parameters:
      entityId - The id of the entity which should be located on the page
      maxResults - The maximum number of results to retrieve
      Returns:
      This query builder as paginated query builder
      Since:
      1.3.0
    • page

      PaginatedCriteriaBuilder<T> page​(KeysetPage keysetPage, int firstResult, int maxResults)
      Invokes pageBy(KeysetPage, int, int, String, String...) with the identifiers of the query root entity.
      Parameters:
      keysetPage - The key set from a previous result, may be null
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      Returns:
      This query builder as paginated query builder
      See Also:
      PagedList.getKeysetPage()
    • pageBy

      PaginatedCriteriaBuilder<T> pageBy​(int firstResult, int maxResults, String identifierExpression)
      Like pageBy(int, int, String, String...) but lacks the varargs parameter to avoid heap pollution.
      Parameters:
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      Returns:
      This query builder as paginated query builder
      Since:
      1.3.0
    • pageByAndNavigate

      PaginatedCriteriaBuilder<T> pageByAndNavigate​(Object entityId, int maxResults, String identifierExpression)
      Like pageByAndNavigate(Object, int, String, String...) but lacks the varargs parameter to avoid heap pollution.
      Parameters:
      entityId - The id of the entity which should be located on the page
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      Returns:
      This query builder as paginated query builder
      Since:
      1.3.0
    • pageBy

      PaginatedCriteriaBuilder<T> pageBy​(KeysetPage keysetPage, int firstResult, int maxResults, String identifierExpression)
      Like pageBy(KeysetPage, int, int, String, String...) but lacks the varargs parameter to avoid heap pollution.
      Parameters:
      keysetPage - The key set from a previous result, may be null
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      Returns:
      This query builder as paginated query builder
      Since:
      1.3.0
      See Also:
      PagedList.getKeysetPage()
    • pageBy

      PaginatedCriteriaBuilder<T> pageBy​(int firstResult, int maxResults, String identifierExpression, String... identifierExpressions)
      Paginates the results of this query based on the given identifier expressions. In JPA, the use of setFirstResult and setMaxResults is not defined when involving fetch joins for collections. When no collection joins are involved, this is fine as rows essentially represent objects, but when collections are joined, this is no longer true. JPA providers usually fall back to querying all data and doing pagination in-memory based on objects or simply don't support that kind of query. This API allows to specify the identifier expressions to use for pagination and transparently handles collection join support. The big advantage of this API over plain setFirstResult and setMaxResults can also be seen when doing scalar queries.

      An example for such queries would be a query that joins a collection: SELECT d.id, contacts.name FROM Document d LEFT JOIN d.contacts contacts If one Document has associated multiple contacts, the above query will produce multiple result set rows for that document. Paginating via setFirstResult and setMaxResults would produce unexpected results whereas using this API, will produce the expected results.

      When paginating on the identifier i.e. d.id, the results are implicitly grouped by the document id and distinct. Therefore calling distinct() on a PaginatedCriteriaBuilder is not allowed.

      Parameters:
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      identifierExpressions - The other identifier expressions
      Returns:
      This query builder as paginated query builder
      Since:
      1.3.0
    • pageByAndNavigate

      PaginatedCriteriaBuilder<T> pageByAndNavigate​(Object entityId, int maxResults, String identifierExpression, String... identifierExpressions)
      Paginates the results of this query and navigates to the page on which the object with the given identifier is located. Beware that the same limitations like for page(int, int) apply. If the object with the given identifier does not exist in the result list:
      Parameters:
      entityId - The id of the object which should be located on the page
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      identifierExpressions - The other identifier expressions
      Returns:
      This query builder as paginated query builder
      Since:
      1.3.0
    • pageBy

      PaginatedCriteriaBuilder<T> pageBy​(KeysetPage keysetPage, int firstResult, int maxResults, String identifierExpression, String... identifierExpressions)
      Like page(int, int) but additionally uses key set pagination when possible. Beware that keyset pagination should not be used as a direct replacement for offset pagination. Since entries that have a lower rank than some keyset might be added or removed, the calculations for the firstResult might be wrong. If strict pagination is required, then the KeysetPage should not be used when the count of lower ranked items changes which will result in the use of offset pagination for that request.

      Key set pagination is possible if and only if the following conditions are met:

      Parameters:
      keysetPage - The key set from a previous result, may be null
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      identifierExpressions - The other identifier expressions
      Returns:
      This query builder as paginated query builder
      Since:
      1.3.0
      See Also:
      PagedList.getKeysetPage()
    • createPageIdQuery

      CriteriaBuilder<Object[]> createPageIdQuery​(int firstResult, int maxResults, String identifierExpression)
      Parameters:
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      Returns:
      the CriteriaBuilder to query id values
      Since:
      1.4.1
    • createPageIdQuery

      CriteriaBuilder<Object[]> createPageIdQuery​(KeysetPage keysetPage, int firstResult, int maxResults, String identifierExpression)
      Parameters:
      keysetPage - The key set from a previous result, may be null
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      Returns:
      the CriteriaBuilder to query id values
      Since:
      1.4.1
    • createPageIdQuery

      CriteriaBuilder<Object[]> createPageIdQuery​(int firstResult, int maxResults, String identifierExpression, String... identifierExpressions)
      Parameters:
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      identifierExpressions - The other identifier expressions
      Returns:
      the CriteriaBuilder to query id values
      Since:
      1.4.1
    • createPageIdQuery

      CriteriaBuilder<Object[]> createPageIdQuery​(KeysetPage keysetPage, int firstResult, int maxResults, String identifierExpression, String... identifierExpressions)
      Parameters:
      keysetPage - The key set from a previous result, may be null
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      identifierExpression - The first identifier expression
      identifierExpressions - The other identifier expressions
      Returns:
      the CriteriaBuilder to query id values
      Since:
      1.4.1
    • join

      X join​(String path, String alias, JoinType type, boolean fetch)
      Adds a join to the query, possibly specializing implicit joins, and giving the joined element an alias. If fetch is set to true, a join fetch will be added.
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      type - The join type
      fetch - True if a join fetch should be added
      Returns:
      The query builder for chaining calls
    • joinDefault

      X joinDefault​(String path, String alias, JoinType type, boolean fetch)
      Adds a join to the query, possibly specializing implicit joins, and giving the joined element an alias. The resulting join will be the default join meaning that expressions which use the absolute path will refer to this join. If fetch is set to true, a join fetch will be added.
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      type - The join type
      fetch - True if a join fetch should be added
      Returns:
      The query builder for chaining calls
    • innerJoinFetch

      X innerJoinFetch​(String path, String alias)
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      Returns:
      The query builder for chaining calls
    • innerJoinFetchDefault

      X innerJoinFetchDefault​(String path, String alias)
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      Returns:
      The query builder for chaining calls
    • leftJoinFetch

      X leftJoinFetch​(String path, String alias)
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      Returns:
      The query builder for chaining calls
    • leftJoinFetchDefault

      X leftJoinFetchDefault​(String path, String alias)
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      Returns:
      The query builder for chaining calls
    • rightJoinFetch

      X rightJoinFetch​(String path, String alias)
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      Returns:
      The query builder for chaining calls
    • rightJoinFetchDefault

      X rightJoinFetchDefault​(String path, String alias)
      Parameters:
      path - The path to join
      alias - The alias for the joined element
      Returns:
      The query builder for chaining calls
    • selectNew

      <Y> SelectObjectBuilder<? extends FullQueryBuilder<Y,​?>> selectNew​(Class<Y> clazz)
      Starts a SelectObjectBuilder for the given class. The types of the parameter arguments used in the SelectObjectBuilder must match a constructor of the given class.
      Type Parameters:
      Y - The new query result type specified by the given class
      Parameters:
      clazz - The class which should be used for the select new select clause
      Returns:
      The select object builder for the given class
    • selectNew

      <Y> SelectObjectBuilder<? extends FullQueryBuilder<Y,​?>> selectNew​(Constructor<Y> constructor)
      Starts a SelectObjectBuilder for the given constructor. The types of the parameter arguments used in the SelectObjectBuilder must match the given constructor.
      Type Parameters:
      Y - The new query result type specified by the given class
      Parameters:
      constructor - The constructor which should be used for the select new select clause
      Returns:
      The select object builder for the given class
    • selectNew

      <Y> FullQueryBuilder<Y,​?> selectNew​(ObjectBuilder<Y> builder)
      Applies the given object builder to this query. The object builder provides the select clauses and is used to transform the result set tuples.
      Type Parameters:
      Y - The new query result type specified by the given class
      Parameters:
      builder - The object builder which transforms the result set into objects of type Y
      Returns:
      The query builder for chaining calls