@@ -570,9 +570,10 @@ public boolean containsPossibleCircles(Predicate<PropertyFilter.RelaxedPropertyP
570
570
}
571
571
572
572
private boolean calculatePossibleCircles (Predicate <PropertyFilter .RelaxedPropertyPath > includeField ) {
573
- Collection <RelationshipDescription > relationships = new HashSet <>(getRelationshipsInHierarchy (includeField ));
573
+ Collection <RelationshipDescription > allRelationships = new HashSet <>(getRelationshipsInHierarchy (includeField ));
574
574
575
- for (RelationshipDescription relationship : relationships ) {
575
+ Set <NodeDescription <?>> thisNodeVisited = Set .of (this );
576
+ for (RelationshipDescription relationship : allRelationships ) {
576
577
PropertyFilter .RelaxedPropertyPath relaxedPropertyPath = PropertyFilter .RelaxedPropertyPath .withRootType (this .getUnderlyingClass ());
577
578
if (!filterProperties (includeField , relationship , relaxedPropertyPath )) {
578
579
continue ;
@@ -583,24 +584,28 @@ private boolean calculatePossibleCircles(Predicate<PropertyFilter.RelaxedPropert
583
584
if (this .equals (targetNode )) {
584
585
return true ;
585
586
}
586
- String relationshipPropertiesPrefix = relationship .hasRelationshipProperties () ? "." + ((Neo4jPersistentEntity <?>) relationship .getRelationshipPropertiesEntity ())
587
- .getPersistentProperty (TargetNode .class ).getFieldName () : "" ;
588
587
589
588
// Branch out with the nodes already visited before
590
- Set <NodeDescription <?>> visitedNodes = new HashSet <>();
589
+ Set <NodeDescription <?>> visitedNodes = new HashSet <>(thisNodeVisited );
591
590
visitedNodes .add (targetNode );
592
- if (calculatePossibleCircles (targetNode , visitedNodes , includeField , relaxedPropertyPath .append (relationship .getFieldName () + relationshipPropertiesPrefix ))) {
591
+
592
+ // we don't care about the other content of relationship properties and jump straight into the `TargetNode`
593
+ String relationshipPropertiesPrefix = relationship .hasRelationshipProperties ()
594
+ ? "." + ((Neo4jPersistentEntity <?>) relationship .getRelationshipPropertiesEntity ()).getPersistentProperty (TargetNode .class ).getFieldName ()
595
+ : "" ;
596
+ PropertyFilter .RelaxedPropertyPath nextPath = relaxedPropertyPath .append (relationship .getFieldName () + relationshipPropertiesPrefix );
597
+ if (calculatePossibleCircles (targetNode , visitedNodes , includeField , nextPath )) {
593
598
return true ;
594
599
}
595
600
}
596
601
return false ;
597
602
}
598
603
599
604
private boolean calculatePossibleCircles (NodeDescription <?> nodeDescription , Set <NodeDescription <?>> visitedNodes , Predicate <PropertyFilter .RelaxedPropertyPath > includeField , PropertyFilter .RelaxedPropertyPath path ) {
600
- Collection <RelationshipDescription > relationships = (( DefaultNeo4jPersistentEntity <?>) nodeDescription ).getRelationshipsInHierarchy (includeField , path );
605
+ Collection <RelationshipDescription > allRelationships = new HashSet <>((( DefaultNeo4jPersistentEntity <?>) nodeDescription ).getRelationshipsInHierarchy (includeField , path ) );
601
606
602
607
Collection <NodeDescription <?>> visitedTargetNodes = new HashSet <>();
603
- for (RelationshipDescription relationship : relationships ) {
608
+ for (RelationshipDescription relationship : allRelationships ) {
604
609
NodeDescription <?> targetNode = relationship .getTarget ();
605
610
if (visitedNodes .contains (targetNode )) {
606
611
return true ;
@@ -611,8 +616,10 @@ private boolean calculatePossibleCircles(NodeDescription<?> nodeDescription, Set
611
616
// Add the already visited target nodes for the next level,
612
617
// but don't (!) add them to the visitedNodes yet.
613
618
// Otherwise, the same "parallel" defined target nodes will report a false circle.
614
- branchedVisitedNodes .addAll (visitedTargetNodes );
615
- if (calculatePossibleCircles (targetNode , branchedVisitedNodes , includeField , path .append (relationship .getFieldName ()))) {
619
+ branchedVisitedNodes .add (targetNode );
620
+ String relationshipPropertiesPrefix = relationship .hasRelationshipProperties () ? "." + ((Neo4jPersistentEntity <?>) relationship .getRelationshipPropertiesEntity ())
621
+ .getPersistentProperty (TargetNode .class ).getFieldName () : "" ;
622
+ if (calculatePossibleCircles (targetNode , branchedVisitedNodes , includeField , path .append (relationship .getFieldName () + relationshipPropertiesPrefix ))) {
616
623
return true ;
617
624
}
618
625
}
0 commit comments