Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fefdf03

Browse files
committed
Polishing.
Extract method. See #3310
1 parent 000c467 commit fefdf03

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

‎src/main/java/org/springframework/data/mapping/context/PersistentEntities.java‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,24 @@ public TypeInformation<?> getTypeUltimatelyReferredToBy(PersistentProperty<?> pr
240240
@Nullable
241241
private PersistentEntity<?, ?> getEntityIdentifiedBy(TypeInformation<?> type) {
242242

243+
Collection<PersistentEntity<?, ?>> entities = getPersistentEntities(type);
244+
245+
if (entities.size() > 1) {
246+
247+
String message = "Found multiple entities identified by " + type.getType() + ": ";
248+
message += entities.stream().map(it -> it.getType().getName()).collect(Collectors.joining(", "));
249+
message += "; Introduce dedicated unique identifier types or explicitly define the target type in @Reference";
250+
251+
throw new IllegalStateException(message);
252+
}
253+
254+
return entities.isEmpty() ? null : entities.iterator().next();
255+
}
256+
257+
private Collection<PersistentEntity<?, ?>> getPersistentEntities(TypeInformation<?> type) {
258+
243259
Collection<PersistentEntity<?, ?>> entities = new ArrayList<>();
260+
244261
for (MappingContext<?, ? extends PersistentProperty<?>> context : getMappingContexts()) {
245262

246263
for (PersistentEntity<?, ? extends PersistentProperty<?>> persistentProperties : context
@@ -255,16 +272,7 @@ public TypeInformation<?> getTypeUltimatelyReferredToBy(PersistentProperty<?> pr
255272
}
256273
}
257274

258-
if (entities.size() > 1) {
259-
260-
String message = "Found multiple entities identified by " + type.getType() + ": ";
261-
message += entities.stream().map(it -> it.getType().getName()).collect(Collectors.joining(", "));
262-
message += "; Introduce dedicated unique identifier types or explicitly define the target type in @Reference";
263-
264-
throw new IllegalStateException(message);
265-
}
266-
267-
return entities.isEmpty() ? null : entities.iterator().next();
275+
return entities;
268276
}
269277

270278
private Collection<? extends MappingContext<?, ? extends PersistentProperty<?>>> getMappingContexts() {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /