T
- The query result typeX
- The concrete builder typepublic interface QueryBuilder<T,X extends QueryBuilder<T,X>> extends BaseQueryBuilder<T,X>
Modifier and Type | Method and Description |
---|---|
X |
fetch(String... paths)
Adds an implicit join fetch for every given path to the query.
|
X |
fetch(String path)
Adds an implicit join fetch to the query.
|
javax.persistence.TypedQuery<T> |
getQuery()
Returns the JPA typed query for the built query.
|
List<T> |
getResultList()
Execute the query and return the result as a type List.
|
T |
getSingleResult()
Execute the query expecting a single result.
|
X |
innerJoinFetch(String path,
String alias)
Like
join(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean) but with JoinType.INNER and fetch set to true. |
X |
innerJoinFetchDefault(String path,
String alias)
Like
joinDefault(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean) but with JoinType.INNER and fetch set to true. |
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.
|
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.
|
X |
leftJoinFetch(String path,
String alias)
Like
join(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean) but with JoinType.LEFT and fetch set to true. |
X |
leftJoinFetchDefault(String path,
String alias)
Like
joinDefault(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean) but with JoinType.LEFT and fetch set to true. |
PaginatedCriteriaBuilder<T> |
page(int firstResult,
int maxResults)
Paginates the results of this query.
|
PaginatedCriteriaBuilder<T> |
page(KeysetPage keysetPage,
int firstResult,
int maxResults)
Like
page(int, int) but additionally uses key set pagination when possible. |
PaginatedCriteriaBuilder<T> |
page(Object entityId,
int maxResults)
Paginates the results of this query and navigates to the page on which
the entity with the given entity id is located.
|
X |
rightJoinFetch(String path,
String alias)
Like
join(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean) but with JoinType.RIGHT and fetch set to true. |
X |
rightJoinFetchDefault(String path,
String alias)
Like
joinDefault(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean) but with JoinType.RIGHT and fetch set to true. |
QueryBuilder<T,?> |
select(String expression)
Adds a select clause with the given expression to the query.
|
QueryBuilder<T,?> |
select(String expression,
String alias)
Adds a select clause with the given expression and alias to the query.
|
CaseWhenStarterBuilder<? extends QueryBuilder<T,?>> |
selectCase()
Like
SelectBuilder.selectCase(java.lang.String) but without an alias. |
CaseWhenStarterBuilder<? extends QueryBuilder<T,?>> |
selectCase(String alias)
Starts a
CaseWhenBuilder with the given alias as select alias. |
<Y> SelectObjectBuilder<? extends QueryBuilder<Y,?>> |
selectNew(Class<Y> clazz)
Starts a
SelectObjectBuilder for the given class. |
<Y> SelectObjectBuilder<? extends QueryBuilder<Y,?>> |
selectNew(Constructor<Y> constructor)
Starts a
SelectObjectBuilder for the given constructor. |
<Y> QueryBuilder<Y,?> |
selectNew(ObjectBuilder<Y> builder)
Applies the given object builder to this query.
|
SimpleCaseWhenStarterBuilder<? extends QueryBuilder<T,?>> |
selectSimpleCase(String expression)
Like
SelectBuilder.selectSimpleCase(java.lang.String, java.lang.String) but without an alias. |
SimpleCaseWhenStarterBuilder<? extends QueryBuilder<T,?>> |
selectSimpleCase(String expression,
String alias)
Starts a
SimpleCaseWhenBuilder with the given alias as select alias. |
SubqueryInitiator<? extends QueryBuilder<T,?>> |
selectSubquery()
Like
SelectBuilder.selectSubquery(java.lang.String) but without an alias. |
SubqueryInitiator<? extends QueryBuilder<T,?>> |
selectSubquery(String alias)
Starts a
SubqueryInitiator for the select item with the given alias. |
SubqueryInitiator<? extends QueryBuilder<T,?>> |
selectSubquery(String subqueryAlias,
String expression)
Like
SelectBuilder.selectSubquery(java.lang.String,java.lang.String,java.lang.String) but without a select alias. |
SubqueryInitiator<? extends QueryBuilder<T,?>> |
selectSubquery(String subqueryAlias,
String expression,
String selectAlias)
Starts a
SubqueryInitiator for a new select item with the given select alias. |
afterKeyset, afterKeyset, afterKeyset, beforeKeyset, beforeKeyset, beforeKeyset, containsParameter, from, from, getMetamodel, getParameter, getParameters, getParameterValue, getQueryString, getResultType, innerJoin, innerJoinDefault, innerJoinDefaultOn, innerJoinOn, isParameterSet, join, joinDefault, joinDefaultOn, joinOn, leftJoin, leftJoinDefault, leftJoinDefaultOn, leftJoinOn, rightJoin, rightJoinDefault, rightJoinDefaultOn, rightJoinOn, setParameter, setParameter, setParameter
whereOr
where, whereCase, whereExists, whereNotExists, whereSimpleCase, whereSubquery, whereSubquery
orderBy, orderByAsc, orderByAsc, orderByDesc, orderByDesc
javax.persistence.TypedQuery<T> getQuery()
List<T> getResultList()
T getSingleResult()
PaginatedCriteriaBuilder<T> page(int firstResult, int maxResults)
Please note: The pagination only works on entity level and NOT on row level. This means that for queries which yield multiple result set rows per entity (i.e. rows with the same entity id), the multiple rows are treated as 1 page entry during the pagination process. Hence, the result size of such paginated queries might be greater than the specified page size.
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 this document.
Since the pagination works on entity id level, the results are implicitely grouped by id and distinct. Therefore calling distinct() or groupBy() on a PaginatedCriteriaBuilder is not allowed.
firstResult
- The position of the first result to retrieve, numbered from 0maxResults
- The maximum number of results to retrievePaginatedCriteriaBuilder<T> page(Object entityId, int maxResults)
page(int, int)
apply.
If the entity with the given entity id does not exist in the result list:
PaginatedCriteriaBuilder.getResultList()
will contain the first pagePagedList.getFirstResult()
will return -1
entityId
- The id of the entity which should be located on the pagemaxResults
- The maximum number of results to retrievePaginatedCriteriaBuilder<T> page(KeysetPage keysetPage, int firstResult, int maxResults)
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 a keyset should
be thrown away when the count of lower ranked items changes to make use of offset pagination again.
Key set pagination is possible if and only if the following conditions are met:
KeysetPage.getMaxResults()
and maxResults
evaluate to the same value ANDKeysetPage.getFirstResult()
- firstResult
is 0KeysetPage.getFirstResult()
- firstResult
is equal to the value of maxResults
keysetPage
- The key set from a previous result, may be nullfirstResult
- The position of the first result to retrieve, numbered from 0maxResults
- The maximum number of results to retrievePagedList.getKeysetPage()
X join(String path, String alias, JoinType type, boolean fetch)
path
- The path to joinalias
- The alias for the joined elementtype
- The join typefetch
- True if a join fetch should be addedX joinDefault(String path, String alias, JoinType type, boolean fetch)
path
- The path to joinalias
- The alias for the joined elementtype
- The join typefetch
- True if a join fetch should be addedX fetch(String path)
path
- The path to join fetchX fetch(String... paths)
paths
- The paths to join fetchX innerJoinFetch(String path, String alias)
join(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean)
but with JoinType.INNER
and fetch set to true.path
- The path to joinalias
- The alias for the joined elementX innerJoinFetchDefault(String path, String alias)
joinDefault(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean)
but with JoinType.INNER
and fetch set to true.path
- The path to joinalias
- The alias for the joined elementX leftJoinFetch(String path, String alias)
join(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean)
but with JoinType.LEFT
and fetch set to true.path
- The path to joinalias
- The alias for the joined elementX leftJoinFetchDefault(String path, String alias)
joinDefault(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean)
but with JoinType.LEFT
and fetch set to true.path
- The path to joinalias
- The alias for the joined elementX rightJoinFetch(String path, String alias)
join(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean)
but with JoinType.RIGHT
and fetch set to true.path
- The path to joinalias
- The alias for the joined elementX rightJoinFetchDefault(String path, String alias)
joinDefault(java.lang.String, java.lang.String, com.blazebit.persistence.JoinType, boolean)
but with JoinType.RIGHT
and fetch set to true.path
- The path to joinalias
- The alias for the joined element<Y> SelectObjectBuilder<? extends QueryBuilder<Y,?>> selectNew(Class<Y> clazz)
SelectObjectBuilder
for the given class. The types of the parameter arguments used in the SelectObjectBuilder
must match a constructor of the given class.Y
- The new query result type specified by the given classclazz
- The class which should be used for the select new select clause<Y> SelectObjectBuilder<? extends QueryBuilder<Y,?>> selectNew(Constructor<Y> constructor)
SelectObjectBuilder
for the given constructor. The types of the parameter arguments used in the SelectObjectBuilder
must match the given constructor.Y
- The new query result type specified by the given classconstructor
- The constructor which should be used for the select new select clause<Y> QueryBuilder<Y,?> selectNew(ObjectBuilder<Y> builder)
Y
- The new query result type specified by the given classbuilder
- The object builder which transforms the result set into objects of type Y
SimpleCaseWhenStarterBuilder<? extends QueryBuilder<T,?>> selectSimpleCase(String expression)
SelectBuilder
SelectBuilder.selectSimpleCase(java.lang.String, java.lang.String)
but without an alias.selectSimpleCase
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectSimpleCase
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
expression
- The case operandSimpleCaseWhenStarterBuilder<? extends QueryBuilder<T,?>> selectSimpleCase(String expression, String alias)
SelectBuilder
SimpleCaseWhenBuilder
with the given alias as select alias.
The expression is the case operand which will be compared to the when expressions defined in the subsequent SimpleCaseWhenBuilder.selectSimpleCase
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectSimpleCase
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
expression
- The case operandalias
- The select alias for the simple case when expressionCaseWhenStarterBuilder<? extends QueryBuilder<T,?>> selectCase()
SelectBuilder
SelectBuilder.selectCase(java.lang.String)
but without an alias.selectCase
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectCase
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
CaseWhenStarterBuilder<? extends QueryBuilder<T,?>> selectCase(String alias)
SelectBuilder
CaseWhenBuilder
with the given alias as select alias.selectCase
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectCase
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
alias
- The select alias for the case when expressionQueryBuilder<T,?> select(String expression)
SelectBuilder
select
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
select
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
expression
- The expression for the select clauseQueryBuilder<T,?> select(String expression, String alias)
SelectBuilder
select
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
select
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
expression
- The expression for the select clausealias
- The alias for the expressionSubqueryInitiator<? extends QueryBuilder<T,?>> selectSubquery()
SelectBuilder
SelectBuilder.selectSubquery(java.lang.String)
but without an alias.selectSubquery
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectSubquery
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
SubqueryInitiator<? extends QueryBuilder<T,?>> selectSubquery(String alias)
SelectBuilder
SubqueryInitiator
for the select item with the given alias.
When the builder finishes, the select item is added to the parent container represented by the type X
.selectSubquery
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectSubquery
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
alias
- The select alias for the subquerySubqueryInitiator<? extends QueryBuilder<T,?>> selectSubquery(String subqueryAlias, String expression, String selectAlias)
SelectBuilder
SubqueryInitiator
for a new select item with the given select alias.
All occurrences of
subqueryAlias
in expression
will be replaced by the subquery.
When the builder finishes, the select item is added to the parent container represented by the type X
.
selectSubquery
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectSubquery
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
subqueryAlias
- The alias for the subquery which will be replaced by the actual subqueryexpression
- The expression which will be added as select item.
This expression contains the subqueryAlias
to define the insertion points for the subquery.selectAlias
- The select alias for the expressionSubqueryInitiator<? extends QueryBuilder<T,?>> selectSubquery(String subqueryAlias, String expression)
SelectBuilder
SelectBuilder.selectSubquery(java.lang.String,java.lang.String,java.lang.String)
but without a select alias.selectSubquery
in interface BaseQueryBuilder<T,X extends QueryBuilder<T,X>>
selectSubquery
in interface SelectBuilder<T,X extends QueryBuilder<T,X>>
subqueryAlias
- The alias for the subquery which will be replaced by the actual subqueryexpression
- The expression which will be added as select itemCopyright © 2015 Blazebit. All Rights Reserved.