Class QueryBean<T,R extends QueryBean<T,R>>

java.lang.Object
io.ebean.typequery.QueryBean<T,R>
Type Parameters:
T - the entity bean type (normal entity bean type e.g. Customer)
R - the specific root query bean type (e.g. QCustomer)
All Implemented Interfaces:
io.ebean.QueryBuilder<R,T>, io.ebean.QueryBuilderProjection<R,T>, IQueryBean<T,R>

@NullMarked public abstract class QueryBean<T,R extends QueryBean<T,R>> extends Object implements IQueryBean<T,R>
Base root query bean providing common features for all root query beans.

For each entity bean querybean-generator generates a query bean that extends TQRootBean.

Example - usage of QCustomer



  Date fiveDaysAgo = ...

  List<Customer> customers =
      new QCustomer()
        .name.ilike("rob")
        .status.equalTo(Customer.Status.GOOD)
        .registered.after(fiveDaysAgo)
        .contacts.email.endsWith("@foo.com")
        .orderBy()
          .name.asc()
          .registered.desc()
        .findList();

 

Resulting SQL where



   where lower(t0.name) like ?  and t0.status = ?  and t0.registered > ?  and u1.email like ?
   order by t0.name, t0.registered desc;

   --bind(rob,GOOD,Mon Jul 27 12:05:37 NZST 2015,%@foo.com)

 
  • Constructor Details

    • QueryBean

      protected QueryBean(Class<T> beanType)
      Construct using the type of bean to query on and the default database.
    • QueryBean

      protected QueryBean(Class<T> beanType, io.ebean.Database database)
      Construct using the type of bean to query on and a given database.
    • QueryBean

      protected QueryBean(io.ebean.Query<T> query)
      Construct using a query.
    • QueryBean

      protected QueryBean(boolean aliasDummy)
      Construct for using as an 'Alias' to use the properties as known string values for select() and fetch().
    • QueryBean

      protected QueryBean(io.ebean.ExpressionList<T> filter)
      Construct for FilterMany
  • Method Details

    • setRoot

      protected void setRoot(R root)
      The enhancement will no longer use this method. Will be removed once the new IntelliJ plugin is released.
    • buildFetchGroup

      public io.ebean.FetchGroup<T> buildFetchGroup()
      Description copied from interface: IQueryBean
      Return the fetch group.
      Specified by:
      buildFetchGroup in interface IQueryBean<T,R extends QueryBean<T,R>>
    • query

      public io.ebean.Query<T> query()
      Description copied from interface: IQueryBean
      Return the underlying query.

      Generally it is not expected that you will need to do this but typically use the find methods available on this 'root query bean' instance like findList().

      Specified by:
      query in interface IQueryBean<T,R extends QueryBean<T,R>>
    • distinctOn

      public R distinctOn(String distinctOn)
      Specified by:
      distinctOn in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • select

      public R select(String properties)
      Specified by:
      select in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • select

      public R select(io.ebean.FetchGroup<T> fetchGroup)
      Specified by:
      select in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • distinctOn

      @SafeVarargs public final R distinctOn(TQProperty<R,?>... properties)
      Description copied from interface: IQueryBean
      Set DISTINCT ON properties. This is a Postgres only SQL feature.
      Specified by:
      distinctOn in interface IQueryBean<T,R extends QueryBean<T,R>>
      Parameters:
      properties - The properties to include in the DISTINCT ON clause.
    • select

      @SafeVarargs public final R select(TQProperty<R,?>... properties)
      Description copied from interface: IQueryBean
      Specify the properties to be loaded on the 'main' root level entity bean.

      The resulting entities with be "partially loaded" aka partial objects.

      Alternatively we can use a QueryBuilderProjection.select(FetchGroup) to specify all properties to load on all parts of the graph.

      
      
         // alias for the customer properties in select()
         QCustomer cust = QCustomer.alias();
      
         // alias for the contact properties in contacts.fetch()
         QContact contact = QContact.alias();
      
         List<Customer> customers =
           new QCustomer()
             // specify the parts of the graph we want to load
             .select(cust.id, cust.name)
             .contacts.fetch(contact.firstName, contact.lastName, contact.email)
      
             // predicates
             .id.gt(1)
             .findList();
      
       
      Specified by:
      select in interface IQueryBean<T,R extends QueryBean<T,R>>
      Parameters:
      properties - the list of properties to fetch
    • select

      public final R select(io.ebean.Query.Property<?>... properties)
      Description copied from interface: IQueryBean
      Specify the properties to be loaded on the 'main' root level entity bean also allowing for functions to be used like StdOperators.max(Query.Property).
      Specified by:
      select in interface IQueryBean<T,R extends QueryBean<T,R>>
      Parameters:
      properties - the list of properties to fetch
    • fetch

      public final R fetch(String path)
      Specified by:
      fetch in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetchQuery

      public final R fetchQuery(String path)
      Specified by:
      fetchQuery in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetchCache

      public final R fetchCache(String path)
      Specified by:
      fetchCache in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetchQuery

      public final R fetchQuery(String path, String properties)
      Specified by:
      fetchQuery in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetchCache

      public final R fetchCache(String path, String properties)
      Specified by:
      fetchCache in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetch

      public final R fetch(String path, String properties)
      Specified by:
      fetch in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetch

      public final R fetch(String path, String properties, io.ebean.FetchConfig fetchConfig)
      Specified by:
      fetch in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetch

      public final R fetch(String path, io.ebean.FetchConfig fetchConfig)
      Specified by:
      fetch in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetchLazy

      public R fetchLazy(String path, String fetchProperties)
      Specified by:
      fetchLazy in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • fetchLazy

      public R fetchLazy(String path)
      Specified by:
      fetchLazy in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • apply

      public final R apply(io.ebean.FetchPath pathProperties)
      Specified by:
      apply in interface io.ebean.QueryBuilderProjection<T,R extends QueryBean<T,R>>
    • also

      public final R also(Consumer<R> apply)
      Specified by:
      also in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • alsoIf

      public final R alsoIf(BooleanSupplier predicate, Consumer<R> apply)
      Specified by:
      alsoIf in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • asOf

      public final R asOf(Timestamp asOf)
      Specified by:
      asOf in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • asDraft

      public final R asDraft()
      Specified by:
      asDraft in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setIncludeSoftDeletes

      public final R setIncludeSoftDeletes()
      Specified by:
      setIncludeSoftDeletes in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • add

      public final R add(io.ebean.Expression expression)
      Description copied from interface: IQueryBean
      Add an expression to the WHERE or HAVING clause.
      Specified by:
      add in interface IQueryBean<T,R extends QueryBean<T,R>>
    • alias

      public final R alias(String alias)
      Specified by:
      alias in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setPaging

      public R setPaging(io.ebean.Paging paging)
      Specified by:
      setPaging in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setMaxRows

      public final R setMaxRows(int maxRows)
      Specified by:
      setMaxRows in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setFirstRow

      public final R setFirstRow(int firstRow)
      Specified by:
      setFirstRow in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setAllowLoadErrors

      public final R setAllowLoadErrors()
      Specified by:
      setAllowLoadErrors in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setAutoTune

      public final R setAutoTune(boolean autoTune)
      Specified by:
      setAutoTune in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setBufferFetchSizeHint

      public final R setBufferFetchSizeHint(int fetchSize)
      Specified by:
      setBufferFetchSizeHint in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setDistinct

      public final R setDistinct(boolean distinct)
      Specified by:
      setDistinct in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setDocIndexName

      public final R setDocIndexName(String indexName)
      Specified by:
      setDocIndexName in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setInheritType

      public final R setInheritType(Class<? extends T> type)
      Specified by:
      setInheritType in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setBaseTable

      public final R setBaseTable(String baseTable)
      Specified by:
      setBaseTable in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • withLock

      public final R withLock(io.ebean.Query.LockType lockType)
      Specified by:
      withLock in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • withLock

      public final R withLock(io.ebean.Query.LockType lockType, io.ebean.Query.LockWait lockWait)
      Specified by:
      withLock in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • exists

      public final R exists(io.ebean.Query<?> subQuery)
      Description copied from interface: IQueryBean
      Add EXISTS sub-query predicate.
      Specified by:
      exists in interface IQueryBean<T,R extends QueryBean<T,R>>
    • notExists

      public final R notExists(io.ebean.Query<?> subQuery)
      Description copied from interface: IQueryBean
      Add NOT EXISTS sub-query predicate.
      Specified by:
      notExists in interface IQueryBean<T,R extends QueryBean<T,R>>
    • exists

      public final R exists(String sqlSubQuery, Object... bindValues)
      Description copied from interface: IQueryBean
      EXISTS using a SQL SubQuery.
      Specified by:
      exists in interface IQueryBean<T,R extends QueryBean<T,R>>
      Parameters:
      sqlSubQuery - The SQL SubQuery
      bindValues - Optional bind values if the SubQuery uses ? bind values.
    • notExists

      public final R notExists(String sqlSubQuery, Object... bindValues)
      Description copied from interface: IQueryBean
      Not EXISTS using a SQL SubQuery.
      Specified by:
      notExists in interface IQueryBean<T,R extends QueryBean<T,R>>
      Parameters:
      sqlSubQuery - The SQL SubQuery
      bindValues - Optional bind values if the SubQuery uses ? bind values.
    • forUpdate

      public final R forUpdate()
      Specified by:
      forUpdate in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • forUpdateNoWait

      public final R forUpdateNoWait()
      Specified by:
      forUpdateNoWait in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • forUpdateSkipLocked

      public final R forUpdateSkipLocked()
      Specified by:
      forUpdateSkipLocked in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • asUpdate

      public final io.ebean.UpdateQuery<T> asUpdate()
      Specified by:
      asUpdate in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • asDto

      public final <D> io.ebean.DtoQuery<D> asDto(Class<D> dtoClass)
      Specified by:
      asDto in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setId

      public final R setId(Object id)
      Description copied from interface: IQueryBean
      Set the Id value to query. This is used with findOne().

      You can use this to have further control over the query. For example adding fetch joins.

      
      
       Order order =
         new QOrder()
           .setId(1)
           .fetch("details")
           .findOne();
      
       // the order details were eagerly fetched
       List<OrderDetail> details = order.getDetails();
      
       
      Specified by:
      setId in interface IQueryBean<T,R extends QueryBean<T,R>>
    • setIdIn

      public final R setIdIn(Object... ids)
      Description copied from interface: IQueryBean
      Set a list of Id values to match.

      
      
       List<Order> orders =
         new QOrder()
           .setIdIn(42, 43, 44)
           .findList();
      
       
      Specified by:
      setIdIn in interface IQueryBean<T,R extends QueryBean<T,R>>
    • setIdIn

      public final R setIdIn(Collection<?> ids)
      Description copied from interface: IQueryBean
      Set a collection of Id values to match.

      
      
       Collection<?> ids = ...
      
       List<Order> orders =
         new QOrder()
           .setIdIn(ids)
           .findList();
      
       
      Specified by:
      setIdIn in interface IQueryBean<T,R extends QueryBean<T,R>>
    • setLabel

      public final R setLabel(String label)
      Specified by:
      setLabel in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setHint

      public final R setHint(String hint)
      Specified by:
      setHint in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setProfileLocation

      public final R setProfileLocation(io.ebean.ProfileLocation profileLocation)
      Description copied from interface: IQueryBean
      Set the profile location of this query. This is used to relate query execution metrics back to a location like a specific line of code.
      Specified by:
      setProfileLocation in interface IQueryBean<T,R extends QueryBean<T,R>>
    • setLazyLoadBatchSize

      public final R setLazyLoadBatchSize(int lazyLoadBatchSize)
      Specified by:
      setLazyLoadBatchSize in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setMapKey

      public final R setMapKey(String mapKey)
      Specified by:
      setMapKey in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setPersistenceContextScope

      public final R setPersistenceContextScope(io.ebean.PersistenceContextScope scope)
      Specified by:
      setPersistenceContextScope in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setCountDistinct

      public R setCountDistinct(io.ebean.CountDistinctOrder orderBy)
      Specified by:
      setCountDistinct in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setRawSql

      public final R setRawSql(io.ebean.RawSql rawSql)
      Specified by:
      setRawSql in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setUnmodifiable

      public R setUnmodifiable(boolean unmodifiable)
      Specified by:
      setUnmodifiable in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setBeanCacheMode

      public final R setBeanCacheMode(io.ebean.CacheMode beanCacheMode)
      Specified by:
      setBeanCacheMode in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setUseDocStore

      public final R setUseDocStore(boolean useDocStore)
      Specified by:
      setUseDocStore in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setDisableLazyLoading

      public final R setDisableLazyLoading(boolean disableLazyLoading)
      Specified by:
      setDisableLazyLoading in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setDisableReadAuditing

      public final R setDisableReadAuditing()
      Specified by:
      setDisableReadAuditing in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setUseQueryCache

      public final R setUseQueryCache(io.ebean.CacheMode cacheMode)
      Specified by:
      setUseQueryCache in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setTimeout

      public final R setTimeout(int secs)
      Specified by:
      setTimeout in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • validate

      public final Set<String> validate()
      Specified by:
      validate in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • raw

      public final R raw(String rawExpression)
      Description copied from interface: IQueryBean
      Add raw expression with no parameters.

      When properties in the clause are fully qualified as table-column names then they are not translated. logical property name names (not fully qualified) will still be translated to their physical name.

      
      
         raw("orderQty < shipQty")
      
       

      Subquery example:

      
      
         .raw("t0.customer_id in (select customer_id from customer_group where group_id = any(?::uuid[]))", groupIds)
      
       
      Specified by:
      raw in interface IQueryBean<T,R extends QueryBean<T,R>>
    • raw

      public final R raw(String rawExpression, Object... bindValues)
      Description copied from interface: IQueryBean
      Add raw expression with an array of parameters.

      The raw expression should contain the same number of ? as there are parameters.

      When properties in the clause are fully qualified as table-column names then they are not translated. logical property name names (not fully qualified) will still be translated to their physical name.

      Specified by:
      raw in interface IQueryBean<T,R extends QueryBean<T,R>>
    • rawOrEmpty

      public final R rawOrEmpty(String raw, Collection<?> values)
      Description copied from interface: IQueryBean
      Only add the raw expression if the values is not null or empty.

      This is a pure convenience expression to make it nicer to deal with the pattern where we use raw() expression with a subquery and only want to add the subquery predicate when the collection of values is not empty.

      Without inOrEmpty()

      
      
         QCustomer query = new QCustomer() // add some predicates
           .status.equalTo(Status.NEW);
      
         // common pattern - we can use rawOrEmpty() instead
         if (orderIds != null && !orderIds.isEmpty()) {
           query.raw("t0.customer_id in (select o.customer_id from orders o where o.id in (?1))", orderIds);
         }
      
         query.findList();
      
       

      Using rawOrEmpty()

      Note that in the example below we use the ?1 bind parameter to get "parameter expansion" for each element in the collection.
      
      
         new QCustomer()
           .status.equalTo(Status.NEW)
           // only add the expression if orderIds is not empty
           .rawOrEmpty("t0.customer_id in (select o.customer_id from orders o where o.id in (?1))", orderIds);
           .findList();
      
       

      Postgres ANY

      With Postgres we would often use the SQL ANY expression and array parameter binding rather than IN.
      
      
         new QCustomer()
           .status.equalTo(Status.NEW)
           .rawOrEmpty("t0.customer_id in (select o.customer_id from orders o where o.id = any(?))", orderIds);
           .findList();
      
       

      Note that we need to cast the Postgres array for UUID types like:

      
      
         " ... = any(?::uuid[])"
      
       
      Specified by:
      rawOrEmpty in interface IQueryBean<T,R extends QueryBean<T,R>>
      Parameters:
      raw - The raw expression that is typically a subquery
      values - The values which is typically a list or set of id values.
    • raw

      public final R raw(String rawExpression, Object bindValue)
      Description copied from interface: IQueryBean
      Add raw expression with a single parameter.

      The raw expression should contain a single ? at the location of the parameter.

      When properties in the clause are fully qualified as table-column names then they are not translated. logical property name names (not fully qualified) will still be translated to their physical name.

      Example:

      
      
         // use a database function
         raw("add_days(orderDate, 10) < ?", someDate)
      
       

      Subquery example:

      
      
         .raw("t0.customer_id in (select customer_id from customer_group where group_id = any(?::uuid[]))", groupIds)
      
       
      Specified by:
      raw in interface IQueryBean<T,R extends QueryBean<T,R>>
    • inTuples

      public final R inTuples(io.ebean.InTuples inTuples)
      Description copied from interface: IQueryBean
      In expression using multiple columns.
      Specified by:
      inTuples in interface IQueryBean<T,R extends QueryBean<T,R>>
    • orderBy

      public final R orderBy()
      Description copied from interface: IQueryBean
      Marker that can be used to indicate that the order by clause is defined after this.

      Example: order by customer name, order date

      
         List<Order> orders =
                new QOrder()
                  .customer.name.ilike("rob")
                  .orderBy()
                    .customer.name.asc()
                    .orderDate.asc()
                  .findList();
      
       
      Specified by:
      orderBy in interface IQueryBean<T,R extends QueryBean<T,R>>
    • order

      @Deprecated(since="13.19", forRemoval=true) public final R order()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      order in interface IQueryBean<T,R extends QueryBean<T,R>>
    • orderBy

      public final R orderBy(String orderByClause)
      Specified by:
      orderBy in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • setOrderBy

      public R setOrderBy(io.ebean.OrderBy<T> orderBy)
      Specified by:
      setOrderBy in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • orderById

      public R orderById(boolean orderById)
      Specified by:
      orderById in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • order

      @Deprecated(since="13.19", forRemoval=true) public final R order(String orderByClause)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      order in interface IQueryBean<T,R extends QueryBean<T,R>>
    • or

      public final R or()
      Description copied from interface: IQueryBean
      Begin a list of expressions added by 'OR'.

      Use endOr() or endJunction() to stop added to OR and 'pop' to the parent expression list.

      Example

      This example uses an 'OR' expression list with an inner 'AND' expression list.

      
      
          List<Customer> customers =
                new QCustomer()
                  .status.equalTo(Customer.Status.GOOD)
                  .or()
                    .id.greaterThan(1000)
                    .and()
                      .name.startsWith("super")
                      .registered.after(fiveDaysAgo)
                    .endAnd()
                  .endOr()
                  .orderBy().id.desc()
                  .findList();
      
       

      Resulting SQL where clause

      sql
      
          where t0.status = ?  and (t0.id > ?  or (t0.name like ?  and t0.registered > ? ) )
          order by t0.id desc;
      
          --bind(GOOD,1000,super%,Wed Jul 22 00:00:00 NZST 2015)
      
       
      Specified by:
      or in interface IQueryBean<T,R extends QueryBean<T,R>>
    • and

      public final R and()
      Description copied from interface: IQueryBean
      Begin a list of expressions added by 'AND'.

      Use endAnd() or endJunction() to stop added to AND and 'pop' to the parent expression list.

      Note that typically the AND expression is only used inside an outer 'OR' expression. This is because the top level expression list defaults to an 'AND' expression list.

      Example

      This example uses an 'OR' expression list with an inner 'AND' expression list.

      
      
          List<Customer> customers =
                new QCustomer()
                  .status.equalTo(Customer.Status.GOOD)
                  .or() // OUTER 'OR'
                    .id.greaterThan(1000)
                    .and()  // NESTED 'AND' expression list
                      .name.startsWith("super")
                      .registered.after(fiveDaysAgo)
                      .endAnd()
                    .endOr()
                  .orderBy().id.desc()
                  .findList();
      
       

      Resulting SQL where clause

      sql
      
          where t0.status = ?  and (t0.id > ?  or (t0.name like ?  and t0.registered > ? ) )
          order by t0.id desc;
      
          --bind(GOOD,1000,super%,Wed Jul 22 00:00:00 NZST 2015)
      
       
      Specified by:
      and in interface IQueryBean<T,R extends QueryBean<T,R>>
    • not

      public final R not()
      Description copied from interface: IQueryBean
      Begin a list of expressions added by NOT.

      Use endNot() or endJunction() to stop added to NOT and 'pop' to the parent expression list.

      Specified by:
      not in interface IQueryBean<T,R extends QueryBean<T,R>>
    • must

      public final R must()
      Description copied from interface: IQueryBean
      Begin a list of expressions added by MUST.

      This automatically makes this query a document store query.

      Use endJunction() to stop added to MUST and 'pop' to the parent expression list.

      Specified by:
      must in interface IQueryBean<T,R extends QueryBean<T,R>>
    • mustNot

      public final R mustNot()
      Description copied from interface: IQueryBean
      Begin a list of expressions added by MUST NOT.

      This automatically makes this query a document store query.

      Use endJunction() to stop added to MUST NOT and 'pop' to the parent expression list.

      Specified by:
      mustNot in interface IQueryBean<T,R extends QueryBean<T,R>>
    • should

      public final R should()
      Description copied from interface: IQueryBean
      Begin a list of expressions added by SHOULD.

      This automatically makes this query a document store query.

      Use endJunction() to stop added to SHOULD and 'pop' to the parent expression list.

      Specified by:
      should in interface IQueryBean<T,R extends QueryBean<T,R>>
    • endJunction

      public final R endJunction()
      Description copied from interface: IQueryBean
      End a list of expressions added by 'OR'.
      Specified by:
      endJunction in interface IQueryBean<T,R extends QueryBean<T,R>>
    • endOr

      public final R endOr()
      Description copied from interface: IQueryBean
      End OR junction - synonym for endJunction().
      Specified by:
      endOr in interface IQueryBean<T,R extends QueryBean<T,R>>
    • endAnd

      public final R endAnd()
      Description copied from interface: IQueryBean
      End AND junction - synonym for endJunction().
      Specified by:
      endAnd in interface IQueryBean<T,R extends QueryBean<T,R>>
    • endNot

      public final R endNot()
      Description copied from interface: IQueryBean
      End NOT junction - synonym for endJunction().
      Specified by:
      endNot in interface IQueryBean<T,R extends QueryBean<T,R>>
    • where

      public final R where()
      Description copied from interface: IQueryBean
      Add expression after this to the WHERE expression list.

      For queries against the normal database (not the doc store) this has no effect.

      This is intended for use with Document Store / ElasticSearch where expressions can be put into either the "query" section or the "filter" section of the query. Full text expressions like MATCH are in the "query" section but many expression can be in either - expressions after the where() are put into the "filter" section which means that they don't add to the relevance and are also cache-able.

      Specified by:
      where in interface IQueryBean<T,R extends QueryBean<T,R>>
    • text

      public final R text()
      Description copied from interface: IQueryBean
      Begin added expressions to the 'Text' expression list.

      This automatically makes the query a document store query.

      For ElasticSearch expressions added to 'text' go into the ElasticSearch 'query context' and expressions added to 'where' go into the ElasticSearch 'filter context'.

      Specified by:
      text in interface IQueryBean<T,R extends QueryBean<T,R>>
    • multiMatch

      public final R multiMatch(String query, io.ebean.search.MultiMatch multiMatch)
      Description copied from interface: IQueryBean
      Add a Text Multi-match expression (document store only).

      This automatically makes the query a document store query.

      Specified by:
      multiMatch in interface IQueryBean<T,R extends QueryBean<T,R>>
    • multiMatch

      public final R multiMatch(String query, String... properties)
      Description copied from interface: IQueryBean
      Add a Text Multi-match expression (document store only).

      This automatically makes the query a document store query.

      Specified by:
      multiMatch in interface IQueryBean<T,R extends QueryBean<T,R>>
    • textCommonTerms

      public final R textCommonTerms(String query, io.ebean.search.TextCommonTerms options)
      Description copied from interface: IQueryBean
      Add a Text common terms expression (document store only).

      This automatically makes the query a document store query.

      Specified by:
      textCommonTerms in interface IQueryBean<T,R extends QueryBean<T,R>>
    • textSimple

      public final R textSimple(String query, io.ebean.search.TextSimple options)
      Description copied from interface: IQueryBean
      Add a Text simple expression (document store only).

      This automatically makes the query a document store query.

      Specified by:
      textSimple in interface IQueryBean<T,R extends QueryBean<T,R>>
    • textQueryString

      public final R textQueryString(String query, io.ebean.search.TextQueryString options)
      Description copied from interface: IQueryBean
      Add a Text query string expression (document store only).

      This automatically makes the query a document store query.

      Specified by:
      textQueryString in interface IQueryBean<T,R extends QueryBean<T,R>>
    • usingTransaction

      public final R usingTransaction(io.ebean.Transaction transaction)
      Specified by:
      usingTransaction in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • usingConnection

      public final R usingConnection(Connection connection)
      Specified by:
      usingConnection in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • usingDatabase

      public R usingDatabase(io.ebean.Database database)
      Specified by:
      usingDatabase in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • usingMaster

      public final R usingMaster()
      Specified by:
      usingMaster in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • exists

      public final boolean exists()
      Specified by:
      exists in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findOne

      public final @Nullable T findOne()
      Specified by:
      findOne in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findOneOrEmpty

      public final Optional<T> findOneOrEmpty()
      Specified by:
      findOneOrEmpty in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findList

      public final List<T> findList()
      Specified by:
      findList in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findStream

      public final Stream<T> findStream()
      Specified by:
      findStream in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findSet

      public final Set<T> findSet()
      Specified by:
      findSet in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findIds

      public final <A> List<A> findIds()
      Specified by:
      findIds in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findMap

      public final <K> Map<K,T> findMap()
      Specified by:
      findMap in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findIterate

      public final io.ebean.QueryIterator<T> findIterate()
      Specified by:
      findIterate in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findSingleAttributeList

      public final <A> List<A> findSingleAttributeList()
      Specified by:
      findSingleAttributeList in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findSingleAttributeSet

      public final <A> Set<A> findSingleAttributeSet()
      Specified by:
      findSingleAttributeSet in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findSingleAttribute

      public final <A> @Nullable A findSingleAttribute()
      Specified by:
      findSingleAttribute in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findSingleAttributeOrEmpty

      public final <A> Optional<A> findSingleAttributeOrEmpty()
      Specified by:
      findSingleAttributeOrEmpty in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findEach

      public final void findEach(Consumer<T> consumer)
      Specified by:
      findEach in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findEach

      public final void findEach(int batch, Consumer<List<T>> consumer)
      Specified by:
      findEach in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findEachWhile

      public final void findEachWhile(Predicate<T> consumer)
      Specified by:
      findEachWhile in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findVersions

      public final List<io.ebean.Version<T>> findVersions()
      Specified by:
      findVersions in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findVersionsBetween

      public final List<io.ebean.Version<T>> findVersionsBetween(Timestamp start, Timestamp end)
      Specified by:
      findVersionsBetween in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findCount

      public final int findCount()
      Specified by:
      findCount in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findFutureCount

      public final io.ebean.FutureRowCount<T> findFutureCount()
      Specified by:
      findFutureCount in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findFutureIds

      public final io.ebean.FutureIds<T> findFutureIds()
      Specified by:
      findFutureIds in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findFutureList

      public final io.ebean.FutureList<T> findFutureList()
      Specified by:
      findFutureList in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findFutureMap

      public final <K> io.ebean.FutureMap<K,T> findFutureMap()
      Specified by:
      findFutureMap in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • findPagedList

      public final io.ebean.PagedList<T> findPagedList()
      Specified by:
      findPagedList in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • delete

      public final int delete()
      Specified by:
      delete in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • getGeneratedSql

      public final String getGeneratedSql()
      Specified by:
      getGeneratedSql in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • getBeanType

      public final Class<T> getBeanType()
      Specified by:
      getBeanType in interface io.ebean.QueryBuilder<T,R extends QueryBean<T,R>>
    • getExpressionList

      public final io.ebean.ExpressionList<T> getExpressionList()
      Description copied from interface: IQueryBean
      Return the expression list that has been built for this query.
      Specified by:
      getExpressionList in interface IQueryBean<T,R extends QueryBean<T,R>>
    • having

      public final R having()
      Description copied from interface: IQueryBean
      Start adding expressions to the having clause when using @Aggregation properties.
      
      
         new QMachineUse()
         // where ...
         .date.inRange(fromDate, toDate)
      
         .having()
         .sumHours.greaterThan(1)
         .findList()
      
         // The sumHours property uses @Aggregation
         // e.g. @Aggregation("sum(hours)")
      
       
      Specified by:
      having in interface IQueryBean<T,R extends QueryBean<T,R>>
    • havingClause

      public final io.ebean.ExpressionList<T> havingClause()
      Description copied from interface: IQueryBean
      Return the underlying having clause to typically when using dynamic aggregation formula.

      Note that after this we no longer have the query bean so typically we use this right at the end of the query.

      
      
        // sum(distanceKms) ... is a "dynamic formula"
        // so we use havingClause() for it like:
      
        List<MachineUse> machineUse =
      
          new QMachineUse()
            .select("machine, sum(fuelUsed), sum(distanceKms)")
      
            // where ...
            .date.greaterThan(LocalDate.now().minusDays(7))
      
            .havingClause()
              .gt("sum(distanceKms)", 2)
              .findList();
      
       
      Specified by:
      havingClause in interface IQueryBean<T,R extends QueryBean<T,R>>
    • peekExprList

      protected final io.ebean.ExpressionList<T> peekExprList()
      Return the current expression list that expressions should be added to.
    • _peekText

      protected final io.ebean.ExpressionList<T> _peekText()