mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#3313 Ability to configure fetch batch size when using FetchGroups and query beans
We can do this currently using string paths and properties, this adds support for doing this when using query beans and strong types
This commit is contained in:
@@ -108,6 +108,18 @@ public abstract class TQAssocBean<T, R, QB> extends TQAssoc<T, R> {
|
||||
return fetchWithProperties(FETCH_DEFAULT, properties);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch this association with config for the type of fetch and the specified properties.
|
||||
*
|
||||
* @param config Fetch configuration to define the type of fetch to use
|
||||
* @param properties The properties to fetch
|
||||
*/
|
||||
@SafeVarargs @SuppressWarnings("varargs")
|
||||
public final R fetch(FetchConfig config, TQProperty<QB,?>... properties) {
|
||||
return fetchWithProperties(config, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Eagerly fetch this association using a 'query join' loading the specified properties.
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.querytest;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.FetchConfig;
|
||||
import io.ebean.FetchGroup;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.test.LoggedSql;
|
||||
@@ -8,6 +9,7 @@ import org.example.domain.Customer;
|
||||
import org.example.domain.Order;
|
||||
import org.example.domain.OrderDetail;
|
||||
import org.example.domain.otherpackage.PhoneNumber;
|
||||
import org.example.domain.query.QContact;
|
||||
import org.example.domain.query.QCustomer;
|
||||
import org.example.domain.query.QOrder;
|
||||
import org.example.domain.query.QOrderDetail;
|
||||
@@ -26,10 +28,17 @@ public class QOrderTest {
|
||||
|
||||
private static final QOrder or = QOrder.alias();
|
||||
|
||||
private static final QContact co = QContact.alias();
|
||||
|
||||
private static final FetchGroup<Customer> fgC = QCustomer.forFetchGroup()
|
||||
.select(cu.name, cu.phoneNumber)
|
||||
.buildFetchGroup();
|
||||
|
||||
private static final FetchGroup<Customer> fgCustomerWithContacts = QCustomer.forFetchGroup()
|
||||
.select(cu.name, cu.phoneNumber)
|
||||
.contacts.fetch(FetchConfig.ofQuery(1000), co.firstName, co.lastName, co.email)
|
||||
.buildFetchGroup();
|
||||
|
||||
private static final FetchGroup<Order> fgNested1 = QOrder.forFetchGroup()
|
||||
.select(or.status, or.shipDate)
|
||||
.customer.fetch(fgC)
|
||||
@@ -70,6 +79,20 @@ public class QOrderTest {
|
||||
DB.delete(customer);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchQueryWithBatch() {
|
||||
LoggedSql.start();
|
||||
|
||||
new QCustomer()
|
||||
.select(fgCustomerWithContacts)
|
||||
.findList();
|
||||
|
||||
final List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.name, t0.phone_number from be_customer t0");
|
||||
assertThat(sql.get(1)).contains("select t0.customer_id, t0.id, t0.first_name, t0.last_name, t0.email from be_contact t0 where");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchCache() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user