18
18
import org .apiguardian .api .API ;
19
19
import org .springframework .data .mapping .PropertyPath ;
20
20
import org .springframework .data .neo4j .core .mapping .Neo4jMappingContext ;
21
- import org .springframework .data .neo4j .core .mapping .Neo4jPersistentEntity ;
22
- import org .springframework .data .neo4j .core .mapping .Neo4jPersistentProperty ;
23
21
import org .springframework .data .projection .ProjectionFactory ;
24
22
import org .springframework .data .projection .ProjectionInformation ;
25
23
import org .springframework .data .repository .query .ResultProcessor ;
26
24
import org .springframework .data .repository .query .ReturnedType ;
27
25
28
26
import java .beans .PropertyDescriptor ;
29
- import java .util .Collection ;
30
27
import java .util .Collections ;
31
28
import java .util .HashMap ;
32
- import java .util .HashSet ;
33
29
import java .util .Map ;
34
30
35
31
/**
@@ -95,7 +91,7 @@ private static void addPropertiesFrom(Class<?> domainType, Class<?> returnedType
95
91
if (mappingContext .getConversionService ().isSimpleType (propertyType )) {
96
92
filteredProperties .put (propertyPath , false );
97
93
} else if (mappingContext .hasPersistentEntityFor (propertyType )) {
98
- addPropertiesFromEntity ( filteredProperties , propertyPath , propertyType , mappingContext , new HashSet <>() );
94
+ filteredProperties . put ( propertyPath , true );
99
95
} else {
100
96
ProjectionInformation nestedProjectionInformation = factory .getProjectionInformation (propertyType );
101
97
// Closed projection should get handled as above (recursion)
@@ -112,46 +108,12 @@ private static void addPropertiesFrom(Class<?> domainType, Class<?> returnedType
112
108
nestedPropertyPath .toDotPath (), mappingContext );
113
109
}
114
110
} else {
115
- // an open projection at this place needs to get replaced with the matching (real) entity
116
- filteredProperties .put (propertyPath , true );
117
- processEntity (domainType , filteredProperties , inputProperty , mappingContext );
111
+ // An open projection at this place needs to get replaced with the matching (real) entity
112
+ // Use domain type as root type for the property path
113
+ PropertyPath domainBasedPropertyPath = PropertyPath .from (inputProperty , domainType );
114
+ filteredProperties .put (domainBasedPropertyPath , true );
118
115
}
119
116
}
120
117
}
121
118
122
- private static void processEntity (Class <?> domainType , Map <PropertyPath , Boolean > filteredProperties ,
123
- String inputProperty , Neo4jMappingContext mappingContext ) {
124
-
125
- Neo4jPersistentEntity <?> persistentEntity = mappingContext .getPersistentEntity (domainType );
126
- Neo4jPersistentProperty persistentProperty = persistentEntity .getPersistentProperty (inputProperty );
127
- Class <?> propertyEntityType = persistentProperty .getActualType ();
128
-
129
- // Use domain type as root type for the property path
130
- PropertyPath propertyPath = PropertyPath .from (inputProperty , domainType );
131
- addPropertiesFromEntity (filteredProperties , propertyPath , propertyEntityType , mappingContext , new HashSet <>());
132
- }
133
-
134
- private static void addPropertiesFromEntity (Map <PropertyPath , Boolean > filteredProperties , PropertyPath propertyPath ,
135
- Class <?> propertyType , Neo4jMappingContext mappingContext ,
136
- Collection <Neo4jPersistentEntity <?>> processedEntities ) {
137
-
138
- if (!mappingContext .hasPersistentEntityFor (propertyType )) {
139
- throw new RuntimeException ("hmmmm" );
140
- }
141
-
142
- Neo4jPersistentEntity <?> persistentEntityFromProperty = mappingContext .getPersistentEntity (propertyType );
143
- // break the recursion / cycles
144
- if (hasProcessedEntity (persistentEntityFromProperty , processedEntities )) {
145
- return ;
146
- }
147
-
148
- filteredProperties .put (propertyPath , true );
149
-
150
- }
151
-
152
- private static boolean hasProcessedEntity (Neo4jPersistentEntity <?> persistentEntityFromProperty ,
153
- Collection <Neo4jPersistentEntity <?>> processedEntities ) {
154
-
155
- return processedEntities .contains (persistentEntityFromProperty );
156
- }
157
119
}
0 commit comments