- Type Parameters:
T
- The bean type the Fetch group can be applied to
@NonNullApi
public interface FetchGroup<T>
Defines what part of the object graph to load (select and fetch clauses).
Using a FetchGroup effectively sets the select() and fetch() clauses for a query. It is alternative to specifying the select() and fetch() clauses on the query allowing for more re-use of "what to load" that can be defined separately from the query and combined with other FetchGroups.
Select example
FetchGroup<Customer> fetchGroup = FetchGroup.of(Customer.class, "name, status");
Customer.query()
.select(fetchGroup)
.findList();
Select and fetch example
FetchGroup<Customer> fetchGroup = FetchGroup.of(Customer.class)
.select("name, status")
.fetch("contacts", "firstName, lastName, email")
.build();
Customer.query()
.select(fetchGroup)
.findList();
Combining FetchGroups
FetchGroups can be combined together to form another FetchGroup.
FetchGroup<Address> FG_ADDRESS = FetchGroup.of(Address.class)
.select("line1, line2, city")
.fetch("country", "name")
.build();
FetchGroup<Customer> FG_CUSTOMER = FetchGroup.of(Customer.class)
.select("name, version")
.fetch("billingAddress", FG_ADDRESS)
.build();
Customer.query()
.select(FG_CUSTOMER)
.findList();
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> FetchGroupBuilder<T>
Return the FetchGroupBuilder with the given select clause that we can add fetch clauses to.static <T> FetchGroup<T>
Return the FetchGroup with the given select clause.static <T> SpiFetchGroupQuery<T>
Return a query to be used by query beans for constructing FetchGroup.
-
Method Details
-
of
Return the FetchGroup with the given select clause.We use this for simple FetchGroup that only select() properties and do not have additional fetch() clause.
FetchGroup<Customer> fetchGroup = FetchGroup.of(Customer.class, "name, status"); Customer.query() .select(fetchGroup) .findList();
- Parameters:
select
- The select clause of the FetchGroup- Returns:
- The FetchGroup with the given select clause
-
of
Return the FetchGroupBuilder with the given select clause that we can add fetch clauses to.We chain select() with one or more fetch() clauses to define the object graph to load.
FetchGroup<Customer> fetchGroup = FetchGroup.of(Customer.class) .select("name, status") .fetch("contacts", "firstName, lastName, email") .build(); Customer.query() .select(fetchGroup) .findList();
- Returns:
- The FetchGroupBuilder with the given select clause which we will add fetch clauses to
-
queryFor
Return a query to be used by query beans for constructing FetchGroup.
-