mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 23:56:36 +00:00
#566 - Refactor internals - OrmQueryDetail, skip fetch path sort when empty
This commit is contained in:
@@ -298,15 +298,18 @@ public class OrmQueryDetail implements Serializable {
|
||||
fetch(new OrmQueryProperties(path, properties));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the fetch paths into depth order adding any missing parent paths if necessary.
|
||||
*/
|
||||
public void sortFetchPaths(BeanDescriptor<?> d) {
|
||||
|
||||
LinkedHashMap<String, OrmQueryProperties> sorted = new LinkedHashMap<String, OrmQueryProperties>();
|
||||
|
||||
for (OrmQueryProperties p : fetchPaths.values()) {
|
||||
sortFetchPaths(d, p, sorted);
|
||||
if (!fetchPaths.isEmpty()) {
|
||||
LinkedHashMap<String, OrmQueryProperties> sorted = new LinkedHashMap<String, OrmQueryProperties>();
|
||||
for (OrmQueryProperties p : fetchPaths.values()) {
|
||||
sortFetchPaths(d, p, sorted);
|
||||
}
|
||||
fetchPaths = sorted;
|
||||
}
|
||||
|
||||
fetchPaths = sorted;
|
||||
}
|
||||
|
||||
private void sortFetchPaths(BeanDescriptor<?> d, OrmQueryProperties p, LinkedHashMap<String, OrmQueryProperties> sorted) {
|
||||
|
||||
@@ -166,6 +166,40 @@ public class OrmQueryDetailTest extends BaseTestCase {
|
||||
assertThat(detail.getChunk("customer.contacts", false).isQueryFetch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortFetchPaths_when_missingParent_expect_addsMissing() {
|
||||
|
||||
OrmQueryDetail detail = new OrmQueryDetail();
|
||||
detail.fetch("customer.contacts", null, null);
|
||||
|
||||
detail.sortFetchPaths(orderDesc());
|
||||
|
||||
assertThat(detail.getFetchPaths()).containsExactly("customer","customer.contacts");
|
||||
assertThat(detail.getChunk("customer",false).getIncluded()).containsExactly("id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortFetchPaths_when_outOfOrder_expect_correctOrder() {
|
||||
|
||||
OrmQueryDetail detail = new OrmQueryDetail();
|
||||
detail.fetch("customer.contacts", "email", null);
|
||||
detail.fetch("customer", "name", null);
|
||||
|
||||
detail.sortFetchPaths(orderDesc());
|
||||
|
||||
assertThat(detail.getFetchPaths()).containsExactly("customer","customer.contacts");
|
||||
assertThat(detail.getChunk("customer",false).getIncluded()).containsExactly("name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortFetchPaths_when_empty_expect_stillEmpty() {
|
||||
|
||||
OrmQueryDetail detail = new OrmQueryDetail();
|
||||
detail.sortFetchPaths(orderDesc());
|
||||
|
||||
assertThat(detail.getFetchPaths()).isEmpty();
|
||||
}
|
||||
|
||||
BeanDescriptor<Order> orderDesc() {
|
||||
return getBeanDescriptor(Order.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user