Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class DFetchGroup<T> implements SpiFetchGroup<T> {
}

@Override
public OrmQueryDetail detail() {
return detail.copy();
public OrmQueryDetail detail(OrmQueryDetail existing) {
return detail.copy(existing);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Query<T> select(String columns) {
@SuppressWarnings("rawtypes")
@Override
public Query<T> select(FetchGroup fetchGroup) {
this.detail = ((SpiFetchGroup) fetchGroup).detail();
this.detail = ((SpiFetchGroup) fetchGroup).detail(detail);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public SpiQuery<T> copy(SpiEbeanServer server) {
copy.useQueryCache = useQueryCache;
copy.unmodifiable = unmodifiable;
if (detail != null) {
copy.detail = detail.copy();
copy.detail = detail.copy(null);
}
copy.temporalMode = temporalMode;
copy.firstRow = firstRow;
Expand Down Expand Up @@ -1387,7 +1387,7 @@ public final Query<T> select(String columns) {
@Override
public final Query<T> select(FetchGroup<T> fetchGroup) {
if (fetchGroup != null) {
this.detail = ((SpiFetchGroup<T>) fetchGroup).detail();
this.detail = ((SpiFetchGroup<T>) fetchGroup).detail(detail);
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ public final class OrmQueryDetail implements Serializable {
/**
* Return a deep copy of the OrmQueryDetail.
*/
public OrmQueryDetail copy() {
public OrmQueryDetail copy(OrmQueryDetail existing) {
OrmQueryDetail copy = new OrmQueryDetail();
copy.baseProps = baseProps.copy();
for (Map.Entry<String, OrmQueryProperties> entry : fetchPaths.entrySet()) {
copy.fetchPaths.put(entry.getKey(), entry.getValue().copy());
}
if (existing != null) {
// transfer any existing filterMany expressions
for (Map.Entry<String, OrmQueryProperties> entry : existing.fetchPaths.entrySet()) {
var filterMany = entry.getValue().getFilterMany();
if (filterMany != null) {
copy.getChunk(entry.getKey(), true).setFilterMany(filterMany);
}
}
}
return copy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface SpiFetchGroup<T> extends FetchGroup<T> {
/**
* Return the detail to use for query execution.
*/
OrmQueryDetail detail();
OrmQueryDetail detail(OrmQueryDetail existing);

/**
* Return the underlying detail for copy purposes.
Expand Down
18 changes: 18 additions & 0 deletions ebean-querybean/src/test/java/org/querytest/QCustomerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.example.domain.query.QContact;
import org.example.domain.query.QCustomer;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import javax.sql.DataSource;
Expand Down Expand Up @@ -391,6 +392,23 @@ void filterManyOr() {
assertThat(q.getGeneratedSql()).contains(" from be_customer t0 left join be_contact t1 on t1.customer_id = t0.id where (t1.id is null or ((t1.first_name like ? escape'|' or t1.last_name like ? escape'|'))) order by t0.id");
}

@Test
@DisplayName("Retain filterMany expression when select fetchGroup applied after filterMany")
void filterManyBeforeSelectFetchGroup_expect_filterManyExpressionRetained() {
var fetchGroup = QCustomer.forFetchGroup()
.select(name)
.contacts.fetch(QContact.Alias.email)
.buildFetchGroup();

var q = new QCustomer()
.contacts.filterMany(c -> c.firstName.startsWith("R"))
.select(fetchGroup)
.query();

q.findList();
assertThat(q.getGeneratedSql()).contains(" t0.id, t0.name, t1.id, t1.email from be_customer t0 left join be_contact t1 on t1.customer_id = t0.id where (t1.id is null or (t1.first_name like ? escape'|')) order by t0.id");
}

@Test
public void testIdIn() {

Expand Down