public interface SearchValue<X,S extends Selection<X>> extends SearchStream<X,S>
SearchStream that is guaranteed to return at most a single result.QueryStream.Builder| Modifier and Type | Method and Description |
|---|---|
SearchValue<X,S> |
bind(Ref<X,? super S> ref)
Bind an unbound reference to the items in this stream.
|
<X2,S2 extends Selection<X2>> |
bind(Ref<X2,? super S2> ref,
Function<? super S,? extends S2> refFunction)
Bind an unbound reference to the result of applying the given function to the items in this stream.
|
SearchValue<X,S> |
filter(Function<? super S,? extends Expression<Boolean>> predicateBuilder)
Filter results using the boolean expression produced by the given function.
|
SearchValue<X,S> |
filter(SingularAttribute<? super X,Boolean> attribute)
Filter results using the specified boolean property.
|
default void |
ifPresent(Consumer<? super X> consumer)
Build and evaluate a JPA query based on this instance and give the returned value, if any, to the given
Consumer. |
default boolean |
isPresent()
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 |
orElse(X defaultValue)
Build and evaluate a JPA query based on this instance and return the single result, if any,
otherwise the given value.
|
default X |
orElseGet(Supplier<? extends X> supplier)
Build and evaluate a JPA query based on this instance and return the single result, if any,
otherwise the value from the given
Supplier. |
default <T extends Throwable> |
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 given
Supplier. |
SearchValue<X,S> |
peek(Consumer<? super S> peeker)
Peek at the items in this stream.
|
default Optional<X> |
toOptional()
Build and evaluate a JPA query based on this instance and return the single result, if any, as an
Optional. |
default X |
value()
Build and evaluate a JPA query based on this instance and return the single result, if any.
|
SearchValue<X,S> |
withFetchGraph(String name)
Configure a fetch graph for this query.
|
SearchValue<X,S> |
withFlushMode(FlushModeType flushMode)
Set the
FlushModeType associated with this query. |
SearchValue<X,S> |
withHint(String name,
Object value)
Associate a hint with this query.
|
SearchValue<X,S> |
withHints(Map<String,Object> hints)
Associate hints with this query.
|
SearchValue<X,S> |
withLoadGraph(String name)
Configure a load graph for this query.
|
SearchValue<X,S> |
withLockMode(LockModeType lockMode)
Set the
LockModeType associated with this query. |
SearchValue<X,S> |
withParam(Parameter<Calendar> parameter,
Calendar value,
TemporalType temporalType)
Bind the value of a query parameter of type
Calendar. |
SearchValue<X,S> |
withParam(Parameter<Date> parameter,
Date value,
TemporalType temporalType)
Bind the value of a query parameter of type
Date. |
<T> SearchValue<X,S> |
withParam(Parameter<T> parameter,
T value)
Bind the value of a query parameter.
|
SearchValue<X,S> |
withParams(Iterable<? extends ParamBinding<?>> params)
Associate parameter bindings with this query.
|
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, thenOrderBygetEntityManager, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParams, newBuilder, toCriteriaQuery, toQueryconfiguredefault X value()
NoResultException - if there is no resultdefault X orElse(X defaultValue)
defaultValue - value to return if there is no matchdefaultValue if not founddefault <T extends Throwable> X orElseThrow(Supplier<? extends T> supplier) throws T extends Throwable
Supplier.T - exception typesupplier - creator of exceptionT - if there is no resultT extends Throwabledefault X orElseGet(Supplier<? extends X> supplier)
Supplier.supplier - creator of exceptionIllegalArgumentException - if supplier is nulldefault void ifPresent(Consumer<? super X> consumer)
Consumer.consumer - receives value returned by query, if anyIllegalArgumentException - if consumer is nulldefault boolean isPresent()
default Optional<X> toOptional()
Optional.
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.
IllegalArgumentException - if this query returns a null valuedefault <Y> SearchValue<Y,Selection<Y>> mapToSelection(Class<Y> type, Function<? super S,? extends Selection<Y>> selectionFunction)
SearchStream
This method provides support for multiple selection using
CriteriaBuilder.array(),
CriteriaBuilder.construct(), or
CriteriaBuilder.tuple().
For normal single selection, typically you would use SearchStream.map() instead of this method.
mapToSelection in interface SearchStream<X,S extends Selection<X>>Y - selection typetype - selection typeselectionFunction - function to build selectionSearchValue<X,S> bind(Ref<X,? super S> ref)
QueryStreambind in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>bind in interface SearchStream<X,S extends Selection<X>>ref - unbound referencerefSearchValue<X,S> peek(Consumer<? super S> peeker)
QueryStream
This is useful in cases where the selection can be modified, e.g., setting join ON conditions
using Join.on().
peek in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>peek in interface SearchStream<X,S extends Selection<X>>peeker - peeker into stream<X2,S2 extends Selection<X2>> SearchValue<X,S> bind(Ref<X2,? super S2> ref, Function<? super S,? extends S2> refFunction)
QueryStreambind in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>bind in interface SearchStream<X,S extends Selection<X>>X2 - type of the bound valueS2 - criteria type of the bound valueref - unbound referencerefFunction - function mapping this stream's Selection to the reference valuerefSearchValue<X,S> filter(SingularAttribute<? super X,Boolean> attribute)
QueryStreamAdds to any previously specified filters.
filter in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>filter in interface SearchStream<X,S extends Selection<X>>attribute - boolean propertySearchValue<X,S> filter(Function<? super S,? extends Expression<Boolean>> predicateBuilder)
QueryStreamAdds to any previously specified filters.
filter in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>filter in interface SearchStream<X,S extends Selection<X>>predicateBuilder - function mapping this stream's item to a boolean ExpressionSearchValue<X,S> withFlushMode(FlushModeType flushMode)
QueryStreamFlushModeType associated with this query.withFlushMode in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withFlushMode in interface SearchStream<X,S extends Selection<X>>flushMode - new flush modeQuery.setFlushMode(javax.persistence.FlushModeType)SearchValue<X,S> withLockMode(LockModeType lockMode)
QueryStreamLockModeType associated with this query.withLockMode in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withLockMode in interface SearchStream<X,S extends Selection<X>>lockMode - new lock modeQuery.setLockMode(javax.persistence.LockModeType)SearchValue<X,S> withHint(String name, Object value)
QueryStreamwithHint in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withHint in interface SearchStream<X,S extends Selection<X>>name - name of hintvalue - value of hintQuery.setHint(java.lang.String, java.lang.Object)SearchValue<X,S> withHints(Map<String,Object> hints)
QueryStreamwithHints in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withHints in interface SearchStream<X,S extends Selection<X>>hints - hints to addQuery.setHint(java.lang.String, java.lang.Object)<T> SearchValue<X,S> withParam(Parameter<T> parameter, T value)
QueryStreamReplaces any previous binding of the same parameter.
withParam in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParam in interface SearchStream<X,S extends Selection<X>>T - parameter value typeparameter - the parameter to setvalue - parameter valueQuery.setParameter(javax.persistence.Parameter, Object)SearchValue<X,S> withParam(Parameter<Date> parameter, Date value, TemporalType temporalType)
QueryStreamDate.
Replaces any previous binding of the same parameter.
withParam in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParam in interface SearchStream<X,S extends Selection<X>>parameter - the parameter to setvalue - parameter valuetemporalType - temporal type for valueQuery.setParameter(javax.persistence.Parameter, Date, TemporalType)SearchValue<X,S> withParam(Parameter<Calendar> parameter, Calendar value, TemporalType temporalType)
QueryStreamCalendar.
Replaces any previous binding of the same parameter.
withParam in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParam in interface SearchStream<X,S extends Selection<X>>parameter - the parameter to setvalue - parameter valuetemporalType - temporal type for valueQuery.setParameter(javax.persistence.Parameter, Calendar, TemporalType)SearchValue<X,S> withParams(Iterable<? extends ParamBinding<?>> params)
QueryStreamReplaces any previous bindings of the same parameters.
withParams in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParams in interface SearchStream<X,S extends Selection<X>>params - bindings to addQuery.setParameter(javax.persistence.Parameter, Object)SearchValue<X,S> withLoadGraph(String name)
QueryStream
Equivalent to withHint("javax.persistence.loadgraph", name).
withLoadGraph in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withLoadGraph in interface SearchStream<X,S extends Selection<X>>name - name of load graphSearchValue<X,S> withFetchGraph(String name)
QueryStream
Equivalent to withHint("javax.persistence.fetchgraph", name).
withFetchGraph in interface QueryStream<X,S extends Selection<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withFetchGraph in interface SearchStream<X,S extends Selection<X>>name - name of fetch graphCopyright © 2023. All rights reserved.