DATACMNS-1366 - Introduce PersistentEntity.requiresPropertyPopulation().
The newly introduced method indicates whether any properties have to be populated to create instances of the entity. This is useful for objects that are completely initialized through their constructors as converters then can avoid iterating over all properties just to find out none of them have to be populated.
This commit is contained in:
@@ -316,4 +316,13 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
|
||||
* @since 2.1
|
||||
*/
|
||||
boolean isImmutable();
|
||||
|
||||
/**
|
||||
* Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by
|
||||
* the constructor.
|
||||
*
|
||||
* @return
|
||||
* @since 2.1
|
||||
*/
|
||||
boolean requiresPropertyPopulation();
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
private final Lazy<Alias> typeAlias;
|
||||
private final Lazy<IsNewStrategy> isNewStrategy;
|
||||
private final Lazy<Boolean> isImmutable;
|
||||
private final Lazy<Boolean> requiresPropertyPopulation;
|
||||
|
||||
/**
|
||||
* Creates a new {@link BasicPersistentEntity} from the given {@link TypeInformation}.
|
||||
@@ -134,6 +135,8 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
: getFallbackIsNewStrategy());
|
||||
|
||||
this.isImmutable = Lazy.of(() -> isAnnotationPresent(Immutable.class));
|
||||
this.requiresPropertyPopulation = Lazy.of(() -> !isImmutable() && properties.stream() //
|
||||
.anyMatch(it -> !(isConstructorArgument(it) || it.isTransient())));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -508,6 +511,15 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
return isImmutable.get();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.PersistentEntity#requiresPropertyPopulation()
|
||||
*/
|
||||
@Override
|
||||
public boolean requiresPropertyPopulation() {
|
||||
return requiresPropertyPopulation.get();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
|
||||
Reference in New Issue
Block a user