Class PanacheQueryImpl<Entity>
- All Implemented Interfaces:
PanacheQuery<Entity>
- Direct Known Subclasses:
CustomCountPanacheQuery
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
PanacheQueryImpl
(CommonPanacheQueryImpl<Entity> delegate) (package private)
PanacheQueryImpl
(jakarta.persistence.EntityManager em, String query, String originalQuery, String orderBy, Object paramsArrayOrMap) -
Method Summary
Modifier and TypeMethodDescriptionlong
count()
Reads and caches the total number of entities this query operates on.<T extends Entity>
PanacheQuery<T>Enables a Hibernate filter during fetching of results for this query.<T extends Entity>
PanacheQuery<T>filter
(String filterName, Parameters parameters) Enables a Hibernate filter during fetching of results for this query.<T extends Entity>
PanacheQuery<T>Enables a Hibernate filter during fetching of results for this query.<T extends Entity>
PanacheQuery<T>Sets the current page to the first page<T extends Entity>
TReturns the first result of the current page index.Returns the first result of the current page index.boolean
Returns true if there is another page to read after the current one.boolean
Returns true if there is a page to read before the current one.<T extends Entity>
PanacheQuery<T>lastPage()
Sets the current page to the last page.list()
Returns the current page of results as aList
.<T extends Entity>
PanacheQuery<T>nextPage()
Sets the current page to the next pagepage()
Returns the current page.<T extends Entity>
PanacheQuery<T>page
(int pageIndex, int pageSize) Sets the current page.<T extends Entity>
PanacheQuery<T>Sets the current page.int
Returns the total number of pages to be read using the current page size.<T extends Entity>
PanacheQuery<T>Sets the current page to the previous page (or the first page if there is no previous page)<T> PanacheQuery<T>
Defines a projection class.<T extends Entity>
PanacheQuery<T>range
(int startIndex, int lastIndex) Switch the query to use a fixed range (start index - last index) instead of a page.<T extends Entity>
TExecutes this query for the current page and return a single result.Executes this query for the current page and return a single result.stream()
Returns the current page of results as aStream
.<T extends Entity>
PanacheQuery<T>Set a query property or hint on the underlying JPA Query.<T extends Entity>
PanacheQuery<T>withLock
(jakarta.persistence.LockModeType lockModeType) Define the locking strategy used for this query.
-
Constructor Details
-
PanacheQueryImpl
-
PanacheQueryImpl
-
-
Method Details
-
project
Description copied from interface:PanacheQuery
Defines a projection class. This will transform the returned values into instances of the given type using the following mapping rules:- If your query already selects some specific columns (starts with
select distinct? a, b, c…
) then we transform it into a query of the form:select distinct? new ProjectionClass(a, b, c)…
. There must be a matching constructor that accepts the selected column types, in the right order. - If your query does not select any specific column (starts with
from…
) then we transform it into a query of the form:select new ProjectionClass(a, b, c…) from…
where we fetch the list of selected columns from your projection class' single constructor, using its parameter names (or theirProjectedFieldName
annotations), in the same order as the constructor. - If this is already a project query of the form
select distinct? new…
, we throw aPanacheQueryException
- Specified by:
project
in interfacePanacheQuery<Entity>
- Parameters:
type
- the projected class type- Returns:
- a new query with the same state as the previous one (params, page, range, lockMode, hints, ...) but a projected
result of the type
type
- If your query already selects some specific columns (starts with
-
page
Description copied from interface:PanacheQuery
Sets the current page.- Specified by:
page
in interfacePanacheQuery<Entity>
- Parameters:
page
- the new page- Returns:
- this query, modified
- See Also:
-
page
Description copied from interface:PanacheQuery
Sets the current page.- Specified by:
page
in interfacePanacheQuery<Entity>
- Parameters:
pageIndex
- the page index (0-based)pageSize
- the page size- Returns:
- this query, modified
- See Also:
-
nextPage
Description copied from interface:PanacheQuery
Sets the current page to the next page- Specified by:
nextPage
in interfacePanacheQuery<Entity>
- Returns:
- this query, modified
- See Also:
-
previousPage
Description copied from interface:PanacheQuery
Sets the current page to the previous page (or the first page if there is no previous page)- Specified by:
previousPage
in interfacePanacheQuery<Entity>
- Returns:
- this query, modified
- See Also:
-
firstPage
Description copied from interface:PanacheQuery
Sets the current page to the first page- Specified by:
firstPage
in interfacePanacheQuery<Entity>
- Returns:
- this query, modified
- See Also:
-
lastPage
Description copied from interface:PanacheQuery
Sets the current page to the last page. This will cause reading of the entity count.- Specified by:
lastPage
in interfacePanacheQuery<Entity>
- Returns:
- this query, modified
- See Also:
-
hasNextPage
public boolean hasNextPage()Description copied from interface:PanacheQuery
Returns true if there is another page to read after the current one. This will cause reading of the entity count.- Specified by:
hasNextPage
in interfacePanacheQuery<Entity>
- Returns:
- true if there is another page to read
- See Also:
-
hasPreviousPage
public boolean hasPreviousPage()Description copied from interface:PanacheQuery
Returns true if there is a page to read before the current one.- Specified by:
hasPreviousPage
in interfacePanacheQuery<Entity>
- Returns:
- true if there is a previous page to read
- See Also:
-
pageCount
public int pageCount()Description copied from interface:PanacheQuery
Returns the total number of pages to be read using the current page size. This will cause reading of the entity count.- Specified by:
pageCount
in interfacePanacheQuery<Entity>
- Returns:
- the total number of pages to be read using the current page size.
-
page
Description copied from interface:PanacheQuery
Returns the current page.- Specified by:
page
in interfacePanacheQuery<Entity>
- Returns:
- the current page
- See Also:
-
range
Description copied from interface:PanacheQuery
Switch the query to use a fixed range (start index - last index) instead of a page. As the range is fixed, subsequent pagination of the query is not possible.- Specified by:
range
in interfacePanacheQuery<Entity>
- Parameters:
startIndex
- the index of the first element, starting at 0lastIndex
- the index of the last element- Returns:
- this query, modified
-
withLock
Description copied from interface:PanacheQuery
Define the locking strategy used for this query.- Specified by:
withLock
in interfacePanacheQuery<Entity>
- Parameters:
lockModeType
- the locking strategy to be used for this query.- Returns:
- this query, modified
-
withHint
Description copied from interface:PanacheQuery
Set a query property or hint on the underlying JPA Query.- Specified by:
withHint
in interfacePanacheQuery<Entity>
- Parameters:
hintName
- name of the property or hint.value
- value for the property or hint.- Returns:
- this query, modified
-
filter
Description copied from interface:PanacheQuery
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 withFilter
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.- Specified by:
filter
in interfacePanacheQuery<Entity>
- Parameters:
filterName
- The name of the filter to enableparameters
- The set of parameters for the filter, if the filter requires parameters- Returns:
- this query, modified
-
filter
Description copied from interface:PanacheQuery
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 withFilter
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.- Specified by:
filter
in interfacePanacheQuery<Entity>
- Parameters:
filterName
- The name of the filter to enableparameters
- The set of parameters for the filter, if the filter requires parameters- Returns:
- this query, modified
-
filter
Description copied from interface:PanacheQuery
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 withFilter
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.- Specified by:
filter
in interfacePanacheQuery<Entity>
- Parameters:
filterName
- The name of the filter to enable- Returns:
- this query, modified
-
count
public long count()Description copied from interface:PanacheQuery
Reads and caches the total number of entities this query operates on. This causes a database query withSELECT COUNT(*)
and a query equivalent to the current query, minus ordering.- Specified by:
count
in interfacePanacheQuery<Entity>
- Returns:
- the total number of entities this query operates on, cached.
-
list
Description copied from interface:PanacheQuery
Returns the current page of results as aList
.- Specified by:
list
in interfacePanacheQuery<Entity>
- Returns:
- the current page of results as a
List
. - See Also:
-
stream
Description copied from interface:PanacheQuery
Returns the current page of results as aStream
.- Specified by:
stream
in interfacePanacheQuery<Entity>
- Returns:
- the current page of results as a
Stream
. - See Also:
-
firstResult
Description copied from interface:PanacheQuery
Returns the first result of the current page index. This ignores the current page size to fetch a single result.- Specified by:
firstResult
in interfacePanacheQuery<Entity>
- Returns:
- the first result of the current page index, or null if there are no results.
- See Also:
-
firstResultOptional
Description copied from interface:PanacheQuery
Returns the first result of the current page index. This ignores the current page size to fetch a single result.- Specified by:
firstResultOptional
in interfacePanacheQuery<Entity>
- Returns:
- if found, an optional containing the entity, else
Optional.empty()
. - See Also:
-
singleResult
Description copied from interface:PanacheQuery
Executes this query for the current page and return a single result.- Specified by:
singleResult
in interfacePanacheQuery<Entity>
- Returns:
- the single result (throws if there is not exactly one)
- See Also:
-
singleResultOptional
Description copied from interface:PanacheQuery
Executes this query for the current page and return a single result.- Specified by:
singleResultOptional
in interfacePanacheQuery<Entity>
- Returns:
- if found, an optional containing the entity, else
Optional.empty()
. - See Also:
-