Interface QueryStream<X,S extends Selection<X>,C extends CommonAbstractCriteria,C2 extends C,Q extends Query>
- Type Parameters:
X- stream item typeS- criteria type for stream itemC- configured criteria API query typeC2- final criteria API query typeQ- JPA query type
- All Superinterfaces:
QueryConfigurer<C,X, S>
- All Known Subinterfaces:
BooleanValue,DeleteStream<X>,DoubleStream,DoubleValue,ExprStream<X,,S> ExprValue<X,,S> FromStream<X,,S> FromValue<X,,S> IntStream,IntValue,LongStream,LongValue,PathStream<X,,S> PathValue<X,,S> RootStream<X>,RootValue<X>,SearchStream<X,,S> SearchValue<X,,S> UpdateStream<X>
Stream-like API.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final class -
Method Summary
Modifier and TypeMethodDescriptionBind an unbound reference to the items in this stream.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.Get theEntityManagerassociated with this instance.intGet the row offset associated with this query.Get theFlushModeTypeassociated with this query.getHints()Get any hints associated with this query.Get theLockModeTypeassociated with this query.intGet the row limit associated with this query.Set<ParamBinding<?>>Get any parameter bindings associated with this query.Get theQueryTypeof this instance.limit(int maxSize) Return this stream truncated to the specified maximum length.static QueryStream.BuildernewBuilder(EntityManager entityManager) Peek at the items in this stream.skip(int num) Return this stream with the specified number of initial elements skipped.Build a criteria API query based on this instance.toQuery()Build a fully configured JPA query based on this instance.withFetchGraph(String name) Configure a fetch graph for this query.withFlushMode(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(LockModeType lockMode) Set theLockModeTypeassociated 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.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
-
Method Details
-
getQueryType
Get theQueryTypeof this instance.- Returns:
- associated
QueryType
-
getEntityManager
EntityManager getEntityManager()Get theEntityManagerassociated with this instance.- Returns:
- associated
EntityManager
-
toCriteriaQuery
C2 toCriteriaQuery()Build a criteria API query based on this instance.Note that due to limitations of the JPA Criteria API, the returned query object lacks information that is configured on the
Queryobject and not theCriteriaQueryobject, including lock mode, hints, parameters, row offset and limit, etc.This information can only be configured on the fully formed
Query; usetoQuery()instead of this method to also include that information.- Returns:
- new Criteria API query corresponding to this instance
- See Also:
-
toQuery
Q toQuery()Build a fully configured JPA query based on this instance.- Returns:
- new JPA query corresponding to this instance
-
getFirstResult
int getFirstResult()Get the row offset associated with this query.- Returns:
- row offset, or -1 if there is none configured
- See Also:
-
getMaxResults
int getMaxResults()Get the row limit associated with this query.- Returns:
- row limit, or -1 if there is none configured
- See Also:
-
getFlushMode
FlushModeType getFlushMode()Get theFlushModeTypeassociated with this query.- Returns:
- flush mode, or null if none set (i.e., use
EntityManagersetting) - See Also:
-
withFlushMode
Set theFlushModeTypeassociated with this query.- Parameters:
flushMode- new flush mode- Returns:
- new stream with the specified flush mode configured
- Throws:
IllegalArgumentException- ifflushModeis null- See Also:
-
getLockMode
LockModeType getLockMode()Get theLockModeTypeassociated with this query.- Returns:
- lock mode, or null if none set
- See Also:
-
withLockMode
Set theLockModeTypeassociated with this query.- Parameters:
lockMode- new lock mode- Returns:
- new stream with the specified lock mode configured
- Throws:
IllegalArgumentException- iflockModeis null- See Also:
-
getHints
Get any hints associated with this query.- Returns:
- configured hints, if any, otherwise an empty map
- See Also:
-
withHint
Associate a hint with this query.- Parameters:
name- name of hintvalue- value of hint- Returns:
- new stream with the specified hint configured
- Throws:
IllegalArgumentException- iflockModeis null- See Also:
-
withHints
Associate hints with this query.- Parameters:
hints- hints to add- Returns:
- new stream with the specified hints added
- Throws:
IllegalArgumentException- ifhintsis null- See Also:
-
getParams
Set<ParamBinding<?>> getParams()Get any parameter bindings associated with this query.- Returns:
- configured parameter bindings, if any, otherwise an empty set
- See Also:
-
withParam
Bind the value of a query parameter.Replaces any previous binding of the same parameter.
- Type Parameters:
T- parameter value type- Parameters:
parameter- the parameter to setvalue- parameter value- Returns:
- new stream with the specified parameter value set
- Throws:
IllegalArgumentException- ifparameteris null- See Also:
-
withParam
Bind the value of a query parameter of typeDate.Replaces any previous binding of the same parameter.
- Parameters:
parameter- the parameter to setvalue- parameter valuetemporalType- temporal type forvalue- Returns:
- new stream with the specified parameter value set
- Throws:
IllegalArgumentException- ifparameterortemporalTypeis null- See Also:
-
withParam
QueryStream<X,S, withParamC, C2, Q> (Parameter<Calendar> parameter, Calendar value, TemporalType temporalType) Bind the value of a query parameter of typeCalendar.Replaces any previous binding of the same parameter.
- Parameters:
parameter- the parameter to setvalue- parameter valuetemporalType- temporal type forvalue- Returns:
- new stream with the specified parameter value set
- Throws:
IllegalArgumentException- ifparameterortemporalTypeis null- See Also:
-
withParams
Associate parameter bindings with this query.Replaces any previous bindings of the same parameters.
- Parameters:
params- bindings to add- Returns:
- new stream with the specified parameter bindings added
- Throws:
IllegalArgumentException- ifparamsor any contained element is nullIllegalArgumentException- ifparamscontains duplicate bindings for the same parameter- See Also:
-
withLoadGraph
Configure a load graph for this query.Equivalent to
withHint("jakarta.persistence.loadgraph", name).- Parameters:
name- name of load graph- Returns:
- new stream with the specified load graph configured
- Throws:
IllegalArgumentException- ifnameis invalid
-
withFetchGraph
Configure a fetch graph for this query.Equivalent to
withHint("jakarta.persistence.fetchgraph", name).- Parameters:
name- name of fetch graph- Returns:
- new stream with the specified fetch graph configured
- Throws:
IllegalArgumentException- ifnameis invalid
-
bind
Bind an unbound reference to the items in this stream.- Parameters:
ref- unbound reference- Returns:
- new stream that binds
ref - Throws:
IllegalArgumentException- ifrefis already boundIllegalArgumentException- ifrefis null
-
bind
<X2,S2 extends Selection<X2>> QueryStream<X,S, bindC, C2, Q> (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.- 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 - Throws:
IllegalArgumentException- ifrefis already boundIllegalArgumentException- ifreforrefFunctionis null
-
peek
Peek at the items in this stream.This is useful in cases where the selection can be modified, e.g., setting join
ONconditions usingJoin.on().- Parameters:
peeker- peeker into stream- Returns:
- new stream that peeks into this stream
- Throws:
IllegalArgumentException- ifpeekeris null
-
filter
Filter results using the boolean expression produced by the given function.Adds to any previously specified filters.
- Parameters:
predicateBuilder- function mapping this stream's item to a booleanExpression- Returns:
- new filtered stream
- Throws:
IllegalArgumentException- ifpredicateBuilderis null
-
filter
Filter results using the specified boolean property.Adds to any previously specified filters.
- Parameters:
attribute- boolean property- Returns:
- new filtered stream
- Throws:
IllegalArgumentException- ifattributeis null
-
limit
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.).
- Parameters:
maxSize- maximum number of elements to return- Returns:
- new truncated stream
- Throws:
IllegalArgumentException- ifmaxSizeis negative
-
skip
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.).
- Parameters:
num- number of elements to skip- Returns:
- new elided stream
- Throws:
IllegalArgumentException- ifnumis negative
-
newBuilder
- Parameters:
entityManager- entity manager- Returns:
- new stream builder
- Throws:
IllegalArgumentException- ifentityManageris null
-