Enum Class CountPolicy

java.lang.Object
java.lang.Enum<CountPolicy>
org.apache.juneau.commons.beanquery.CountPolicy
All Implemented Interfaces:
Serializable, Comparable<CountPolicy>, Constable

public enum CountPolicy extends Enum<CountPolicy>
Which counts a find / findValues call computes alongside its page of rows.

Set on BeanQueryContext.Builder.countPolicy(CountPolicy) and overridable per session with BeanQuerySession.Builder.countPolicy(CountPolicy). Counts can cost extra queries (two COUNT(*) statements on a SQL engine), so the default IF_REQUESTED lets the caller opt in while the server keeps the final say. BeanQuerySession.count(BeanQuery) always computes both counts regardless of the policy.

Example:

// Always return the matched count, whatever the caller asks for. InMemoryBeanQueryContext<Person> context = InMemoryBeanQueryContext .create(Person.class) .countPolicy(CountPolicy.MATCHED) .build(); try (InMemoryBeanQuerySession<Person> session = context.getSession(people)) { long matched = session.find(query).matched().getAsLong(); }

Since:
10.0.0
  • Enum Constant Details

    • NONE

      public static final CountPolicy NONE
      Never compute counts; Page.total() and Page.matched() are empty.
    • MATCHED

      public static final CountPolicy MATCHED
      Compute only the matched count (rows that pass the guards and the search).
    • BOTH

      public static final CountPolicy BOTH
      Compute both the total count (rows that pass the guards) and the matched count.
    • IF_REQUESTED

      public static final CountPolicy IF_REQUESTED
      Let the query decide through its opts: counts=matched → MATCHED; counts=both or counts=true → BOTH; anything else → NONE.

      A resolved query never carries this value; it is always replaced by one of the other three.

  • Method Details

    • values

      public static CountPolicy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static CountPolicy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null