public interface ExprStream<X,S extends Expression<X>> extends SearchStream<X,S>
SearchStream containing items representable as Expressions.QueryStream.Builder| Modifier and Type | Method and Description |
|---|---|
<R> ExprStream<X,S> |
addRoot(Ref<R,? super Root<R>> ref,
Class<R> type)
Bind an unbound reference to a new query root that will be added to the query.
|
Subquery<X> |
asSubquery()
Convert this instance into a subquery that can be used within an intermediate step of an outer query.
|
ExprStream<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.
|
LongValue |
count()
Create value returning the number of instances in this stream.
|
LongValue |
countDistinct()
Create value returning the number of distinct instances in this stream.
|
ExprStream<X,S> |
distinct()
Suppress duplicates.
|
Predicate |
exists()
Convert this instance into an "exists" subquery that can be used within an intermediate step of an outer query.
|
ExprStream<X,S> |
fetch(PluralAttribute<? super X,?,?> attribute)
Add a plural fetch join to this stream.
|
ExprStream<X,S> |
fetch(PluralAttribute<? super X,?,?> attribute,
JoinType joinType)
Add a plural fetch join to this stream.
|
ExprStream<X,S> |
fetch(SingularAttribute<? super X,?> attribute)
Add a singular fetch inner join to this stream.
|
ExprStream<X,S> |
fetch(SingularAttribute<? super X,?> attribute,
JoinType joinType)
Add a singular fetch join to this stream.
|
ExprStream<X,S> |
filter(Function<? super S,? extends Expression<Boolean>> predicateBuilder)
Filter results using the boolean expression produced by the given function.
|
ExprStream<X,S> |
filter(SingularAttribute<? super X,Boolean> attribute)
Filter results using the specified boolean property.
|
ExprValue<X,S> |
findAny()
Find any instance in the stream.
|
ExprValue<X,S> |
findFirst()
Find the first instance in the stream.
|
ExprValue<X,S> |
findSingle()
Find the only instance in the stream.
|
ExprStream<X,S> |
groupBy(Function<? super S,? extends Expression<?>> groupFunction)
Apply grouping based on a single expression.
|
ExprStream<X,S> |
groupBy(Ref<?,? extends Expression<?>> ref)
Apply grouping based on an expression reference.
|
ExprStream<X,S> |
groupBy(SingularAttribute<? super X,?> attribute)
Apply grouping based on the specified property.
|
ExprStream<X,S> |
groupByMulti(Function<? super S,? extends List<Expression<?>>> groupFunction)
Apply grouping based on a list of expressions.
|
ExprStream<X,S> |
having(Function<? super S,? extends Expression<Boolean>> havingFunction)
Add a "having" restriction.
|
ExprStream<X,S> |
limit(int maxSize)
Return this stream truncated to the specified maximum length.
|
ExprStream<X,S> |
orderBy(Function<? super S,? extends Expression<?>> orderExprFunction,
boolean asc)
Order results using the
Expression produced by the given Function. |
ExprStream<X,S> |
orderBy(Order... orders)
Order results using the specified
Orders. |
ExprStream<X,S> |
orderBy(Ref<?,? extends Expression<?>> ref,
boolean asc)
Order results using the specified expression reference.
|
ExprStream<X,S> |
orderBy(SingularAttribute<? super X,?> attribute,
boolean asc)
Order results using the specified property.
|
ExprStream<X,S> |
orderBy(SingularAttribute<? super X,?> attribute1,
boolean asc1,
SingularAttribute<? super X,?> attribute2,
boolean asc2)
Order results using the specified properties.
|
ExprStream<X,S> |
orderBy(SingularAttribute<? super X,?> attribute1,
boolean asc1,
SingularAttribute<? super X,?> attribute2,
boolean asc2,
SingularAttribute<? super X,?> attribute3,
boolean asc3)
Order results using the specified properties.
|
ExprStream<X,S> |
orderByMulti(Function<? super S,? extends List<? extends Order>> orderListFunction)
|
ExprStream<X,S> |
peek(Consumer<? super S> peeker)
Peek at the items in this stream.
|
ExprStream<X,S> |
skip(int num)
Return this stream with the specified number of initial elements skipped.
|
ExprStream<X,S> |
thenOrderBy(Function<? super S,? extends Expression<?>> orderExprFunction,
boolean asc)
Order results using the
Expression produced by the given Function after existing sort. |
ExprStream<X,S> |
thenOrderBy(Order... orders)
Order results using the specified
Orders after existing sort. |
ExprStream<X,S> |
thenOrderBy(Ref<?,? extends Expression<?>> ref,
boolean asc)
Order results using the specified expression reference after existing sort.
|
ExprStream<X,S> |
thenOrderBy(SingularAttribute<? super X,?> attribute,
boolean asc)
Order results using the specified property after existing sort.
|
ExprStream<X,S> |
withFetchGraph(String name)
Configure a fetch graph for this query.
|
ExprStream<X,S> |
withFlushMode(FlushModeType flushMode)
Set the
FlushModeType associated with this query. |
ExprStream<X,S> |
withHint(String name,
Object value)
Associate a hint with this query.
|
ExprStream<X,S> |
withHints(Map<String,Object> hints)
Associate hints with this query.
|
ExprStream<X,S> |
withLoadGraph(String name)
Configure a load graph for this query.
|
ExprStream<X,S> |
withLockMode(LockModeType lockMode)
Set the
LockModeType associated with this query. |
ExprStream<X,S> |
withParam(Parameter<Calendar> parameter,
Calendar value,
TemporalType temporalType)
Bind the value of a query parameter of type
Calendar. |
ExprStream<X,S> |
withParam(Parameter<Date> parameter,
Date value,
TemporalType temporalType)
Bind the value of a query parameter of type
Date. |
<T> ExprStream<X,S> |
withParam(Parameter<T> parameter,
T value)
Bind the value of a query parameter.
|
ExprStream<X,S> |
withParams(Iterable<? extends ParamBinding<?>> params)
Associate parameter bindings with this query.
|
allMatch, allMatch, anyMatch, anyMatch, flatMap, flatMap, flatMap, flatMapKeys, flatMapValues, getQueryType, getResultList, getResultStream, isEmpty, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, map, map, map, map, mapToDouble, mapToDouble, mapToExpr, mapToFrom, mapToInt, mapToInt, mapToLong, mapToLong, mapToPath, mapToRef, mapToRef, mapToRef, mapToRef, mapToRoot, mapToSelection, noneMatch, noneMatchgetEntityManager, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParams, newBuilder, toCriteriaQuery, toQueryconfigureSubquery<X> asSubquery()
IllegalStateException - if not invoked during a terminal operation on an outer queryPredicate exists()
Note: to perform the equivalent of an "exists" operation on the outermost query, use SearchStream.isEmpty().
IllegalStateException - if invoked on a stream which is not being used as a subquerySearchStream.isEmpty()LongValue count()
Warning: don't use in combination with groupBy(), because SQL's COUNT() returns a non-unique
result in grouped queries, or else a NonUniqueResultException can result.
LongValue countDistinct()
Warning: don't use in combination with groupBy(), because SQL's COUNT() returns a non-unique
result in grouped queries, or else a NonUniqueResultException can result.
ExprStream<X,S> distinct()
SearchStreamdistinct in interface SearchStream<X,S extends Expression<X>>ExprStream<X,S> orderBy(Ref<?,? extends Expression<?>> ref, boolean asc)
SearchStreamReplaces any existing sort ordering.
orderBy in interface SearchStream<X,S extends Expression<X>>ref - previously bound expression referenceasc - true for ascending, false for descendingExprStream<X,S> orderBy(SingularAttribute<? super X,?> attribute, boolean asc)
SearchStreamReplaces any existing sort ordering.
orderBy in interface SearchStream<X,S extends Expression<X>>attribute - associated propertyasc - true for ascending, false for descendingExprStream<X,S> orderBy(SingularAttribute<? super X,?> attribute1, boolean asc1, SingularAttribute<? super X,?> attribute2, boolean asc2)
SearchStreamReplaces any existing sort ordering.
orderBy in interface SearchStream<X,S extends Expression<X>>attribute1 - associated propertyasc1 - true for attribute1 ascending, false for attribute1 descendingattribute2 - associated propertyasc2 - true for attribute2 ascending, false for attribute2 descendingExprStream<X,S> orderBy(SingularAttribute<? super X,?> attribute1, boolean asc1, SingularAttribute<? super X,?> attribute2, boolean asc2, SingularAttribute<? super X,?> attribute3, boolean asc3)
SearchStreamReplaces any existing sort ordering.
orderBy in interface SearchStream<X,S extends Expression<X>>attribute1 - associated propertyasc1 - true for attribute1 ascending, false for attribute1 descendingattribute2 - associated propertyasc2 - true for attribute2 ascending, false for attribute2 descendingattribute3 - associated propertyasc3 - true for attribute3 ascending, false for attribute3 descendingExprStream<X,S> orderBy(Function<? super S,? extends Expression<?>> orderExprFunction, boolean asc)
SearchStreamExpression produced by the given Function.
Replaces any existing sort ordering.
orderBy in interface SearchStream<X,S extends Expression<X>>orderExprFunction - Function that produces an Expression to order on given an item expressionasc - true for ascending, false for descendingExprStream<X,S> orderBy(Order... orders)
SearchStreamOrders.
Replaces any existing sort ordering.
orderBy in interface SearchStream<X,S extends Expression<X>>orders - ordering(s), with higher precedence orderings firstExprStream<X,S> orderByMulti(Function<? super S,? extends List<? extends Order>> orderListFunction)
SearchStreamOrder list produced by the given Function.
Replaces any existing sort ordering.
orderByMulti in interface SearchStream<X,S extends Expression<X>>orderListFunction - Function that produces the sort ordering given an item expressionExprStream<X,S> thenOrderBy(SingularAttribute<? super X,?> attribute, boolean asc)
SearchStreamAdds to any existing sort ordering.
thenOrderBy in interface SearchStream<X,S extends Expression<X>>attribute - associated propertyasc - true for ascending, false for descendingExprStream<X,S> thenOrderBy(Ref<?,? extends Expression<?>> ref, boolean asc)
SearchStreamAdds to any existing sort ordering.
thenOrderBy in interface SearchStream<X,S extends Expression<X>>ref - previously bound expression referenceasc - true for ascending, false for descendingExprStream<X,S> thenOrderBy(Order... orders)
SearchStreamOrders after existing sort.
Adds to any existing sort ordering.
thenOrderBy in interface SearchStream<X,S extends Expression<X>>orders - ordering(s), with higher precedence orderings firstExprStream<X,S> thenOrderBy(Function<? super S,? extends Expression<?>> orderExprFunction, boolean asc)
SearchStreamExpression produced by the given Function after existing sort.
Adds to any existing sort ordering.
thenOrderBy in interface SearchStream<X,S extends Expression<X>>orderExprFunction - Function that produces an Expression to order on given an item expressionasc - true for ascending, false for descendingExprStream<X,S> groupBy(Ref<?,? extends Expression<?>> ref)
SearchStreamAdds to any previously specified groupings.
groupBy in interface SearchStream<X,S extends Expression<X>>ref - previously bound expression referenceExprStream<X,S> groupBy(SingularAttribute<? super X,?> attribute)
SearchStreamAdds to any previously specified groupings.
groupBy in interface SearchStream<X,S extends Expression<X>>attribute - associated propertyExprStream<X,S> groupBy(Function<? super S,? extends Expression<?>> groupFunction)
SearchStreamAdds to any previously specified groupings.
groupBy in interface SearchStream<X,S extends Expression<X>>groupFunction - function returning an expression by which to group resultsExprStream<X,S> groupByMulti(Function<? super S,? extends List<Expression<?>>> groupFunction)
SearchStreamAdds to any previously specified groupings.
groupByMulti in interface SearchStream<X,S extends Expression<X>>groupFunction - function returning a list of expressions by which to group resultsExprStream<X,S> having(Function<? super S,? extends Expression<Boolean>> havingFunction)
SearchStreamAdds to any previously specified "having" restrictions.
having in interface SearchStream<X,S extends Expression<X>>havingFunction - function returning a test to apply to grouped resultsExprValue<X,S> findAny()
SearchStreamfindAny in interface SearchStream<X,S extends Expression<X>>NULL if this stream is empty)ExprValue<X,S> findFirst()
SearchStreamfindFirst in interface SearchStream<X,S extends Expression<X>>NULL if this stream is empty)ExprValue<X,S> findSingle()
SearchStream
Invoke this method only when you know that the result stream contains at most one value, e.g., when searching
for an object by its value in a field with a unique constraint. If the stream actually contains multiple values,
then invoking any of the "single value" SearchValue methods such as value() or
toOptional() will generate a NonUniqueResultException.
Using this method is preferable to using SearchStream.findFirst() or SearchStream.findAny() for the same purpose, because it
not only actually verifies the uniqueness assumption, but it also makes that assumption clearer in the code.
Example:
final User user = qb.stream(User.class)
.filter(u -> qb.equal(u.get(User_.username), username))
.findSingle()
.orElseThrow(NoSuchUserException::new);
findSingle in interface SearchStream<X,S extends Expression<X>>NULL if this stream is empty)ExprStream<X,S> fetch(SingularAttribute<? super X,?> attribute)
SearchStream
Equivalent to fetch(attribute, JoinType.INNER).
fetch in interface SearchStream<X,S extends Expression<X>>attribute - associated propertyExprStream<X,S> fetch(SingularAttribute<? super X,?> attribute, JoinType joinType)
SearchStream
Unlike join(), this method does not change the stream's content type.
In other words, this method is used simply to pre-fetch an association, to avoid having to fetch it again
later for each individual element in the stream.
fetch in interface SearchStream<X,S extends Expression<X>>attribute - associated propertyjoinType - join typeExprStream<X,S> fetch(PluralAttribute<? super X,?,?> attribute)
SearchStream
Equivalent to fetch(attribute, JoinType.INNER).
fetch in interface SearchStream<X,S extends Expression<X>>attribute - associated propertyExprStream<X,S> fetch(PluralAttribute<? super X,?,?> attribute, JoinType joinType)
SearchStream
Unlike join(), this method does not change the stream's content type.
In other words, this method is used simply to pre-fetch an association, to avoid having to fetch it again
later for each individual element in the stream.
fetch in interface SearchStream<X,S extends Expression<X>>attribute - associated propertyjoinType - join typeExprStream<X,S> bind(Ref<X,? super S> ref)
QueryStreambind in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>bind in interface SearchStream<X,S extends Expression<X>>ref - unbound referencerefExprStream<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 Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>peek in interface SearchStream<X,S extends Expression<X>>peeker - peeker into stream<X2,S2 extends Selection<X2>> ExprStream<X,S> bind(Ref<X2,? super S2> ref, Function<? super S,? extends S2> refFunction)
QueryStreambind in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>bind in interface SearchStream<X,S extends Expression<X>>X2 - type of the bound valueS2 - criteria type of the bound valueref - unbound referencerefFunction - function mapping this stream's Selection to the reference valueref<R> ExprStream<X,S> addRoot(Ref<R,? super Root<R>> ref, Class<R> type)
SearchStream
To select the new root in a SearchStream, use SearchStream.map(),
providing a Function that returns ref.
Note that this effectively creates an unconstrained (cross product) join with the new root.
Typically there would be some additional restrictions imposed (e.g., via filter())
to relate the new root to the items in the stream.
addRoot in interface SearchStream<X,S extends Expression<X>>R - type of the new query rootref - unbound referencetype - type of the new query rootref to a new query root from typeExprStream<X,S> filter(SingularAttribute<? super X,Boolean> attribute)
QueryStreamAdds to any previously specified filters.
filter in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>filter in interface SearchStream<X,S extends Expression<X>>attribute - boolean propertyExprStream<X,S> filter(Function<? super S,? extends Expression<Boolean>> predicateBuilder)
QueryStreamAdds to any previously specified filters.
filter in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>filter in interface SearchStream<X,S extends Expression<X>>predicateBuilder - function mapping this stream's item to a boolean ExpressionExprStream<X,S> limit(int maxSize)
QueryStreamDue to limitations in the JPA Criteria API, this method is not supported on subquery streams and in general must be specified last (after any filtering, sorting, grouping, joins, etc.).
limit in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>limit in interface SearchStream<X,S extends Expression<X>>maxSize - maximum number of elements to returnExprStream<X,S> skip(int num)
QueryStreamDue to limitations in the JPA Criteria API, this method is not supported on subquery streams and in general must be specified last (after any filtering, sorting, grouping, joins, etc.).
skip in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>skip in interface SearchStream<X,S extends Expression<X>>num - number of elements to skipExprStream<X,S> withFlushMode(FlushModeType flushMode)
QueryStreamFlushModeType associated with this query.withFlushMode in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withFlushMode in interface SearchStream<X,S extends Expression<X>>flushMode - new flush modeQuery.setFlushMode(javax.persistence.FlushModeType)ExprStream<X,S> withLockMode(LockModeType lockMode)
QueryStreamLockModeType associated with this query.withLockMode in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withLockMode in interface SearchStream<X,S extends Expression<X>>lockMode - new lock modeQuery.setLockMode(javax.persistence.LockModeType)ExprStream<X,S> withHint(String name, Object value)
QueryStreamwithHint in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withHint in interface SearchStream<X,S extends Expression<X>>name - name of hintvalue - value of hintQuery.setHint(java.lang.String, java.lang.Object)ExprStream<X,S> withHints(Map<String,Object> hints)
QueryStreamwithHints in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withHints in interface SearchStream<X,S extends Expression<X>>hints - hints to addQuery.setHint(java.lang.String, java.lang.Object)<T> ExprStream<X,S> withParam(Parameter<T> parameter, T value)
QueryStreamReplaces any previous binding of the same parameter.
withParam in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParam in interface SearchStream<X,S extends Expression<X>>T - parameter value typeparameter - the parameter to setvalue - parameter valueQuery.setParameter(javax.persistence.Parameter, Object)ExprStream<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 Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParam in interface SearchStream<X,S extends Expression<X>>parameter - the parameter to setvalue - parameter valuetemporalType - temporal type for valueQuery.setParameter(javax.persistence.Parameter, Date, TemporalType)ExprStream<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 Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParam in interface SearchStream<X,S extends Expression<X>>parameter - the parameter to setvalue - parameter valuetemporalType - temporal type for valueQuery.setParameter(javax.persistence.Parameter, Calendar, TemporalType)ExprStream<X,S> withParams(Iterable<? extends ParamBinding<?>> params)
QueryStreamReplaces any previous bindings of the same parameters.
withParams in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withParams in interface SearchStream<X,S extends Expression<X>>params - bindings to addQuery.setParameter(javax.persistence.Parameter, Object)ExprStream<X,S> withLoadGraph(String name)
QueryStream
Equivalent to withHint("javax.persistence.loadgraph", name).
withLoadGraph in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withLoadGraph in interface SearchStream<X,S extends Expression<X>>name - name of load graphExprStream<X,S> withFetchGraph(String name)
QueryStream
Equivalent to withHint("javax.persistence.fetchgraph", name).
withFetchGraph in interface QueryStream<X,S extends Expression<X>,AbstractQuery<?>,CriteriaQuery<X>,TypedQuery<X>>withFetchGraph in interface SearchStream<X,S extends Expression<X>>name - name of fetch graphCopyright © 2023. All rights reserved.