Class BeanQuerySession<T>
- Type Parameters:
T- The row (bean) type.
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
InMemoryBeanQuerySession,SqlBeanQuerySession
BeanQueryContext: the rows (or connection) to query, plus optional
per-request narrowing of the context's settings.
Open a session per request and close it with try-with-resources. A session is not thread-safe. Its public methods
are final: each validates the BeanQuery into a ResolvedQuery (throwing
BeanQuerySyntaxException for bad input) and then calls the engine's doXxx hook. Engine failures
throw BeanQueryExecutionException.
BeanQuerySession.Builder.restrictColumns(String...) only narrows the context's columns. The limit, cap and count-policy
overrides replace the context's values for this session (so they can also raise or remove a cap); they are for
trusted server-side callers only, never request data.
Example:
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBeanQuerySession.Builder<T,SELF extends BeanQuerySession.Builder<T, SELF>> The settings every engine's session builder shares. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBeanQuerySession(BeanQuerySession.Builder<T, ?> builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Releases whatever the session acquired.columns()Returns this session's columns, in order (the context's columns after anyrestriction).final CountsReturns both counts, whatever theCountPolicy.protected abstract CountsdoCount(ResolvedQuery query) Engine hook forcount(BeanQuery).doFind(ResolvedQuery query) Engine hook forfind(BeanQuery).doFindValues(ResolvedQuery query) Engine hook forfindValues(BeanQuery).doStream(ResolvedQuery query) Engine hook forstream(BeanQuery).doStreamValues(ResolvedQuery query) Engine hook forstreamValues(BeanQuery).Returns one page of matching rows, plus the counts theCountPolicyselects.findValues(BeanQuery query) Likefind(BeanQuery), but each row is a map of the viewed columns, in view order.Returns the context that created this session (throughBeanQueryContext.createSession()or an engine'sgetSession(...)shortcut).final intReturns the largest number of search clauses a query may use in this session: the context's cap, or this session'soverride.final intReturns the largest number of sort keys a query may use in this session: the context's cap, or this session'soverride.protected static <R> Page<R>page(List<R> rows, ResolvedQuery query, LongSupplier total, LongSupplier matched) Builds a page, computing only the counts the query'spolicyselects.final ResolvedQueryValidates a query against this session's rules without running it.Streams one page of matching rows.streamValues(BeanQuery query) Likestream(BeanQuery), but each row is a map of the viewed columns, in view order.
-
Constructor Details
-
BeanQuerySession
Constructor. Takes a private copy of the builder's settings and validates it.- Parameters:
builder- The builder. Must not benull .- Throws:
IllegalStateException- If the settings are invalid.
-
-
Method Details
-
columns
Returns this session's columns, in order (the context's columns after anyrestriction).- Returns:
- An unmodifiable list.
-
getContext
Returns the context that created this session (throughBeanQueryContext.createSession()or an engine'sgetSession(...)shortcut).Engines whose session builder is given a narrower context type (for example,
InMemoryBeanQuerySession) override this with a covariant return type.- Returns:
- The context. Never
null .
-
getMaxSearchClauses
Returns the largest number of search clauses a query may use in this session: the context's cap, or this session'soverride.- Returns:
- The cap.
-
getMaxSortKeys
Returns the largest number of sort keys a query may use in this session: the context's cap, or this session'soverride.- Returns:
- The cap.
-
resolve
Validates a query against this session's rules without running it.- Parameters:
query- The query. Must not benull .- Returns:
- The resolved query.
- Throws:
BeanQuerySyntaxException- If the query breaks a rule.
-
find
Returns one page of matching rows, plus the counts theCountPolicyselects.- Parameters:
query- The query. Must not benull .- Returns:
- The page.
- Throws:
BeanQuerySyntaxException- If the query breaks a rule.BeanQueryExecutionException- If the engine fails.
-
findValues
Likefind(BeanQuery), but each row is a map of the viewed columns, in view order.- Parameters:
query- The query. Must not benull .- Returns:
- The page.
- Throws:
BeanQuerySyntaxException- If the query breaks a rule.BeanQueryExecutionException- If the engine fails.
-
count
Returns both counts, whatever theCountPolicy. Sort, view and paging are ignored.- Parameters:
query- The query. Must not benull .- Returns:
- The counts.
- Throws:
BeanQuerySyntaxException- If the query breaks a rule.BeanQueryExecutionException- If the engine fails.
-
stream
Streams one page of matching rows. Close the stream (or the session) to release engine resources.- Parameters:
query- The query. Must not benull .- Returns:
- The rows.
- Throws:
BeanQuerySyntaxException- If the query breaks a rule.BeanQueryExecutionException- If the engine fails.
-
streamValues
Likestream(BeanQuery), but each row is a map of the viewed columns, in view order.- Parameters:
query- The query. Must not benull .- Returns:
- The rows.
- Throws:
BeanQuerySyntaxException- If the query breaks a rule.BeanQueryExecutionException- If the engine fails.
-
doFind
Engine hook forfind(BeanQuery).- Parameters:
query- The validated query.- Returns:
- The page. Build it with
page(List, ResolvedQuery, LongSupplier, LongSupplier).
-
doFindValues
Engine hook forfindValues(BeanQuery).- Parameters:
query- The validated query.- Returns:
- The page.
-
doCount
Engine hook forcount(BeanQuery).- Parameters:
query- The validated query.- Returns:
- The counts.
-
doStream
Engine hook forstream(BeanQuery).- Parameters:
query- The validated query.- Returns:
- The rows.
-
doStreamValues
Engine hook forstreamValues(BeanQuery).- Parameters:
query- The validated query.- Returns:
- The rows.
-
page
protected static <R> Page<R> page(List<R> rows, ResolvedQuery query, LongSupplier total, LongSupplier matched) Builds a page, computing only the counts the query'spolicyselects.- Type Parameters:
R- The row type.- Parameters:
rows- The page's rows.query- The validated query.total- Computes the total count. Called only underCountPolicy.BOTH.matched- Computes the matched count. Called only underCountPolicy.MATCHEDorCountPolicy.BOTH.- Returns:
- The page.
-
close
Releases whatever the session acquired. Never throws a checked exception.- Specified by:
closein interfaceAutoCloseable
-