Skip to content

Commit b883fad

Browse files
author
Mikhail Polivakha
committed
GH-2099: Code review fixes, polishing
Signed-off-by: Mikhail Polivakha <mikhailpolivakha@email.com> Singed-off-by: mipo256 <mikhailpolivakha@email.com>
1 parent 720e033 commit b883fad

File tree

1 file changed

+15
-40
lines changed

1 file changed

+15
-40
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/RelationalExampleMapper.java

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntit
8282
ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
8383

8484
final List<Criteria> criteriaBasedOnProperties = buildCriteria( //
85+
null, //
8586
persistentEntity, //
8687
matcherAccessor, //
8788
probePropertyAccessor //
@@ -103,21 +104,23 @@ private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntit
103104
}
104105

105106
private <T> List<Criteria> buildCriteria( //
107+
@Nullable PropertyPath propertyPath, //
106108
RelationalPersistentEntity<?> persistentEntity, //
107109
ExampleMatcherAccessor matcherAccessor, //
108110
PersistentPropertyAccessor<T> probePropertyAccessor //
109111
) {
110112
final List<Criteria> criteriaBasedOnProperties = new ArrayList<>();
111113

112-
persistentEntity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) property -> {
114+
for (RelationalPersistentProperty property : persistentEntity) {
113115
potentiallyEnrichCriteria(
114-
null,
116+
propertyPath,
115117
matcherAccessor, //
116118
probePropertyAccessor, //
117119
property, //
118120
criteriaBasedOnProperties //
119121
);
120-
});
122+
}
123+
121124
return criteriaBasedOnProperties;
122125
}
123126

@@ -158,12 +161,15 @@ private <T> void potentiallyEnrichCriteria(
158161
Object actualPropertyValue = entityPropertiesAccessor.getProperty(property);
159162

160163
if (property.isEmbedded() && actualPropertyValue != null) {
161-
processEmbeddedRecursively( //
162-
matcherAccessor, //
163-
actualPropertyValue,
164-
property, //
165-
criteriaBasedOnProperties, //
166-
currentPropertyPath //
164+
RelationalPersistentEntity<?> embeddedPersistentEntity = mappingContext.getRequiredPersistentEntity(property.getTypeInformation());
165+
166+
criteriaBasedOnProperties.addAll(
167+
buildCriteria(
168+
currentPropertyPath,
169+
embeddedPersistentEntity,
170+
matcherAccessor,
171+
embeddedPersistentEntity.getPropertyAccessor(actualPropertyValue)
172+
)
167173
);
168174
} else {
169175
Optional<?> optionalConvertedPropValue = matcherAccessor //
@@ -209,37 +215,6 @@ private <T> void potentiallyEnrichCriteria(
209215

210216
}
211217

212-
/**
213-
* Processes an embedded entity's properties recursively.
214-
*
215-
* @param matcherAccessor the input matcher on the {@link Example#getProbe() original probe}.
216-
* @param value the actual embedded object.
217-
* @param property the embedded property.
218-
* @param criteriaBasedOnProperties collection of {@link Criteria} objects to potentially enrich.
219-
* @param currentPropertyPath the dot-separated path of the passed {@code property}.
220-
*/
221-
private void processEmbeddedRecursively(
222-
ExampleMatcherAccessor matcherAccessor,
223-
Object value,
224-
RelationalPersistentProperty property,
225-
List<Criteria> criteriaBasedOnProperties,
226-
PropertyPath currentPropertyPath
227-
) {
228-
RelationalPersistentEntity<?> embeddedPersistentEntity = mappingContext.getPersistentEntity(property.getTypeInformation());
229-
230-
PersistentPropertyAccessor<?> embeddedEntityPropertyAccessor = embeddedPersistentEntity.getPropertyAccessor(value);
231-
232-
embeddedPersistentEntity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) embeddedProperty ->
233-
potentiallyEnrichCriteria(
234-
currentPropertyPath,
235-
matcherAccessor,
236-
embeddedEntityPropertyAccessor,
237-
embeddedProperty,
238-
criteriaBasedOnProperties
239-
)
240-
);
241-
}
242-
243218
private static PropertyPath resolveCurrentPropertyPath(@Nullable PropertyPath propertyPath, RelationalPersistentProperty property) {
244219
PropertyPath currentPropertyPath;
245220

0 commit comments

Comments
 (0)