Skip to content

Commit 6decfa8

Browse files
committed
GH-2748 - Fix property filter in FluentQuery....
Using FluentQueryByExample/Predicate with a subset of properties, the underlying fetching mechanics in the Neo4jTemplate was still querying for everything if the domain has a potential circular dependency. Closes #2748
1 parent 507b0fe commit 6decfa8

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/main/java/org/springframework/data/neo4j/repository/query/QueryFragments.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Optional;
2323
import java.util.concurrent.atomic.AtomicReference;
24+
import java.util.function.Predicate;
2425

2526
import org.apiguardian.api.API;
2627
import org.neo4j.cypherdsl.core.Condition;
@@ -61,6 +62,7 @@ public final class QueryFragments {
6162
* This flag becomes {@literal true} for backward scrolling keyset pagination. Any {@code AbstractNeo4jQuery} will in turn reverse the result list.
6263
*/
6364
private boolean requiresReverseSort = false;
65+
private Predicate<PropertyFilter.RelaxedPropertyPath> projectingPropertyFilter;
6466

6567
public void addMatchOn(PatternElement match) {
6668
this.matchOn.add(match);
@@ -95,8 +97,13 @@ public void setReturnExpression(Expression returnExpression, boolean isScalarVal
9597
this.scalarValueReturn = isScalarValue;
9698
}
9799

100+
public void setProjectingPropertyFilter(Predicate<PropertyFilter.RelaxedPropertyPath> projectingPropertyFilter) {
101+
this.projectingPropertyFilter = projectingPropertyFilter;
102+
}
103+
98104
public boolean includeField(PropertyFilter.RelaxedPropertyPath fieldName) {
99-
return this.returnTuple == null || this.returnTuple.include(fieldName);
105+
return (projectingPropertyFilter == null || projectingPropertyFilter.test(fieldName))
106+
&& (this.returnTuple == null || this.returnTuple.include(fieldName));
100107
}
101108

102109
public void setOrderBy(Collection<SortItem> orderBy) {

src/main/java/org/springframework/data/neo4j/repository/query/QueryFragmentsAndParameters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ private static QueryFragmentsAndParameters getQueryFragmentsAndParameters(
338338
} else {
339339
queryFragments.setReturnExpressions(
340340
cypherGenerator.createReturnStatementForMatch(entityMetaData, includeField));
341+
queryFragments.setProjectingPropertyFilter(includeField);
341342
}
342343

343344
if (pageable != null) {

src/test/java/org/springframework/data/neo4j/integration/shared/common/Flight.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class Flight {
3636
@Relationship(type = "ARRIVES")
3737
private final Airport arrival;
3838

39+
@Relationship("NEXT_FLIGHT")
40+
private Flight nextFlight;
41+
3942
public Flight(String name, Airport departure, Airport arrival) {
4043
this.name = name;
4144
this.departure = departure;

0 commit comments

Comments
 (0)