org.springframework.data.mapping.model

## Class BasicPersistentEntity<T,P extends PersistentProperty<P>>

- java.lang.Object
- - org.springframework.data.mapping.model.BasicPersistentEntity<T,P>

All Implemented Interfaces:
  Iterable<P>, MutablePersistentEntity<T,P>, PersistentEntity<T,P>

    public class BasicPersistentEntity<T,P extends PersistentProperty<P>>
    extends Object
    implements MutablePersistentEntity<T,P>

Simple value object to capture information of `PersistentEntity`s.

Author:
  Oliver Gierke, Jon Brisbin, Patryk Wasik, Thomas Darimont, Christoph Strobl, Mark Paluch

### Constructor Summary

Constructors
Constructor and Description
`BasicPersistentEntity(TypeInformation<T> information)` Creates a new `BasicPersistentEntity` from the given `TypeInformation`.
`BasicPersistentEntity(TypeInformation<T> information, Comparator<P> comparator)` Creates a new `BasicPersistentEntity` for the given `TypeInformation` and `Comparator`.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addAssociation(Association<P> association)` Adds an `Association` to the entity.
`void` `addPersistentProperty(P property)` Adds a `PersistentProperty` to the entity.
`void` `doWithAssociations(AssociationHandler<P> handler)` Applies the given `AssociationHandler` to all `Association` contained in this `PersistentEntity`.
`void` `doWithAssociations(SimpleAssociationHandler handler)`
`void` `doWithProperties(PropertyHandler<P> handler)` Applies the given `PropertyHandler` to all `PersistentProperty`s contained in this `PersistentEntity`.
`void` `doWithProperties(SimplePropertyHandler handler)`
`<A extends Annotation> A` `findAnnotation(Class<A> annotationType)` Looks up the annotation of the given type on the `PersistentEntity`.
`protected EvaluationContext` `getEvaluationContext(Object rootObject)` Obtain a `EvaluationContext` for a `rootObject`.
`protected EvaluationContext` `getEvaluationContext(Object rootObject, ExpressionDependencies dependencies)` Obtain a `EvaluationContext` for a `rootObject` given `ExpressionDependencies`.
`protected IsNewStrategy` `getFallbackIsNewStrategy()` Returns the default `IsNewStrategy` to be used.
`IdentifierAccessor` `getIdentifierAccessor(Object bean)` Returns the `IdentifierAccessor` for the given bean.
`P` `getIdProperty()` Returns the id property of the `PersistentEntity`.
`String` `getName()` The entity name including any package prefix.
`PreferredConstructor<T,P>` `getPersistenceConstructor()` Returns the `PreferredConstructor` to be used to instantiate objects of this `PersistentEntity`.
`Iterable<P>` `getPersistentProperties(Class<? extends Annotation> annotationType)` Returns all properties equipped with an `Annotation` of the given type.
`P` `getPersistentProperty(String name)` Obtains a `PersistentProperty` instance by name.
`<B> PersistentPropertyAccessor<B>` `getPropertyAccessor(B bean)` Returns a `PersistentPropertyAccessor` to access property values of the given bean.
`<B> PersistentPropertyPathAccessor<B>` `getPropertyPathAccessor(B bean)` Returns a `PersistentPropertyPathAccessor` to access property values of the given bean.
`Class<T>` `getType()` Returns the resolved Java type of this entity.
`Alias` `getTypeAlias()` Returns the alias to be used when storing type information.
`TypeInformation<T>` `getTypeInformation()` Returns the `TypeInformation` backing this `PersistentEntity`.
`P` `getVersionProperty()` Returns the version property of the `PersistentEntity`.
`boolean` `hasIdProperty()` Returns whether the `PersistentEntity` has an id property.
`boolean` `hasVersionProperty()` Returns whether the `PersistentEntity` has a version property.
`<A extends Annotation> boolean` `isAnnotationPresent(Class<A> annotationType)` Checks whether the annotation of the given type is present on the `PersistentEntity`.
`boolean` `isConstructorArgument(PersistentProperty<?> property)` Returns whether the given `PersistentProperty` is referred to by a constructor argument of the `PersistentEntity`.
`boolean` `isIdProperty(PersistentProperty<?> property)` Returns whether the given `PersistentProperty` is the id property of the entity.
`boolean` `isImmutable()` Returns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via the `PersistentPropertyAccessor` obtained via `PersistentEntity.getPropertyAccessor(Object)`.
`boolean` `isNew(Object bean)` Returns whether the given bean is considered new according to the static metadata.
`boolean` `isVersionProperty(PersistentProperty<?> property)` Returns whether the given `PersistentProperty` is the version property of the entity.
`Iterator<P>` `iterator()`
`boolean` `requiresPropertyPopulation()` Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.
`protected P` `returnPropertyIfBetterIdPropertyCandidateOrNull(P property)` Returns the given property if it is a better candidate for the id property than the current id property.
`void` `setEvaluationContextProvider(EvaluationContextProvider provider)` Sets the `EvaluationContextProvider` to be used by the entity.
`void` `setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory)` Sets the `PersistentPropertyAccessorFactory` for the entity.
`void` `verify()` Callback method to trigger validation of the `PersistentEntity`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.data.mapping.PersistentEntity

`getPersistentProperty, getRequiredAnnotation, getRequiredIdProperty, getRequiredPersistentProperty, getRequiredVersionProperty`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Constructor Detail

#### BasicPersistentEntity

    public BasicPersistentEntity(TypeInformation<T> information)

Creates a new `BasicPersistentEntity` from the given `TypeInformation`.

Parameters:
  `information` - must not be null.

#### BasicPersistentEntity

    public BasicPersistentEntity(TypeInformation<T> information,
                                 @Nullable
                                 Comparator<P> comparator)

Creates a new `BasicPersistentEntity` for the given `TypeInformation` and `Comparator`. The given `Comparator` will be used to define the order of the `PersistentProperty` instances added to the entity.

Parameters:
  `information` - must not be null.
  `comparator` - can be null.

### Method Detail

#### getPersistenceConstructor

    @Nullable
    public PreferredConstructor<T,P> getPersistenceConstructor()

Description copied from interface: `PersistentEntity`
Returns the `PreferredConstructor` to be used to instantiate objects of this `PersistentEntity`.

Specified by:
  `getPersistenceConstructor` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
  null in case no suitable constructor for automatic construction can be found. This usually indicates that the instantiation of the object of that persistent entity is done through either a customer `EntityInstantiator` or handled by custom conversion mechanisms entirely.

#### isConstructorArgument

    public boolean isConstructorArgument(PersistentProperty<?> property)

Description copied from interface: `PersistentEntity`
Returns whether the given `PersistentProperty` is referred to by a constructor argument of the `PersistentEntity`.

Specified by:
  `isConstructorArgument` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `property` - can be null.
Returns:
  true if the given `PersistentProperty` is referred to by a constructor argument or false if not or null.

#### isIdProperty

    public boolean isIdProperty(PersistentProperty<?> property)

Description copied from interface: `PersistentEntity`
Returns whether the given `PersistentProperty` is the id property of the entity.

Specified by:
  `isIdProperty` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `property` - can be null.
Returns:
  true given property is the entities id.

#### isVersionProperty

    public boolean isVersionProperty(PersistentProperty<?> property)

Description copied from interface: `PersistentEntity`
Returns whether the given `PersistentProperty` is the version property of the entity.

Specified by:
  `isVersionProperty` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `property` - can be null.
Returns:
  true given property is used as version.

#### getName

    public String getName()

Description copied from interface: `PersistentEntity`
The entity name including any package prefix.

Specified by:
  `getName` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
  must never return null.

#### getIdProperty

    @Nullable
    public P getIdProperty()

Description copied from interface: `PersistentEntity`
Returns the id property of the `PersistentEntity`. Can be null in case this is an entity completely handled by a custom conversion.

Specified by:
  `getIdProperty` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
  the id property of the `PersistentEntity`.

#### getVersionProperty

    @Nullable
    public P getVersionProperty()

Description copied from interface: `PersistentEntity`
Returns the version property of the `PersistentEntity`. Can be null in case no version property is available on the entity.

Specified by:
  `getVersionProperty` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
  the version property of the `PersistentEntity`.

#### hasIdProperty

    public boolean hasIdProperty()

Description copied from interface: `PersistentEntity`
Returns whether the `PersistentEntity` has an id property. If this call returns true, `PersistentEntity.getIdProperty()` will return a non-null value.

Specified by:
  `hasIdProperty` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
  true if entity has an id property.

#### hasVersionProperty

    public boolean hasVersionProperty()

Description copied from interface: `PersistentEntity`
Returns whether the `PersistentEntity` has a version property. If this call returns true, `PersistentEntity.getVersionProperty()` will return a non-null value.

Specified by:
  `hasVersionProperty` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
  true if entity has a version property.

#### addPersistentProperty

    public void addPersistentProperty(P property)

Description copied from interface: `MutablePersistentEntity`
Adds a `PersistentProperty` to the entity.

Specified by:
  `addPersistentProperty` in interface `MutablePersistentEntity<T,P extends PersistentProperty<P>>`

#### setEvaluationContextProvider

    public void setEvaluationContextProvider(EvaluationContextProvider provider)

Description copied from interface: `MutablePersistentEntity`
Sets the `EvaluationContextProvider` to be used by the entity.

Specified by:
  `setEvaluationContextProvider` in interface `MutablePersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `provider` - must not be null.

#### returnPropertyIfBetterIdPropertyCandidateOrNull

    @Nullable
    protected P returnPropertyIfBetterIdPropertyCandidateOrNull(P property)

Returns the given property if it is a better candidate for the id property than the current id property.

Parameters:
  `property` - the new id property candidate, will never be null.
Returns:
  the given id property or null if the given property is not an id property.

#### addAssociation

    public void addAssociation(Association<P> association)

Description copied from interface: `MutablePersistentEntity`
Adds an `Association` to the entity.

Specified by:
  `addAssociation` in interface `MutablePersistentEntity<T,P extends PersistentProperty<P>>`

#### getPersistentProperty

    @Nullable
    public P getPersistentProperty(String name)

Description copied from interface: `PersistentEntity`
Obtains a `PersistentProperty` instance by name.

Specified by:
  `getPersistentProperty` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `name` - The name of the property. Can be null.
Returns:
  the `PersistentProperty` or null if it doesn't exist.

#### getPersistentProperties

    public Iterable<P> getPersistentProperties(Class<? extends Annotation> annotationType)

Description copied from interface: `PersistentEntity`
Returns all properties equipped with an `Annotation` of the given type.

Specified by:
  `getPersistentProperties` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `annotationType` - must not be null.
Returns:
  empty `Iterator` if no match found. Never null.

#### getType

    public Class<T> getType()

Description copied from interface: `PersistentEntity`
Returns the resolved Java type of this entity.

Specified by:
  `getType` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
  The underlying Java class for this entity. Never null.

#### getTypeAlias

    public Alias getTypeAlias()

Description copied from interface: `PersistentEntity`
Returns the alias to be used when storing type information. Might be null to indicate that there was no alias defined through the mapping metadata.

Specified by:
  `getTypeAlias` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:

#### getTypeInformation

    public TypeInformation<T> getTypeInformation()

Description copied from interface: `PersistentEntity`
Returns the `TypeInformation` backing this `PersistentEntity`.

Specified by:
  `getTypeInformation` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:

#### doWithProperties

    public void doWithProperties(PropertyHandler<P> handler)

Description copied from interface: `PersistentEntity`
Applies the given `PropertyHandler` to all `PersistentProperty`s contained in this `PersistentEntity`.

Specified by:
  `doWithProperties` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `handler` - must not be null.

#### doWithProperties

    public void doWithProperties(SimplePropertyHandler handler)

Specified by:
  `doWithProperties` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`

#### doWithAssociations

    public void doWithAssociations(AssociationHandler<P> handler)

Description copied from interface: `PersistentEntity`
Applies the given `AssociationHandler` to all `Association` contained in this `PersistentEntity`.

Specified by:
  `doWithAssociations` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `handler` - must not be null.

#### doWithAssociations

    public void doWithAssociations(SimpleAssociationHandler handler)

Specified by:
  `doWithAssociations` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`

#### findAnnotation

    @Nullable
    public <A extends Annotation> A findAnnotation(Class<A> annotationType)

Description copied from interface: `PersistentEntity`
Looks up the annotation of the given type on the `PersistentEntity`.

Specified by:
  `findAnnotation` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `annotationType` - must not be null.
Returns:
  null if not found.

#### isAnnotationPresent

    public <A extends Annotation> boolean isAnnotationPresent(Class<A> annotationType)

Description copied from interface: `PersistentEntity`
Checks whether the annotation of the given type is present on the `PersistentEntity`.

Specified by:
  `isAnnotationPresent` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `annotationType` - must not be null.
Returns:
  true if `Annotation` of given type is present.

#### verify

    public void verify()

Description copied from interface: `MutablePersistentEntity`
Callback method to trigger validation of the `PersistentEntity`. As `MutablePersistentEntity` is not immutable there might be some verification steps necessary after the object has reached is final state.

Specified by:
  `verify` in interface `MutablePersistentEntity<T,P extends PersistentProperty<P>>`

#### setPersistentPropertyAccessorFactory

    public void setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory)

Description copied from interface: `MutablePersistentEntity`
Sets the `PersistentPropertyAccessorFactory` for the entity. A `PersistentPropertyAccessorFactory` creates `PersistentPropertyAccessor`s for instances of this entity.

Specified by:
  `setPersistentPropertyAccessorFactory` in interface `MutablePersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `factory` - must not be null.

#### getPropertyAccessor

    public <B> PersistentPropertyAccessor<B> getPropertyAccessor(B bean)

Description copied from interface: `PersistentEntity`
Returns a `PersistentPropertyAccessor` to access property values of the given bean.

Specified by:
  `getPropertyAccessor` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `bean` - must not be null.
Returns:
  new `PersistentPropertyAccessor`.

#### getPropertyPathAccessor

    public <B> PersistentPropertyPathAccessor<B> getPropertyPathAccessor(B bean)

Description copied from interface: `PersistentEntity`
Returns a `PersistentPropertyPathAccessor` to access property values of the given bean.

Specified by:
  `getPropertyPathAccessor` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `bean` - must not be null.
Returns:
  a new `PersistentPropertyPathAccessor`

#### getIdentifierAccessor

    public IdentifierAccessor getIdentifierAccessor(Object bean)

Description copied from interface: `PersistentEntity`
Returns the `IdentifierAccessor` for the given bean.

Specified by:
  `getIdentifierAccessor` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `bean` - must not be null.
Returns:
  new `IdentifierAccessor`.

#### isNew

    public boolean isNew(Object bean)

Description copied from interface: `PersistentEntity`
Returns whether the given bean is considered new according to the static metadata.

Specified by:
  `isNew` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Parameters:
  `bean` - must not be null.
Returns:
  whether the given bean is considered a new instance.

#### isImmutable

    public boolean isImmutable()

Description copied from interface: `PersistentEntity`
Returns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via the `PersistentPropertyAccessor` obtained via `PersistentEntity.getPropertyAccessor(Object)`.

Specified by:
  `isImmutable` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:
See Also:
  `Immutable`

#### requiresPropertyPopulation

    public boolean requiresPropertyPopulation()

Description copied from interface: `PersistentEntity`
Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.

Specified by:
  `requiresPropertyPopulation` in interface `PersistentEntity<T,P extends PersistentProperty<P>>`
Returns:

#### iterator

    public Iterator<P> iterator()

Specified by:
  `iterator` in interface `Iterable<P extends PersistentProperty<P>>`

#### getEvaluationContext

    protected EvaluationContext getEvaluationContext(Object rootObject)

Obtain a `EvaluationContext` for a `rootObject`.

Parameters:
  `rootObject` - must not be null.
Returns:
  the evaluation context including all potential extensions.
Since:
  2.1

#### getEvaluationContext

    protected EvaluationContext getEvaluationContext(Object rootObject,
                                                     ExpressionDependencies dependencies)

Obtain a `EvaluationContext` for a `rootObject` given `ExpressionDependencies`.

Parameters:
  `rootObject` - must not be null.
  `dependencies` - must not be null.
Returns:
  the evaluation context with extensions loaded that satisfy `ExpressionDependencies`.
Since:
  2.4.2

#### getFallbackIsNewStrategy

    protected IsNewStrategy getFallbackIsNewStrategy()

Returns the default `IsNewStrategy` to be used. Will be a `PersistentEntityIsNewStrategy` by default. Note, that this strategy only gets used if the entity doesn't implement `Persistable` as this indicates the user wants to be in control over whether an entity is new or not.

Returns:
Since:
  2.1