Package org.apache.juneau.commons.beanquery
A BeanQuery carries only raw strings: one search string of
column=expression clauses in the $-language, plus raw view/sort directives, position/
limit, and an open opts bag. The clause grammar shared by search and opts is decoded
by ClauseParser; the single public
SearchExpressionParser then parses each clause's expression against a
SearchOperatorSet, throwing
BeanQuerySyntaxException on an unknown operator or a malformed
expression.
A BeanQueryContext is the immutable, thread-safe half: its columns,
operators and limits are fixed by a builder (create()...build(); copy() derives a variant). Per
request it opens a BeanQuerySession, which may narrow the columns,
override the limits and add a guard. Every query is validated into a
ResolvedQuery before any engine runs it; rule violations throw
BeanQuerySyntaxException (client error) and engine failures throw
BeanQueryExecutionException (server error). Results come back as
Pages with the counts the
CountPolicy selects.
The InMemoryBeanQueryContext runs against an in-JVM collection. SQL
engines live in separate modules: juneau-beanquery-sql supplies the shared JDBC context and the
SqlDialect hook under org.apache.juneau.beanquery.sql. Commons
carries the query API only, not the SQL dialect types.
Example:
-
ClassDescriptionA protocol-agnostic query request against a collection of beans: what to search, which columns to return, how to sort, and which page to return (design §5.1, §5.3).Builds an immutable
BeanQuery.A group of cross-column conditions built withBeanQuery.Builder.or(Consumer),BeanQuery.Builder.and(Consumer), orBeanQuery.Builder.not(Consumer).The reusable, immutable, server-side half of a BeanQuery engine: which columns may be searched, sorted and viewed, which operators apply, and the limits every session enforces.BeanQueryContext.Builder<T,SELF extends BeanQueryContext.Builder<T, SELF>> The settings every engine's context builder shares.A server-side failure while running a validBeanQuery: aSQLException, a connection failure, or a column accessor that throws.One unit of query work against aBeanQueryContext: the rows (or connection) to query, plus optional per-request narrowing of the context's settings.BeanQuerySession.Builder<T,SELF extends BeanQuerySession.Builder<T, SELF>> The settings every engine's session builder shares.Thrown when a$-search expression names an unknown operator or is otherwise malformed (an unclosed parenthesis, a wrong argument count, junk after the close paren, an empty expression, and so on), or when a higher-level check (column allow-list, sort keys, paging, regex policy, operator/type mismatch, an unparseable typed value) rejects a caller-supplied query.Stable identity for aBeanQuerySyntaxException, independent of the (free-text) message.Which counts afind/findValuescall computes alongside its page of rows.What a caller asksBeanQuery.Builder.counts(CountRequest)to write onto aBeanQuery'sopts(design §5).The two neutral row counts a session can report:Counts.total()(the rows in scope before the query's search) andCounts.matched()(the rows that survive the search, before any page limit).A resolved, engine-neutral search tree (design §7) — theResolvedQuery.filter()replacement for the earlier flatTerm/terms()list.An AND of two or more (or, at the top level, zero) sub-filters.One resolvedcolumn=expressionleaf, with the column'sSearchTypecarried alongside for the engine.The negation of exactly one sub-filter.An OR of two or more sub-filters.The in-memoryBeanQueryContext: runsBeanQuerys against an in-JVM collection of beans or maps.Builder forInMemoryBeanQueryContext.ABeanQuerySessionover one in-memory collection.Builder forInMemoryBeanQuerySession.Page<T>One page of query results, plus the optional counts selected by the session'sCountPolicy.QueryModel<T>The query view of a bean class: its readable properties (query columns), its writable properties, and how to create an instance.One bean property as BeanQuery sees it: its column name, value type and inferredSearchType, and how to read and write it.A signed, relative-to-request-time duration value: wire literal[+-]<n>(ms|s|m|h|d)(a request-time offset that stays a plain literal on the wire).The duration unit, with its lowercase wire token (design review §3 Gap 2).ABeanQueryafter validation: the engine-neutral input to every engine hook.One sort key: its column, the column's value type, and the direction.One node of the parse tree produced bySearchExpressionParser: the resolved, validated form of a column's$-search expression that a context walks to filter rows or build SQL.The single public parser for the$-search language (design §5.1).The immutable definition of a single$-search operator — its$-name, arity, the value types it applies to, and its popup help text.Builder forSearchOperator.An immutable, ordered collection ofSearchOperators that governs which$-operators the parser recognizes.The leaf predicate an application supplies for a custom search operator so the in-memory context can evaluate it against a cell value (design §5.3).The per-column value type that governs which search operators apply to a column and how a bare (no leading$) pattern token is interpreted.