Interface SearchValue<X,S extends Selection<X>>
- All Superinterfaces:
QueryConfigurer<AbstractQuery<?>,
,X, S> QueryStream<X,
,S, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> SearchStream<X,
S>
- All Known Subinterfaces:
BooleanValue
,DoubleValue
,ExprValue<X,
,S> FromValue<X,
,S> IntValue
,LongValue
,PathValue<X,
,S> RootValue<X>
SearchStream
that is guaranteed to return at most a single result.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.dellroad.querystream.jpa.QueryStream
QueryStream.Builder
-
Method Summary
Modifier and TypeMethodDescriptionBind an unbound reference to the items in this stream.<X2,
S2 extends Selection<X2>>
SearchValue<X,S> Bind an unbound reference to the result of applying the given function to the items in this stream.filter
(SingularAttribute<? super X, Boolean> attribute) Filter results using the specified boolean property.filter
(Function<? super S, ? extends Expression<Boolean>> predicateBuilder) Filter results using the boolean expression produced by the given function.default void
Build and evaluate a JPA query based on this instance and give the returned value, if any, to the givenConsumer
.default boolean
Build and evaluate a JPA query based on this instance and return true if a result is returned, otherwise false.default <Y> SearchValue<Y,
Selection<Y>> mapToSelection
(Class<Y> type, Function<? super S, ? extends Selection<Y>> selectionFunction) Map this stream into a stream whose elements are the result of applying the given function.default X
Build and evaluate a JPA query based on this instance and return the single result, if any, otherwise the given value.default X
Build and evaluate a JPA query based on this instance and return the single result, if any, otherwise the value from the givenSupplier
.orElseThrow
(Supplier<? extends T> supplier) Build and evaluate a JPA query based on this instance and return the single result, if any, otherwise throw an exception provided by the givenSupplier
.Peek at the items in this stream.Build and evaluate a JPA query based on this instance and return the single result, if any, as anOptional
.default X
value()
Build and evaluate a JPA query based on this instance and return the single result, if any.withFetchGraph
(String name) Configure a fetch graph for this query.withFlushMode
(FlushModeType flushMode) Set theFlushModeType
associated with this query.Associate a hint with this query.Associate hints with this query.withLoadGraph
(String name) Configure a load graph for this query.withLockMode
(LockModeType lockMode) Set theLockModeType
associated with this query.withParam
(Parameter<Calendar> parameter, Calendar value, TemporalType temporalType) Bind the value of a query parameter of typeCalendar
.withParam
(Parameter<Date> parameter, Date value, TemporalType temporalType) Bind the value of a query parameter of typeDate
.<T> SearchValue<X,
S> Bind the value of a query parameter.withParams
(Iterable<? extends ParamBinding<?>> params) Associate parameter bindings with this query.Methods inherited from interface org.dellroad.querystream.jpa.QueryConfigurer
configure
Methods inherited from interface org.dellroad.querystream.jpa.QueryStream
getEntityManager, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParams, toCriteriaQuery, toQuery
Methods inherited from interface org.dellroad.querystream.jpa.SearchStream
addRoot, allMatch, allMatch, anyMatch, anyMatch, distinct, fetch, fetch, fetch, fetch, findAny, findFirst, findSingle, flatMap, flatMap, flatMap, flatMapKeys, flatMapValues, getQueryType, getResultList, getResultStream, groupBy, groupBy, groupBy, groupByMulti, having, isEmpty, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, limit, map, map, map, map, mapToDouble, mapToDouble, mapToExpr, mapToFrom, mapToInt, mapToInt, mapToLong, mapToLong, mapToPath, mapToRef, mapToRef, mapToRef, mapToRef, mapToRoot, noneMatch, noneMatch, orderBy, orderBy, orderBy, orderBy, orderBy, orderBy, orderByMulti, skip, thenOrderBy, thenOrderBy, thenOrderBy, thenOrderBy
-
Method Details
-
value
Build and evaluate a JPA query based on this instance and return the single result, if any.- Returns:
- result of executed query
- Throws:
NoResultException
- if there is no resultNonUniqueResultException
- if there is more than one result
-
orElse
Build and evaluate a JPA query based on this instance and return the single result, if any, otherwise the given value.- Parameters:
defaultValue
- value to return if there is no match- Returns:
- result of executed query, or
defaultValue
if not found - Throws:
NonUniqueResultException
- if there is more than one result
-
orElseThrow
Build and evaluate a JPA query based on this instance and return the single result, if any, otherwise throw an exception provided by the givenSupplier
.- Type Parameters:
T
- exception type- Parameters:
supplier
- creator of exception- Returns:
- result of executed query
- Throws:
T
- if there is no resultNonUniqueResultException
- if there is more than one result
-
orElseGet
Build and evaluate a JPA query based on this instance and return the single result, if any, otherwise the value from the givenSupplier
.- Parameters:
supplier
- creator of exception- Returns:
- result of executed query
- Throws:
NonUniqueResultException
- if there is more than one resultIllegalArgumentException
- ifsupplier
is null
-
ifPresent
Build and evaluate a JPA query based on this instance and give the returned value, if any, to the givenConsumer
.- Parameters:
consumer
- receives value returned by query, if any- Throws:
IllegalArgumentException
- ifconsumer
is nullNonUniqueResultException
- if there is more than one result
-
isPresent
default boolean isPresent()Build and evaluate a JPA query based on this instance and return true if a result is returned, otherwise false.- Returns:
- true if executed query returns a result, false otherwise
- Throws:
NonUniqueResultException
- if there is more than one result
-
toOptional
Build and evaluate a JPA query based on this instance and return the single result, if any, as anOptional
.Note: due to limitations of the
Optional
class, this method does not support returning null values; if the query returns a null value, an exception is thrown.- Returns:
- the optional result of the executed query
- Throws:
NonUniqueResultException
- if there is more than one resultIllegalArgumentException
- if this query returns a null value
-
mapToSelection
default <Y> SearchValue<Y,Selection<Y>> mapToSelection(Class<Y> type, Function<? super S, ? extends Selection<Y>> selectionFunction) Description copied from interface:SearchStream
Map this stream into a stream whose elements are the result of applying the given function.This method provides support for multiple selection using
CriteriaBuilder.array()
,CriteriaBuilder.construct()
, orCriteriaBuilder.tuple()
. For normal single selection, typically you would useSearchStream.map()
instead of this method.- Specified by:
mapToSelection
in interfaceSearchStream<X,
S extends Selection<X>> - Type Parameters:
Y
- selection type- Parameters:
type
- selection typeselectionFunction
- function to build selection- Returns:
- mapped stream
-
bind
Description copied from interface:QueryStream
Bind an unbound reference to the items in this stream.- Specified by:
bind
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
bind
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
ref
- unbound reference- Returns:
- new stream that binds
ref
-
peek
Description copied from interface:QueryStream
Peek at the items in this stream.This is useful in cases where the selection can be modified, e.g., setting join
ON
conditions usingJoin.on()
.- Specified by:
peek
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
peek
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
peeker
- peeker into stream- Returns:
- new stream that peeks into this stream
-
bind
<X2,S2 extends Selection<X2>> SearchValue<X,S> bind(Ref<X2, ? super S2> ref, Function<? super S, ? extends S2> refFunction) Description copied from interface:QueryStream
Bind an unbound reference to the result of applying the given function to the items in this stream.- Specified by:
bind
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
bind
in interfaceSearchStream<X,
S extends Selection<X>> - Type Parameters:
X2
- type of the bound valueS2
- criteria type of the bound value- Parameters:
ref
- unbound referencerefFunction
- function mapping this stream'sSelection
to the reference value- Returns:
- new stream that binds
ref
-
filter
Description copied from interface:QueryStream
Filter results using the specified boolean property.Adds to any previously specified filters.
- Specified by:
filter
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
filter
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
attribute
- boolean property- Returns:
- new filtered stream
-
filter
Description copied from interface:QueryStream
Filter results using the boolean expression produced by the given function.Adds to any previously specified filters.
- Specified by:
filter
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
filter
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
predicateBuilder
- function mapping this stream's item to a booleanExpression
- Returns:
- new filtered stream
-
withFlushMode
Description copied from interface:QueryStream
Set theFlushModeType
associated with this query.- Specified by:
withFlushMode
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withFlushMode
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
flushMode
- new flush mode- Returns:
- new stream with the specified flush mode configured
- See Also:
-
withLockMode
Description copied from interface:QueryStream
Set theLockModeType
associated with this query.- Specified by:
withLockMode
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withLockMode
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
lockMode
- new lock mode- Returns:
- new stream with the specified lock mode configured
- See Also:
-
withHint
Description copied from interface:QueryStream
Associate a hint with this query.- Specified by:
withHint
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withHint
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
name
- name of hintvalue
- value of hint- Returns:
- new stream with the specified hint configured
- See Also:
-
withHints
Description copied from interface:QueryStream
Associate hints with this query.- Specified by:
withHints
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withHints
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
hints
- hints to add- Returns:
- new stream with the specified hints added
- See Also:
-
withParam
Description copied from interface:QueryStream
Bind the value of a query parameter.Replaces any previous binding of the same parameter.
- Specified by:
withParam
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withParam
in interfaceSearchStream<X,
S extends Selection<X>> - Type Parameters:
T
- parameter value type- Parameters:
parameter
- the parameter to setvalue
- parameter value- Returns:
- new stream with the specified parameter value set
- See Also:
-
withParam
Description copied from interface:QueryStream
Bind the value of a query parameter of typeDate
.Replaces any previous binding of the same parameter.
- Specified by:
withParam
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withParam
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
parameter
- the parameter to setvalue
- parameter valuetemporalType
- temporal type forvalue
- Returns:
- new stream with the specified parameter value set
- See Also:
-
withParam
SearchValue<X,S> withParam(Parameter<Calendar> parameter, Calendar value, TemporalType temporalType) Description copied from interface:QueryStream
Bind the value of a query parameter of typeCalendar
.Replaces any previous binding of the same parameter.
- Specified by:
withParam
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withParam
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
parameter
- the parameter to setvalue
- parameter valuetemporalType
- temporal type forvalue
- Returns:
- new stream with the specified parameter value set
- See Also:
-
withParams
Description copied from interface:QueryStream
Associate parameter bindings with this query.Replaces any previous bindings of the same parameters.
- Specified by:
withParams
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withParams
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
params
- bindings to add- Returns:
- new stream with the specified parameter bindings added
- See Also:
-
withLoadGraph
Description copied from interface:QueryStream
Configure a load graph for this query.Equivalent to
withHint
("jakarta.persistence.loadgraph", name)
.- Specified by:
withLoadGraph
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withLoadGraph
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
name
- name of load graph- Returns:
- new stream with the specified load graph configured
-
withFetchGraph
Description copied from interface:QueryStream
Configure a fetch graph for this query.Equivalent to
withHint
("jakarta.persistence.fetchgraph", name)
.- Specified by:
withFetchGraph
in interfaceQueryStream<X,
S extends Selection<X>, AbstractQuery<?>, CriteriaQuery<X>, TypedQuery<X>> - Specified by:
withFetchGraph
in interfaceSearchStream<X,
S extends Selection<X>> - Parameters:
name
- name of fetch graph- Returns:
- new stream with the specified fetch graph configured
-