Interface IntStream
- All Superinterfaces:
ExprStream<Integer,
,Expression<Integer>> QueryConfigurer<AbstractQuery<?>,
,Integer, Expression<Integer>> QueryStream<Integer,
,Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> SearchStream<Integer,
Expression<Integer>>
- All Known Subinterfaces:
IntValue
SearchStream
containing Integer
values.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.dellroad.querystream.jpa.QueryStream
QueryStream.Builder
-
Method Summary
Modifier and TypeMethodDescription<R> IntStream
Bind an unbound reference to a new query root that will be added to the query.average()
bind
(Ref<Integer, ? super Expression<Integer>> ref) Bind an unbound reference to the items in this stream.bind
(Ref<X2, ? super S2> ref, Function<? super Expression<Integer>, ? extends S2> refFunction) Bind an unbound reference to the result of applying the given function to the items in this stream.distinct()
Suppress duplicates.filter
(Function<? super Expression<Integer>, ? extends Expression<Boolean>> predicateBuilder) Filter results using the boolean expression produced by the given function.findAny()
Find any instance in the stream.Find the first instance in the stream.Find the only instance in the stream or null.groupBy
(Function<? super Expression<Integer>, ? extends Expression<?>> groupFunction) Apply grouping based on a single expression.groupBy
(Ref<?, ? extends Expression<?>> ref) Apply grouping based on an expression reference.groupByMulti
(Function<? super Expression<Integer>, ? extends List<Expression<?>>> groupFunction) Apply grouping based on a list of expressions.having
(Function<? super Expression<Integer>, ? extends Expression<Boolean>> havingFunction) Add a "having" restriction.limit
(int maxSize) Return this stream truncated to the specified maximum length.max()
min()
Order results using the specifiedOrder
s.orderBy
(Function<? super Expression<Integer>, ? extends Expression<?>> orderExprFunction, boolean asc) Order results using theExpression
produced by the givenFunction
.orderBy
(Ref<?, ? extends Expression<?>> ref, boolean asc) Order results using the specified expression reference.orderByMulti
(Function<? super Expression<Integer>, ? extends List<? extends Order>> orderListFunction) peek
(Consumer<? super Expression<Integer>> peeker) Peek at the items in this stream.skip
(int num) Return this stream with the specified number of initial elements skipped.sum()
thenOrderBy
(Order... orders) Order results using the specifiedOrder
s after existing sort.thenOrderBy
(Function<? super Expression<Integer>, ? extends Expression<?>> orderExprFunction, boolean asc) Order results using theExpression
produced by the givenFunction
after existing sort.thenOrderBy
(Ref<?, ? extends Expression<?>> ref, boolean asc) Order results using the specified expression reference after existing sort.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> IntStream
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.ExprStream
asSubquery, count, countDistinct, exists, fetch, fetch, fetch, fetch, filter, groupBy, orderBy, orderBy, orderBy, thenOrderBy
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
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, noneMatch
-
Method Details
-
average
DoubleValue average() -
max
IntValue max() -
min
IntValue min() -
sum
IntValue sum() -
asLongStream
LongStream asLongStream() -
asDoubleStream
DoubleStream asDoubleStream() -
distinct
IntStream distinct()Description copied from interface:SearchStream
Suppress duplicates.- Specified by:
distinct
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
distinct
in interfaceSearchStream<Integer,
Expression<Integer>> - Returns:
- a new stream with duplicates removed
-
orderBy
Description copied from interface:SearchStream
Order results using the specified expression reference.Replaces any existing sort ordering.
- Specified by:
orderBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
orderBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
ref
- previously bound expression referenceasc
- true for ascending, false for descending- Returns:
- a new stream with specified ordering
-
orderBy
IntStream orderBy(Function<? super Expression<Integer>, ? extends Expression<?>> orderExprFunction, boolean asc) Description copied from interface:SearchStream
Order results using theExpression
produced by the givenFunction
.Replaces any existing sort ordering.
- Specified by:
orderBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
orderBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
orderExprFunction
-Function
that produces anExpression
to order on given an item expressionasc
- true for ascending, false for descending- Returns:
- a new stream with specified ordering
-
orderBy
Description copied from interface:SearchStream
Order results using the specifiedOrder
s.Replaces any existing sort ordering.
- Specified by:
orderBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
orderBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
orders
- ordering(s), with higher precedence orderings first- Returns:
- a new stream with specified ordering(s)
-
orderByMulti
IntStream orderByMulti(Function<? super Expression<Integer>, ? extends List<? extends Order>> orderListFunction) Description copied from interface:SearchStream
Order results using theOrder
list produced by the givenFunction
.Replaces any existing sort ordering.
- Specified by:
orderByMulti
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
orderByMulti
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
orderListFunction
-Function
that produces the sort ordering given an item expression- Returns:
- a new stream with specified ordering
-
thenOrderBy
Description copied from interface:SearchStream
Order results using the specified expression reference after existing sort.Adds to any existing sort ordering.
- Specified by:
thenOrderBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
thenOrderBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
ref
- previously bound expression referenceasc
- true for ascending, false for descending- Returns:
- a new stream with specified additional ordering
-
thenOrderBy
Description copied from interface:SearchStream
Order results using the specifiedOrder
s after existing sort.Adds to any existing sort ordering.
- Specified by:
thenOrderBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
thenOrderBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
orders
- ordering(s), with higher precedence orderings first- Returns:
- a new stream with specified additional ordering(s)
-
thenOrderBy
IntStream thenOrderBy(Function<? super Expression<Integer>, ? extends Expression<?>> orderExprFunction, boolean asc) Description copied from interface:SearchStream
Order results using theExpression
produced by the givenFunction
after existing sort.Adds to any existing sort ordering.
- Specified by:
thenOrderBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
thenOrderBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
orderExprFunction
-Function
that produces anExpression
to order on given an item expressionasc
- true for ascending, false for descending- Returns:
- a new stream with specified additional ordering
-
groupBy
Description copied from interface:SearchStream
Apply grouping based on an expression reference.Adds to any previously specified groupings.
- Specified by:
groupBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
groupBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
ref
- previously bound expression reference- Returns:
- a new stream with additional grouping
-
groupBy
Description copied from interface:SearchStream
Apply grouping based on a single expression.Adds to any previously specified groupings.
- Specified by:
groupBy
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
groupBy
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
groupFunction
- function returning an expression by which to group results- Returns:
- a new stream with additional grouping
-
groupByMulti
IntStream groupByMulti(Function<? super Expression<Integer>, ? extends List<Expression<?>>> groupFunction) Description copied from interface:SearchStream
Apply grouping based on a list of expressions.Adds to any previously specified groupings.
- Specified by:
groupByMulti
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
groupByMulti
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
groupFunction
- function returning a list of expressions by which to group results- Returns:
- a new instance
-
having
IntStream having(Function<? super Expression<Integer>, ? extends Expression<Boolean>> havingFunction) Description copied from interface:SearchStream
Add a "having" restriction.Adds to any previously specified "having" restrictions.
- Specified by:
having
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
having
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
havingFunction
- function returning a test to apply to grouped results- Returns:
- a new instance
-
findAny
IntValue findAny()Description copied from interface:SearchStream
Find any instance in the stream.- Specified by:
findAny
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
findAny
in interfaceSearchStream<Integer,
Expression<Integer>> - Returns:
- single-valued stream containg any instance in this stream (or
NULL
if this stream is empty)
-
findFirst
IntValue findFirst()Description copied from interface:SearchStream
Find the first instance in the stream.- Specified by:
findFirst
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
findFirst
in interfaceSearchStream<Integer,
Expression<Integer>> - Returns:
- single-valued stream containg the first instance in this stream (or
NULL
if this stream is empty)
-
findSingle
IntValue findSingle()Description copied from interface:SearchStream
Find the only instance in the stream or null.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 asvalue()
ortoOptional()
will generate aNonUniqueResultException
.Using this method is preferable to using
SearchStream.findFirst()
orSearchStream.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);
- Specified by:
findSingle
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
findSingle
in interfaceSearchStream<Integer,
Expression<Integer>> - Returns:
- a single value, either the only instance in this stream or null if this stream is empty
-
bind
Description copied from interface:QueryStream
Bind an unbound reference to the items in this stream.- Specified by:
bind
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
bind
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
bind
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
peek
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
peek
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
peeker
- peeker into stream- Returns:
- new stream that peeks into this stream
-
bind
<X2,S2 extends Selection<X2>> IntStream bind(Ref<X2, ? super S2> ref, Function<? super Expression<Integer>, ? 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
bind
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
bind
in interfaceSearchStream<Integer,
Expression<Integer>> - 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
-
addRoot
Description copied from interface:SearchStream
Bind an unbound reference to a new query root that will be added to the query.To select the new root in a
SearchStream
, useSearchStream.map()
, providing aFunction
that returnsref
.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.- Specified by:
addRoot
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
addRoot
in interfaceSearchStream<Integer,
Expression<Integer>> - Type Parameters:
R
- type of the new query root- Parameters:
ref
- unbound referencetype
- type of the new query root- Returns:
- new stream that binds
ref
to a new query root fromtype
-
filter
IntStream filter(Function<? super Expression<Integer>, ? extends Expression<Boolean>> predicateBuilder) 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
filter
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
filter
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
predicateBuilder
- function mapping this stream's item to a booleanExpression
- Returns:
- new filtered stream
-
limit
Description copied from interface:QueryStream
Return this stream truncated to the specified maximum length.Due 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.).
- Specified by:
limit
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
limit
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
limit
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
maxSize
- maximum number of elements to return- Returns:
- new truncated stream
-
skip
Description copied from interface:QueryStream
Return this stream with the specified number of initial elements skipped.Due 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.).
- Specified by:
skip
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
skip
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
skip
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
num
- number of elements to skip- Returns:
- new elided stream
-
withFlushMode
Description copied from interface:QueryStream
Set theFlushModeType
associated with this query.- Specified by:
withFlushMode
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withFlushMode
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withFlushMode
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withLockMode
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withLockMode
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withHint
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withHint
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withHints
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withHints
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withParam
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withParam
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withParam
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withParam
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
parameter
- the parameter to setvalue
- parameter valuetemporalType
- temporal type forvalue
- 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 typeCalendar
.Replaces any previous binding of the same parameter.
- Specified by:
withParam
in interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withParam
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withParam
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withParams
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withParams
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withLoadGraph
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withLoadGraph
in interfaceSearchStream<Integer,
Expression<Integer>> - 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 interfaceExprStream<Integer,
Expression<Integer>> - Specified by:
withFetchGraph
in interfaceQueryStream<Integer,
Expression<Integer>, AbstractQuery<?>, CriteriaQuery<Integer>, TypedQuery<Integer>> - Specified by:
withFetchGraph
in interfaceSearchStream<Integer,
Expression<Integer>> - Parameters:
name
- name of fetch graph- Returns:
- new stream with the specified fetch graph configured
-