Polishing.

Extract method.

See #3310
This commit is contained in:
Mark Paluch
2025-06-11 09:11:02 +02:00
parent 8e38e374b3
commit 9ce25da431

View File

@@ -238,7 +238,24 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
*/
private @Nullable PersistentEntity<?, ?> getEntityIdentifiedBy(TypeInformation<?> type) {
Collection<PersistentEntity<?, ?>> entities = getPersistentEntities(type);
if (entities.size() > 1) {
String message = "Found multiple entities identified by " + type.getType() + ": ";
message += entities.stream().map(it -> it.getType().getName()).collect(Collectors.joining(", "));
message += "; Introduce dedicated unique identifier types or explicitly define the target type in @Reference";
throw new IllegalStateException(message);
}
return entities.isEmpty() ? null : entities.iterator().next();
}
private Collection<PersistentEntity<?, ?>> getPersistentEntities(TypeInformation<?> type) {
Collection<PersistentEntity<?, ?>> entities = new ArrayList<>();
for (MappingContext<?, ? extends PersistentProperty<?>> context : getMappingContexts()) {
for (PersistentEntity<?, ? extends PersistentProperty<?>> persistentProperties : context
@@ -253,16 +270,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
}
}
if (entities.size() > 1) {
String message = "Found multiple entities identified by " + type.getType() + ": ";
message += entities.stream().map(it -> it.getType().getName()).collect(Collectors.joining(", "));
message += "; Introduce dedicated unique identifier types or explicitly define the target type in @Reference";
throw new IllegalStateException(message);
}
return entities.isEmpty() ? null : entities.iterator().next();
return entities;
}
private Collection<? extends MappingContext<?, ? extends PersistentProperty<?>>> getMappingContexts() {