Class BeanQueryContext<T>

java.lang.Object
org.apache.juneau.commons.beanquery.BeanQueryContext<T>
Type Parameters:
T - The row (bean) type.
Direct Known Subclasses:
InMemoryBeanQueryContext, SqlBeanQueryContext

public abstract class BeanQueryContext<T> extends Object
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.

Build a context once, at startup, from its engine's create(...) factory. It holds no rows and no connections, so it can be shared across threads. Open a BeanQuerySession per request with the engine's getSession(...) shortcut or with createSession(). Call copy() to derive a variant.

The base class owns every engine-independent check (spec ยง5): the column allow-list, operator/type checks, the regex gate, the size caps, limit clamping and the count policy. Engines see only a ResolvedQuery.

Example:

// Once, at startup. InMemoryBeanQueryContext<Person> people = InMemoryBeanQueryContext .create(Person.class) // Columns: every getter on Person. .exclude("passwordHash") // Never searchable, sortable or visible. .column("version", SearchType.VERSION) .maxLimit(500) .build(); // A stricter variant for a public page. InMemoryBeanQueryContext<Person> guest = people.copy().allowRegex(false).defaultLimit(50).maxLimit(50).build(); // Per request. try (InMemoryBeanQuerySession<Person> session = people.getSession(rows)) { Page<Person> page = session.find(query); }

Since:
10.0.0
  • Constructor Details

  • Method Details

    • columns

      public final List<String> columns()
      Returns the declared columns, in order: the allow-list for search, sort and view, and the default view.
      Returns:
      An unmodifiable list.
    • operatorSet

      Returns the default operator set a client may use. $regex is absent if regex is disallowed.
      Returns:
      The operator set.
    • operatorSet

      public final SearchOperatorSet operatorSet(String column)
      Returns the operator set a client may use on one column. $regex is absent if regex is disallowed.
      Parameters:
      column - The column name.
      Returns:
      The column's operator set, else the default set.
    • getColumnType

      public final SearchType getColumnType(String name)
      Returns the type stored for a declared column: the type given to column, or the type inferred for it (for example, InMemoryBeanQueryContext.create(Class) infers one per bean getter).
      Parameters:
      name - The column name.
      Returns:
      The column's type. Never null.
      Throws:
      IllegalArgumentException - If the column is not declared.
    • getMaxSearchClauses

      public final int getMaxSearchClauses()
      Returns the largest number of search clauses a query may use.
      Returns:
      The cap.
    • getMaxSortKeys

      public final int getMaxSortKeys()
      Returns the largest number of sort keys a query may use.
      Returns:
      The cap.
    • resolve

      public final ResolvedQuery resolve(BeanQuery query)
      Validates a query against this context's rules without running it.
      Parameters:
      query - The query. Must not be null.
      Returns:
      The resolved query.
      Throws:
      BeanQuerySyntaxException - If the query breaks a rule.
    • checkOrigin

      protected final void checkOrigin(ResolvedQuery query)
      Confirms that query was produced by resolving against this context (directly, or through a session built from it) before an engine uses it. An engine's rendering/execution code that accepts a caller-supplied ResolvedQuery — rather than one it just resolved itself — calls this first, so a query resolved against a different context's columns is rejected with a clear message instead of silently rendering (or running) against the wrong schema.
      Parameters:
      query - The query to check. Must not be null.
      Throws:
      IllegalArgumentException - If query was not produced by this context.
    • copy

      public abstract BeanQueryContext.Builder<T,?> copy()
      Returns a builder initialized from this context. Building it leaves this context unchanged.
      Returns:
      A new builder.
    • createSession

      Returns a builder for a session over this context.
      Returns:
      A new session builder.