Entity
- The entity type being queriedpublic interface PanacheQuery<Entity>
Interface representing an entity query, which abstracts the use of paging, getting the number of results, and
operating on List
or Stream
.
Instances of this interface cannot mutate the query itself or its parameters: only paging information can be modified, and instances of this interface can be reused to obtain multiple pages of results.
Modifier and Type | Method and Description |
---|---|
long |
count()
Reads and caches the total number of entities this query operates on.
|
<T extends Entity> |
filter(String filterName)
Enables a Hibernate filter during fetching of results for this query.
|
<T extends Entity> |
filter(String filterName,
Map<String,Object> parameters)
Enables a Hibernate filter during fetching of results for this query.
|
<T extends Entity> |
filter(String filterName,
Parameters parameters)
Enables a Hibernate filter during fetching of results for this query.
|
<T extends Entity> |
firstPage()
Sets the current page to the first page
|
<T extends Entity> |
firstResult()
Returns the first result of the current page index.
|
<T extends Entity> |
firstResultOptional()
Returns the first result of the current page index.
|
boolean |
hasNextPage()
Returns true if there is another page to read after the current one.
|
boolean |
hasPreviousPage()
Returns true if there is a page to read before the current one.
|
<T extends Entity> |
lastPage()
Sets the current page to the last page.
|
<T extends Entity> |
list()
Returns the current page of results as a
List . |
<T extends Entity> |
nextPage()
Sets the current page to the next page
|
Page |
page()
Returns the current page.
|
<T extends Entity> |
page(int pageIndex,
int pageSize)
Sets the current page.
|
<T extends Entity> |
page(Page page)
Sets the current page.
|
int |
pageCount()
Returns the total number of pages to be read using the current page size.
|
<T extends Entity> |
previousPage()
Sets the current page to the previous page (or the first page if there is no previous page)
|
<T> PanacheQuery<T> |
project(Class<T> type)
Defines a projection class: the getters, and the public fields, will be used to restrict which fields should be
retrieved from the database.
|
<T extends Entity> |
range(int startIndex,
int lastIndex)
Switch the query to use a fixed range (start index - last index) instead of a page.
|
<T extends Entity> |
singleResult()
Executes this query for the current page and return a single result.
|
<T extends Entity> |
singleResultOptional()
Executes this query for the current page and return a single result.
|
<T extends Entity> |
stream()
Returns the current page of results as a
Stream . |
<T extends Entity> |
withHint(String hintName,
Object value)
Set a query property or hint on the underlying JPA Query.
|
<T extends Entity> |
withLock(javax.persistence.LockModeType lockModeType)
Define the locking strategy used for this query.
|
<T> PanacheQuery<T> project(Class<T> type)
<T extends Entity> PanacheQuery<T> page(Page page)
page
- the new pagepage(int, int)
,
page()
<T extends Entity> PanacheQuery<T> page(int pageIndex, int pageSize)
pageIndex
- the page indexpageSize
- the page sizepage(Page)
,
page()
<T extends Entity> PanacheQuery<T> nextPage()
UnsupportedOperationException
- if a page hasn't been set or if a range is already setpreviousPage()
<T extends Entity> PanacheQuery<T> previousPage()
UnsupportedOperationException
- if a page hasn't been set or if a range is already setnextPage()
<T extends Entity> PanacheQuery<T> firstPage()
UnsupportedOperationException
- if a page hasn't been set or if a range is already setlastPage()
<T extends Entity> PanacheQuery<T> lastPage()
UnsupportedOperationException
- if a page hasn't been set or if a range is already setfirstPage()
,
count()
boolean hasNextPage()
UnsupportedOperationException
- if a page hasn't been set or if a range is already sethasPreviousPage()
,
count()
boolean hasPreviousPage()
UnsupportedOperationException
- if a page hasn't been set or if a range is already sethasNextPage()
int pageCount()
UnsupportedOperationException
- if a page hasn't been set or if a range is already setPage page()
UnsupportedOperationException
- if a page hasn't been set or if a range is already setpage(Page)
,
page(int,int)
<T extends Entity> PanacheQuery<T> range(int startIndex, int lastIndex)
startIndex
- the index of the first element, starting at 0lastIndex
- the index of the last element<T extends Entity> PanacheQuery<T> withLock(javax.persistence.LockModeType lockModeType)
lockModeType
- the locking strategy to be used for this query.<T extends Entity> PanacheQuery<T> withHint(String hintName, Object value)
hintName
- name of the property or hint.value
- value for the property or hint.<T extends Entity> PanacheQuery<T> filter(String filterName, Parameters parameters)
Enables a Hibernate filter during fetching of results for this query. Your filter must be declared
with FilterDef
on your entity or package, and enabled with Filter
on your entity.
WARNING: setting filters can only be done on the underlying Hibernate Session
and so this
will modify the session's filters for the duration of obtaining the results (not while building
the query). Enabled filters will be removed from the session afterwards, but no effort is made to
preserve filters enabled on the session outside of this API.
filterName
- The name of the filter to enableparameters
- The set of parameters for the filter, if the filter requires parameters<T extends Entity> PanacheQuery<T> filter(String filterName, Map<String,Object> parameters)
Enables a Hibernate filter during fetching of results for this query. Your filter must be declared
with FilterDef
on your entity or package, and enabled with Filter
on your entity.
WARNING: setting filters can only be done on the underlying Hibernate Session
and so this
will modify the session's filters for the duration of obtaining the results (not while building
the query). Enabled filters will be removed from the session afterwards, but no effort is made to
preserve filters enabled on the session outside of this API.
filterName
- The name of the filter to enableparameters
- The set of parameters for the filter, if the filter requires parameters<T extends Entity> PanacheQuery<T> filter(String filterName)
Enables a Hibernate filter during fetching of results for this query. Your filter must be declared
with FilterDef
on your entity or package, and enabled with Filter
on your entity.
WARNING: setting filters can only be done on the underlying Hibernate Session
and so this
will modify the session's filters for the duration of obtaining the results (not while building
the query). Enabled filters will be removed from the session afterwards, but no effort is made to
preserve filters enabled on the session outside of this API.
filterName
- The name of the filter to enablelong count()
SELECT COUNT(*)
and a query equivalent to the current query, minus
ordering.<T extends Entity> List<T> list()
List
.List
.stream()
,
page(Page)
,
page()
<T extends Entity> Stream<T> stream()
Stream
.Stream
.list()
,
page(Page)
,
page()
<T extends Entity> T firstResult()
singleResult()
<T extends Entity> Optional<T> firstResultOptional()
Optional.empty()
.singleResultOptional()
<T extends Entity> T singleResult()
javax.persistence.NoResultException
- if there is no resultjavax.persistence.NonUniqueResultException
- if there are more than one resultfirstResult()
<T extends Entity> Optional<T> singleResultOptional()
Optional.empty()
.javax.persistence.NonUniqueResultException
- if there are more than one resultfirstResultOptional()
Copyright © 2020 JBoss by Red Hat. All rights reserved.