Module io.ebean.api
Package io.ebean

Interface QueryBuilderProjection<SELF,T>

Type Parameters:
SELF - The builder type
T - The entity bean type
All Known Subinterfaces:
Query<T>, QueryBuilder<SELF,T>, SpiFetchGroupQuery<T>

public interface QueryBuilderProjection<SELF,T>
Builder for ORM Query projection (the select and fetch part).
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(FetchPath fetchPath)
    Apply the path properties replacing the select and fetch clauses.
    distinctOn(String distinctOn)
    Set DISTINCT ON clause.
    fetch(String path)
    Specify a path to fetch eagerly including all its properties.
    fetch(String path, FetchConfig fetchConfig)
    Additionally specify a JoinConfig to specify a "query join" and or define the lazy loading query.
    fetch(String path, String fetchProperties)
    Specify a path to fetch eagerly including specific properties.
    fetch(String path, String fetchProperties, FetchConfig fetchConfig)
    Additionally specify a FetchConfig to use a separate query or lazy loading to load this path.
    Fetch the path eagerly using L2 cache.
    fetchCache(String path, String fetchProperties)
    Fetch the path and properties using L2 bean cache.
    Fetch the path lazily (via batch lazy loading).
    fetchLazy(String path, String fetchProperties)
    Fetch the path and properties lazily (via batch lazy loading).
    Fetch the path eagerly using a "query join" (separate SQL query).
    fetchQuery(String path, String fetchProperties)
    Fetch the path and properties using a "query join" (separate SQL query).
    select(FetchGroup<T> fetchGroup)
    Apply the fetchGroup which defines what part of the object graph to load.
    select(String fetchProperties)
    Specify the properties to fetch on the root level entity bean in comma delimited format.
  • Method Details

    • apply

      SELF apply(FetchPath fetchPath)
      Apply the path properties replacing the select and fetch clauses.

      This is typically used when the FetchPath is applied to both the query and the JSON output.

    • select

      SELF select(String fetchProperties)
      Specify the properties to fetch on the root level entity bean in comma delimited format.

      The Id property is automatically included in the properties to fetch unless setDistinct(true) is set on the query.

      Use fetch(String, String) to specify specific properties to fetch on other non-root level paths of the object graph.

      
      
       List<Customer> customers = DB.find(Customer.class)
           // Only fetch the customer id, name and status.
           // This is described as a "Partial Object"
           .select("name, status")
           .where.ilike("name", "rob%")
           .findList();
      
       
      Parameters:
      fetchProperties - the properties to fetch for this bean (* = all properties).
    • distinctOn

      SELF distinctOn(String distinctOn)
      Set DISTINCT ON clause. This is a Postgres only SQL feature.
      Parameters:
      distinctOn - The properties to include in the DISTINCT ON clause.
    • select

      SELF select(FetchGroup<T> fetchGroup)
      Apply the fetchGroup which defines what part of the object graph to load.
    • fetch

      SELF fetch(String path, String fetchProperties)
      Specify a path to fetch eagerly including specific properties.

      Ebean will endeavour to fetch this path using a SQL join. If Ebean determines that it can not use a SQL join (due to maxRows or because it would result in a cartesian product) Ebean will automatically convert this fetch query into a "query join" - i.e. use fetchQuery().

      
      
       // query orders...
       List<Order> orders = DB.find(Order.class)
             // fetch the customer...
             // ... getting the customers name and phone number
             .fetch("customer", "name, phoneNumber")
      
             // ... also fetch the customers billing address (* = all properties)
             .fetch("customer.billingAddress", "*")
             .findList();
       

      If columns is null or "*" then all columns/properties for that path are fetched.

      
      
       // fetch customers (their id, name and status)
       List<Customer> customers = DB.find(Customer.class)
           .select("name, status")
           .fetch("contacts", "firstName,lastName,email")
           .findList();
      
       
      Parameters:
      path - the property path we wish to fetch eagerly.
      fetchProperties - properties of the associated bean that you want to include in the fetch (* means all properties, null also means all properties).
    • fetchQuery

      SELF fetchQuery(String path, String fetchProperties)
      Fetch the path and properties using a "query join" (separate SQL query).

      This is the same as:

      
      
        fetch(path, fetchProperties, FetchConfig.ofQuery())
      
       

      This would be used instead of a fetch() when we use a separate SQL query to fetch this part of the object graph rather than a SQL join.

      We might typically get a performance benefit when the path to fetch is a OneToMany or ManyToMany, the 'width' of the 'root bean' is wide and the cardinality of the many is high.

      Parameters:
      path - the property path we wish to fetch eagerly.
      fetchProperties - properties of the associated bean that you want to include in the fetch (* means all properties, null also means all properties).
    • fetchCache

      SELF fetchCache(String path, String fetchProperties)
      Fetch the path and properties using L2 bean cache.
      Parameters:
      path - The path of the beans we are fetching from L2 cache.
      fetchProperties - The properties that should be loaded.
    • fetchLazy

      SELF fetchLazy(String path, String fetchProperties)
      Fetch the path and properties lazily (via batch lazy loading).

      This is the same as:

      
      
        fetch(path, fetchProperties, FetchConfig.ofLazy())
      
       

      The reason for using fetchLazy() is to either:

      • Control/tune what is fetched as part of lazy loading
      • Make use of the L2 cache, build this part of the graph from L2 cache
      Parameters:
      path - the property path we wish to fetch lazily.
      fetchProperties - properties of the associated bean that you want to include in the fetch (* means all properties, null also means all properties).
    • fetch

      SELF fetch(String path, String fetchProperties, FetchConfig fetchConfig)
      Additionally specify a FetchConfig to use a separate query or lazy loading to load this path.
      
      
       // fetch customers (their id, name and status)
       List<Customer> customers = DB.find(Customer.class)
           .select("name, status")
           .fetch("contacts", "firstName,lastName,email", FetchConfig.ofLazy(10))
           .findList();
      
       
      Parameters:
      path - the property path we wish to fetch eagerly.
    • fetch

      SELF fetch(String path)
      Specify a path to fetch eagerly including all its properties.

      Ebean will endeavour to fetch this path using a SQL join. If Ebean determines that it can not use a SQL join (due to maxRows or because it would result in a cartesian product) Ebean will automatically convert this fetch query into a "query join" - i.e. use fetchQuery().

      
      
       // fetch customers (their id, name and status)
       List<Customer> customers = DB.find(Customer.class)
           // eager fetch the contacts
           .fetch("contacts")
           .findList();
      
       
      Parameters:
      path - the property path we wish to fetch eagerly.
    • fetchQuery

      SELF fetchQuery(String path)
      Fetch the path eagerly using a "query join" (separate SQL query).

      This is the same as:

      
      
        fetch(path, FetchConfig.ofQuery())
      
       

      This would be used instead of a fetch() when we use a separate SQL query to fetch this part of the object graph rather than a SQL join.

      We might typically get a performance benefit when the path to fetch is a OneToMany or ManyToMany, the 'width' of the 'root bean' is wide and the cardinality of the many is high.

      Parameters:
      path - the property path we wish to fetch eagerly
    • fetchCache

      SELF fetchCache(String path)
      Fetch the path eagerly using L2 cache.
    • fetchLazy

      SELF fetchLazy(String path)
      Fetch the path lazily (via batch lazy loading).

      This is the same as:

      
      
        fetch(path, FetchConfig.ofLazy())
      
       

      The reason for using fetchLazy() is to either:

      • Control/tune what is fetched as part of lazy loading
      • Make use of the L2 cache, build this part of the graph from L2 cache
      Parameters:
      path - the property path we wish to fetch lazily.
    • fetch

      SELF fetch(String path, FetchConfig fetchConfig)
      Additionally specify a JoinConfig to specify a "query join" and or define the lazy loading query.
      
      
       // fetch customers (their id, name and status)
       List<Customer> customers = DB.find(Customer.class)
           // lazy fetch contacts with a batch size of 100
           .fetch("contacts", FetchConfig.ofLazy(100))
           .findList();