T
- The bean type the Fetch group can be applied topublic interface FetchGroup<T>
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.
FetchGroup<Customer> fetchGroup = FetchGroup.of(Customer.class, "name, status");
Customer.query()
.select(fetchGroup)
.findList();
FetchGroup<Customer> fetchGroup = FetchGroup.of(Customer.class)
.select("name, status")
.fetch("contacts", "firstName, lastName, email")
.build();
Customer.query()
.select(fetchGroup)
.findList();
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();
Modifier and Type | Method and Description |
---|---|
static <T> FetchGroupBuilder<T> |
of(Class<T> cls)
Return the FetchGroupBuilder with the given select clause that we can add fetch clauses to.
|
static <T> FetchGroup<T> |
of(Class<T> cls,
String select)
Return the FetchGroup with the given select clause.
|
@Nonnull static <T> FetchGroup<T> of(Class<T> cls, String select)
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();
select
- The select clause of the FetchGroup@Nonnull static <T> FetchGroupBuilder<T> of(Class<T> cls)
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();
Copyright © 2019. All rights reserved.