|
59 | 59 | import org.springframework.data.mapping.model.SimpleTypeHolder; |
60 | 60 | import org.springframework.data.spel.EvaluationContextProvider; |
61 | 61 | import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider; |
| 62 | +import org.springframework.data.util.CustomCollections; |
62 | 63 | import org.springframework.data.util.KotlinReflectionUtils; |
63 | 64 | import org.springframework.data.util.NullableWrapperConverters; |
64 | 65 | import org.springframework.data.util.Optionals; |
@@ -143,7 +144,6 @@ public void setApplicationContext(ApplicationContext applicationContext) throws |
143 | 144 | * |
144 | 145 | * @param initialEntitySet |
145 | 146 | * @see #setManagedTypes(ManagedTypes) |
146 | | - * |
147 | 147 | */ |
148 | 148 | public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet) { |
149 | 149 | setManagedTypes(ManagedTypes.fromIterable(initialEntitySet)); |
@@ -415,16 +415,18 @@ private E doAddPersistentEntity(TypeInformation<?> typeInformation) { |
415 | 415 | persistentEntities.put(typeInformation, Optional.of(entity)); |
416 | 416 | } |
417 | 417 |
|
418 | | - PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type); |
419 | | - Map<String, PropertyDescriptor> descriptors = new HashMap<>(); |
| 418 | + if (shouldCreateProperties(userTypeInformation)) { |
| 419 | + PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type); |
| 420 | + Map<String, PropertyDescriptor> descriptors = new HashMap<>(); |
420 | 421 |
|
421 | | - for (PropertyDescriptor descriptor : pds) { |
422 | | - descriptors.put(descriptor.getName(), descriptor); |
423 | | - } |
| 422 | + for (PropertyDescriptor descriptor : pds) { |
| 423 | + descriptors.put(descriptor.getName(), descriptor); |
| 424 | + } |
424 | 425 |
|
425 | | - PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors); |
426 | | - ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE); |
427 | | - persistentPropertyCreator.addPropertiesForRemainingDescriptors(); |
| 426 | + PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors); |
| 427 | + ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE); |
| 428 | + persistentPropertyCreator.addPropertiesForRemainingDescriptors(); |
| 429 | + } |
428 | 430 |
|
429 | 431 | entity.verify(); |
430 | 432 |
|
@@ -475,6 +477,35 @@ public Collection<TypeInformation<?>> getManagedTypes() { |
475 | 477 | */ |
476 | 478 | protected abstract P createPersistentProperty(Property property, E owner, SimpleTypeHolder simpleTypeHolder); |
477 | 479 |
|
| 480 | + /** |
| 481 | + * Whether to create the {@link PersistentProperty}s for the given {@link TypeInformation}. |
| 482 | + * |
| 483 | + * @param typeInformation must not be {@literal null}. |
| 484 | + * @return {@literal true} properties should be created, {@literal false} otherwise |
| 485 | + */ |
| 486 | + protected boolean shouldCreateProperties(TypeInformation<?> typeInformation) { |
| 487 | + |
| 488 | + Class<?> type = typeInformation.getType(); |
| 489 | + |
| 490 | + return !typeInformation.isMap() && !isCollectionLike(type); |
| 491 | + } |
| 492 | + |
| 493 | + /** |
| 494 | + * In contrast to TypeInformation, we do not consider types implementing Streamable collection-like as domain types |
| 495 | + * can implement that type. |
| 496 | + * |
| 497 | + * @param type must not be {@literal null}. |
| 498 | + * @return |
| 499 | + * @see TypeInformation#isCollectionLike() |
| 500 | + */ |
| 501 | + private static boolean isCollectionLike(Class<?> type) { |
| 502 | + |
| 503 | + return type.isArray() // |
| 504 | + || Iterable.class.equals(type) // |
| 505 | + || Streamable.class.equals(type) // |
| 506 | + || Collection.class.isAssignableFrom(type) || CustomCollections.isCollection(type); |
| 507 | + } |
| 508 | + |
478 | 509 | @Override |
479 | 510 | public void afterPropertiesSet() { |
480 | 511 | initialize(); |
@@ -532,6 +563,7 @@ private PersistentPropertyCreator(E entity, Map<String, PropertyDescriptor> desc |
532 | 563 | this.remainingDescriptors = remainingDescriptors; |
533 | 564 | } |
534 | 565 |
|
| 566 | + @Override |
535 | 567 | public void doWith(Field field) { |
536 | 568 |
|
537 | 569 | String fieldName = field.getName(); |
|
0 commit comments