Interface SearchValue<X,S extends jakarta.persistence.criteria.Selection<X>>
- All Superinterfaces:
QueryConfigurer<jakarta.persistence.criteria.AbstractQuery<?>,,X, S> QueryStream<X,,S, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.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 jakarta.persistence.criteria.Selection<X2>>
SearchValue<X,S> Bind an unbound reference to the result of applying the given function to the items in this stream.Filter results using the specified boolean property.filter(Function<? super S, ? extends jakarta.persistence.criteria.Expression<Boolean>> predicateBuilder) Filter results using the boolean expression produced by the given function.default voidBuild and evaluate a JPA query based on this instance and give the returned value, if any, to the givenConsumer.default booleanBuild and evaluate a JPA query based on this instance and return true if a result is returned, otherwise false.default <Y> SearchValue<Y,jakarta.persistence.criteria.Selection<Y>> mapToSelection(Class<Y> type, Function<? super S, ? extends jakarta.persistence.criteria.Selection<Y>> selectionFunction) Map this stream into a stream whose elements are the result of applying the given function.default XBuild and evaluate a JPA query based on this instance and return the single result, if any, otherwise the given value.default XBuild 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 Xvalue()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(jakarta.persistence.FlushModeType flushMode) Set theFlushModeTypeassociated 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(jakarta.persistence.LockModeType lockMode) Set theLockModeTypeassociated with this query.withParam(jakarta.persistence.Parameter<Calendar> parameter, Calendar value, jakarta.persistence.TemporalType temporalType) Bind the value of a query parameter of typeCalendar.withParam(jakarta.persistence.Parameter<Date> parameter, Date value, jakarta.persistence.TemporalType temporalType) Bind the value of a query parameter of typeDate.<T> SearchValue<X,S> withParam(jakarta.persistence.Parameter<T> parameter, T value) 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
configureMethods inherited from interface org.dellroad.querystream.jpa.QueryStream
getEntityManager, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParams, toCriteriaQuery, toQueryMethods 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:
jakarta.persistence.NoResultException- if there is no resultjakarta.persistence.NonUniqueResultException- 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
defaultValueif not found - Throws:
jakarta.persistence.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 resultjakarta.persistence.NonUniqueResultException- 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:
jakarta.persistence.NonUniqueResultException- if there is more than one resultIllegalArgumentException- ifsupplieris 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- ifconsumeris nulljakarta.persistence.NonUniqueResultException- 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:
jakarta.persistence.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
Optionalclass, 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:
jakarta.persistence.NonUniqueResultException- if there is more than one resultIllegalArgumentException- if this query returns a null value
-
mapToSelection
default <Y> SearchValue<Y,jakarta.persistence.criteria.Selection<Y>> mapToSelection(Class<Y> type, Function<? super S, ? extends jakarta.persistence.criteria.Selection<Y>> selectionFunction) Description copied from interface:SearchStreamMap 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:
mapToSelectionin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Type Parameters:
Y- selection type- Parameters:
type- selection typeselectionFunction- function to build selection- Returns:
- mapped stream
-
bind
Description copied from interface:QueryStreamBind an unbound reference to the items in this stream.- Specified by:
bindin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
bindin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
ref- unbound reference- Returns:
- new stream that binds
ref
-
peek
Description copied from interface:QueryStreamPeek at the items in this stream.This is useful in cases where the selection can be modified, e.g., setting join
ONconditions usingJoin.on().- Specified by:
peekin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
peekin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
peeker- peeker into stream- Returns:
- new stream that peeks into this stream
-
bind
<X2,S2 extends jakarta.persistence.criteria.Selection<X2>> SearchValue<X,S> bind(Ref<X2, ? super S2> ref, Function<? super S, ? extends S2> refFunction) Description copied from interface:QueryStreamBind an unbound reference to the result of applying the given function to the items in this stream.- Specified by:
bindin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
bindin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Type Parameters:
X2- type of the bound valueS2- criteria type of the bound value- Parameters:
ref- unbound referencerefFunction- function mapping this stream'sSelectionto the reference value- Returns:
- new stream that binds
ref
-
filter
SearchValue<X,S> filter(jakarta.persistence.metamodel.SingularAttribute<? super X, Boolean> attribute) Description copied from interface:QueryStreamFilter results using the specified boolean property.Adds to any previously specified filters.
- Specified by:
filterin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
filterin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
attribute- boolean property- Returns:
- new filtered stream
-
filter
SearchValue<X,S> filter(Function<? super S, ? extends jakarta.persistence.criteria.Expression<Boolean>> predicateBuilder) Description copied from interface:QueryStreamFilter results using the boolean expression produced by the given function.Adds to any previously specified filters.
- Specified by:
filterin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
filterin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
predicateBuilder- function mapping this stream's item to a booleanExpression- Returns:
- new filtered stream
-
withFlushMode
Description copied from interface:QueryStreamSet theFlushModeTypeassociated with this query.- Specified by:
withFlushModein interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withFlushModein interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
flushMode- new flush mode- Returns:
- new stream with the specified flush mode configured
- See Also:
-
Query.setFlushMode(jakarta.persistence.FlushModeType)
-
withLockMode
Description copied from interface:QueryStreamSet theLockModeTypeassociated with this query.- Specified by:
withLockModein interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withLockModein interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
lockMode- new lock mode- Returns:
- new stream with the specified lock mode configured
- See Also:
-
Query.setLockMode(jakarta.persistence.LockModeType)
-
withHint
Description copied from interface:QueryStreamAssociate a hint with this query.- Specified by:
withHintin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withHintin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
name- name of hintvalue- value of hint- Returns:
- new stream with the specified hint configured
- See Also:
-
Query.setHint(java.lang.String, java.lang.Object)
-
withHints
Description copied from interface:QueryStreamAssociate hints with this query.- Specified by:
withHintsin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withHintsin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
hints- hints to add- Returns:
- new stream with the specified hints added
- See Also:
-
Query.setHint(java.lang.String, java.lang.Object)
-
withParam
Description copied from interface:QueryStreamBind the value of a query parameter.Replaces any previous binding of the same parameter.
- Specified by:
withParamin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withParamin interfaceSearchStream<X,S extends jakarta.persistence.criteria.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:
-
Query.setParameter(Parameter, Object)
-
withParam
SearchValue<X,S> withParam(jakarta.persistence.Parameter<Date> parameter, Date value, jakarta.persistence.TemporalType temporalType) Description copied from interface:QueryStreamBind the value of a query parameter of typeDate.Replaces any previous binding of the same parameter.
- Specified by:
withParamin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withParamin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
parameter- the parameter to setvalue- parameter valuetemporalType- temporal type forvalue- Returns:
- new stream with the specified parameter value set
- See Also:
-
Query.setParameter(Parameter, Date, TemporalType)
-
withParam
SearchValue<X,S> withParam(jakarta.persistence.Parameter<Calendar> parameter, Calendar value, jakarta.persistence.TemporalType temporalType) Description copied from interface:QueryStreamBind the value of a query parameter of typeCalendar.Replaces any previous binding of the same parameter.
- Specified by:
withParamin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withParamin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
parameter- the parameter to setvalue- parameter valuetemporalType- temporal type forvalue- Returns:
- new stream with the specified parameter value set
- See Also:
-
Query.setParameter(Parameter, Calendar, TemporalType)
-
withParams
Description copied from interface:QueryStreamAssociate parameter bindings with this query.Replaces any previous bindings of the same parameters.
- Specified by:
withParamsin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withParamsin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
params- bindings to add- Returns:
- new stream with the specified parameter bindings added
- See Also:
-
Query.setParameter(Parameter, Object)
-
withLoadGraph
Description copied from interface:QueryStreamConfigure a load graph for this query.Equivalent to
withHint("jakarta.persistence.loadgraph", name).- Specified by:
withLoadGraphin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withLoadGraphin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
name- name of load graph- Returns:
- new stream with the specified load graph configured
-
withFetchGraph
Description copied from interface:QueryStreamConfigure a fetch graph for this query.Equivalent to
withHint("jakarta.persistence.fetchgraph", name).- Specified by:
withFetchGraphin interfaceQueryStream<X,S extends jakarta.persistence.criteria.Selection<X>, jakarta.persistence.criteria.AbstractQuery<?>, jakarta.persistence.criteria.CriteriaQuery<X>, jakarta.persistence.TypedQuery<X>> - Specified by:
withFetchGraphin interfaceSearchStream<X,S extends jakarta.persistence.criteria.Selection<X>> - Parameters:
name- name of fetch graph- Returns:
- new stream with the specified fetch graph configured
-