Class BeanQuery

java.lang.Object
org.apache.juneau.commons.beanquery.BeanQuery
Direct Known Subclasses:
BeanQueryRequest

public class BeanQuery extends Object
A 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).

Every field is a plain raw value — there are no HTTP-binding annotations, no Optional, no search map, no page string, and no parsed operators on this bean. A null field means absent. The grammar for search and opts lives inside those single strings and is decoded by a session when the query runs, not by this bean.

Fields
  • search (String) — the one search string. Top-level commas (outside parentheses) separate clauses; the first unescaped = separates a column from its raw $-expression (SearchExpressionParser); backslash escapes \, / \= / \\ are literals. Columns combine with and. See ClauseParser.
  • view (String) — a comma-separated list of column names, in output order.
  • sort (String) — a comma-separated list of column (ascending) or column:desc tokens (a trailing -/+ is also accepted).
  • position (Integer) — the 0-based first row of the page, or null for the start.
  • limit (Integer) — the page size, or null for all rows.
  • opts (String) — an open bag of key=value clauses (same grammar as search). The session reads counts and ignores unknown keys.

Construct with create(), which returns a BeanQuery.Builder that assembles these raw strings fluently:

Example:

BeanQuery q = BeanQuery.create() .eq("status", "active") .or(g -> g.contains("name", "bob").contains("email", "bob")) .sort("name") .limit(50) .build();

The HTTP-binding BeanQueryRequest (juneau-rest-common) extends this class and adds the @Query bindings.

Since:
10.0.0
  • Constructor Details

  • Method Details

    • create

      public static BeanQuery.Builder create()
      Creates a new BeanQuery.Builder.
      Returns:
      A new builder.
    • getSearch

      public String getSearch()
      The one search string.
      Returns:
      The search string, or null if absent.
    • setSearch

      public BeanQuery setSearch(String value)
      Sets the one search string.
      Parameters:
      value - The search string. Can be null to unset.
      Returns:
      This object.
    • getView

      public String getView()
      The raw view (column-selection) directive.
      Returns:
      The view string, or null if absent.
    • setView

      public BeanQuery setView(String value)
      Sets the raw view (column-selection) directive.
      Parameters:
      value - The view string. Can be null to unset.
      Returns:
      This object.
    • getSort

      public String getSort()
      The raw sort directive.
      Returns:
      The sort string, or null if absent.
    • setSort

      public BeanQuery setSort(String value)
      Sets the raw sort directive.
      Parameters:
      value - The sort string. Can be null to unset.
      Returns:
      This object.
    • getPosition

      public Integer getPosition()
      The 0-based first row of the page.
      Returns:
      The position, or null for the start of the results.
    • setPosition

      public BeanQuery setPosition(Integer value)
      Sets the 0-based first row of the page.
      Parameters:
      value - The position. Can be null to unset.
      Returns:
      This object.
    • getLimit

      public Integer getLimit()
      The page size.
      Returns:
      The limit, or null for all rows.
    • setLimit

      public BeanQuery setLimit(Integer value)
      Sets the page size.
      Parameters:
      value - The limit. Can be null to unset (all rows).
      Returns:
      This object.
    • getOpts

      public String getOpts()
      The one opts string (an open bag of key=value clauses).
      Returns:
      The opts string, or null if absent.
    • setOpts

      public BeanQuery setOpts(String value)
      Sets the one opts string.
      Parameters:
      value - The opts string. Can be null to unset.
      Returns:
      This object.
    • copy

      Creates a BeanQuery.Builder pre-populated with this query's current state, so individual settings can be changed or added without disturbing the rest. getSearch() is re-parsed into the builder's item tree, so a new condition on an existing top-level column merges through $and(...) rather than being dropped or duplicated.
      Returns:
      A new builder seeded from this query.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object