Class BasicPersistentEntity<T,P extends PersistentProperty<P>>
java.lang.Object
org.springframework.data.mapping.model.BasicPersistentEntity<T,P>
- All Implemented Interfaces:
Iterable<P>
,Aware
,EnvironmentAware
,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, Johannes Englmeier
-
Constructor Summary
ConstructorDescriptionBasicPersistentEntity
(TypeInformation<T> information) Creates a newBasicPersistentEntity
from the givenTypeInformation
.BasicPersistentEntity
(TypeInformation<T> information, Comparator<P> comparator) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAssociation
(Association<P> association) Adds anAssociation
to the entity.void
addPersistentProperty
(P property) Adds aPersistentProperty
to the entity.void
doWithAssociations
(AssociationHandler<P> handler) void
void
doWithProperties
(PropertyHandler<P> handler) void
doWithProperties
(SimplePropertyHandler handler) Applies the givenSimplePropertyHandler
to allPersistentProperty
s contained in thisPersistentEntity
.<A extends Annotation>
AfindAnnotation
(Class<A> annotationType) Looks up the annotation of the given type on thePersistentEntity
.protected EvaluationContext
getEvaluationContext
(Object rootObject) Obtain aEvaluationContext
for arootObject
.protected EvaluationContext
getEvaluationContext
(Object rootObject, ExpressionDependencies dependencies) protected IsNewStrategy
Returns the defaultIsNewStrategy
to be used.getIdentifierAccessor
(Object bean) Returns theIdentifierAccessor
for the given bean.Returns the id property of thePersistentEntity
.Returns theInstanceCreatorMetadata
to be used to instantiate objects of thisPersistentEntity
.getName()
The entity name including any package prefix.getPersistentProperties
(Class<? extends Annotation> annotationType) Returns all properties equipped with anAnnotation
of the given type.getPersistentProperty
(String name) Obtains aPersistentProperty
instance by name.<B> PersistentPropertyAccessor<B>
getPropertyAccessor
(B bean) Returns aPersistentPropertyAccessor
to access property values of the given bean.getPropertyPathAccessor
(B bean) Returns aPersistentPropertyPathAccessor
to access property values of the given bean.getType()
Returns the resolved Java type of this entity.Returns the alias to be used when storing type information.Returns theTypeInformation
backing thisPersistentEntity
.protected ValueEvaluationContext
getValueEvaluationContext
(Object rootObject) Obtain aValueEvaluationContext
for arootObject
.protected ValueEvaluationContext
getValueEvaluationContext
(Object rootObject, ExpressionDependencies dependencies) Returns the version property of thePersistentEntity
.boolean
Returns whether thePersistentEntity
has an id property.boolean
Returns whether thePersistentEntity
has a version property.<A extends Annotation>
booleanisAnnotationPresent
(Class<A> annotationType) Checks whether the annotation of the given type is present on thePersistentEntity
.boolean
isCreatorArgument
(PersistentProperty<?> property) Returns whether the givenPersistentProperty
is referred to by a creator argument of thePersistentEntity
.boolean
isIdProperty
(PersistentProperty<?> property) Returns whether the givenPersistentProperty
is the id property of the entity.boolean
Returns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via thePersistentPropertyAccessor
obtained viaPersistentEntity.getPropertyAccessor(Object)
.boolean
Returns whether the given bean is considered new according to the static metadata.boolean
isVersionProperty
(PersistentProperty<?> property) Returns whether the givenPersistentProperty
is the version property of the entity.iterator()
boolean
Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.protected P
Returns the given property if it is a better candidate for the id property than the current id property.void
setEnvironment
(Environment environment) void
Sets theEvaluationContextProvider
to be used by the entity.void
Sets thePersistentPropertyAccessorFactory
for the entity.void
verify()
Callback method to trigger validation of thePersistentEntity
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.springframework.data.mapping.PersistentEntity
doWithAll, getPersistentProperty, getRequiredAnnotation, getRequiredIdProperty, getRequiredPersistentProperty, getRequiredVersionProperty
-
Constructor Details
-
BasicPersistentEntity
Creates a newBasicPersistentEntity
from the givenTypeInformation
.- Parameters:
information
- must not be null.
-
BasicPersistentEntity
Creates a newBasicPersistentEntity
for the givenTypeInformation
andComparator
. The givenComparator
will be used to define the order of thePersistentProperty
instances added to the entity.- Parameters:
information
- must not be null.comparator
- can be null.
-
-
Method Details
-
getInstanceCreatorMetadata
Description copied from interface:PersistentEntity
Returns theInstanceCreatorMetadata
to be used to instantiate objects of thisPersistentEntity
.- Specified by:
getInstanceCreatorMetadata
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- null in case no suitable creation mechanism 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.
-
isCreatorArgument
Description copied from interface:PersistentEntity
Returns whether the givenPersistentProperty
is referred to by a creator argument of thePersistentEntity
.- Specified by:
isCreatorArgument
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
property
- can be null.- Returns:
- true if the given
PersistentProperty
is referred to by a creator argument or false if not or null.
-
isIdProperty
Description copied from interface:PersistentEntity
Returns whether the givenPersistentProperty
is the id property of the entity.- Specified by:
isIdProperty
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
property
- can be null.- Returns:
- true given property is the entities id.
-
isVersionProperty
Description copied from interface:PersistentEntity
Returns whether the givenPersistentProperty
is the version property of the entity.- Specified by:
isVersionProperty
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
property
- can be null.- Returns:
- true given property is used as version.
-
getName
Description copied from interface:PersistentEntity
The entity name including any package prefix.- Specified by:
getName
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- must never return null.
-
getIdProperty
Description copied from interface:PersistentEntity
Returns the id property of thePersistentEntity
. Can be null in case this is an entity completely handled by a custom conversion.- Specified by:
getIdProperty
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- the id property of the
PersistentEntity
.
-
getVersionProperty
Description copied from interface:PersistentEntity
Returns the version property of thePersistentEntity
. Can be null in case no version property is available on the entity.- Specified by:
getVersionProperty
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- the version property of the
PersistentEntity
.
-
hasIdProperty
public boolean hasIdProperty()Description copied from interface:PersistentEntity
Returns whether thePersistentEntity
has an id property. If this call returns true,PersistentEntity.getIdProperty()
will return a non-null value.- Specified by:
hasIdProperty
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- true if entity has an id property.
-
hasVersionProperty
public boolean hasVersionProperty()Description copied from interface:PersistentEntity
Returns whether thePersistentEntity
has a version property. If this call returns true,PersistentEntity.getVersionProperty()
will return a non-null value.- Specified by:
hasVersionProperty
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- true if entity has a version property.
-
addPersistentProperty
Description copied from interface:MutablePersistentEntity
Adds aPersistentProperty
to the entity.- Specified by:
addPersistentProperty
in interfaceMutablePersistentEntity<T,
P extends PersistentProperty<P>>
-
setEvaluationContextProvider
Description copied from interface:MutablePersistentEntity
Sets theEvaluationContextProvider
to be used by the entity.- Specified by:
setEvaluationContextProvider
in interfaceMutablePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
provider
- must not be null.
-
setEnvironment
- Specified by:
setEnvironment
in interfaceEnvironmentAware
- Parameters:
environment
- theEnvironment
that this component runs in.- Since:
- 3.3
-
returnPropertyIfBetterIdPropertyCandidateOrNull
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
Description copied from interface:MutablePersistentEntity
Adds anAssociation
to the entity.- Specified by:
addAssociation
in interfaceMutablePersistentEntity<T,
P extends PersistentProperty<P>>
-
getPersistentProperty
Description copied from interface:PersistentEntity
Obtains aPersistentProperty
instance by name.- Specified by:
getPersistentProperty
in interfacePersistentEntity<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
Description copied from interface:PersistentEntity
Returns all properties equipped with anAnnotation
of the given type.- Specified by:
getPersistentProperties
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
annotationType
- must not be null.- Returns:
- empty
Iterator
if no match found. Never null.
-
getType
Description copied from interface:PersistentEntity
Returns the resolved Java type of this entity.- Specified by:
getType
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- The underlying Java class for this entity. Never null.
-
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 interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
-
getTypeInformation
Description copied from interface:PersistentEntity
Returns theTypeInformation
backing thisPersistentEntity
.- Specified by:
getTypeInformation
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
-
doWithProperties
Description copied from interface:PersistentEntity
Applies the givenPropertyHandler
to allPersistentProperty
s contained in thisPersistentEntity
. The iteration order is undefined.- Specified by:
doWithProperties
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
handler
- must not be null.
-
doWithProperties
Description copied from interface:PersistentEntity
Applies the givenSimplePropertyHandler
to allPersistentProperty
s contained in thisPersistentEntity
. The iteration order is undefined.- Specified by:
doWithProperties
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
handler
- must not be null.
-
doWithAssociations
Description copied from interface:PersistentEntity
Applies the givenAssociationHandler
to allAssociation
contained in thisPersistentEntity
. The iteration order is undefined.- Specified by:
doWithAssociations
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
handler
- must not be null.
-
doWithAssociations
Description copied from interface:PersistentEntity
Applies the givenSimpleAssociationHandler
to allAssociation
contained in thisPersistentEntity
. The iteration order is undefined.- Specified by:
doWithAssociations
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
handler
- must not be null.
-
findAnnotation
Description copied from interface:PersistentEntity
Looks up the annotation of the given type on thePersistentEntity
.- Specified by:
findAnnotation
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
annotationType
- must not be null.- Returns:
- null if not found.
-
isAnnotationPresent
Description copied from interface:PersistentEntity
Checks whether the annotation of the given type is present on thePersistentEntity
.- Specified by:
isAnnotationPresent
in interfacePersistentEntity<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 thePersistentEntity
. AsMutablePersistentEntity
is not immutable there might be some verification steps necessary after the object has reached is final state.- Specified by:
verify
in interfaceMutablePersistentEntity<T,
P extends PersistentProperty<P>>
-
setPersistentPropertyAccessorFactory
Description copied from interface:MutablePersistentEntity
Sets thePersistentPropertyAccessorFactory
for the entity. APersistentPropertyAccessorFactory
createsPersistentPropertyAccessor
s for instances of this entity.- Specified by:
setPersistentPropertyAccessorFactory
in interfaceMutablePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
factory
- must not be null.
-
getPropertyAccessor
Description copied from interface:PersistentEntity
Returns aPersistentPropertyAccessor
to access property values of the given bean.- Specified by:
getPropertyAccessor
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
bean
- must not be null.- Returns:
- new
PersistentPropertyAccessor
.
-
getPropertyPathAccessor
Description copied from interface:PersistentEntity
Returns aPersistentPropertyPathAccessor
to access property values of the given bean.- Specified by:
getPropertyPathAccessor
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
bean
- must not be null.- Returns:
- a new
PersistentPropertyPathAccessor
-
getIdentifierAccessor
Description copied from interface:PersistentEntity
Returns theIdentifierAccessor
for the given bean.- Specified by:
getIdentifierAccessor
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Parameters:
bean
- must not be null.- Returns:
- new
IdentifierAccessor
.
-
isNew
Description copied from interface:PersistentEntity
Returns whether the given bean is considered new according to the static metadata.- Specified by:
isNew
in interfacePersistentEntity<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 thePersistentPropertyAccessor
obtained viaPersistentEntity.getPropertyAccessor(Object)
.- Specified by:
isImmutable
in interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
- See Also:
-
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 interfacePersistentEntity<T,
P extends PersistentProperty<P>> - Returns:
-
iterator
-
getEvaluationContext
Obtain aEvaluationContext
for arootObject
.- 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) - Parameters:
rootObject
- must not be null.dependencies
- must not be null.- Returns:
- the evaluation context with extensions loaded that satisfy
ExpressionDependencies
. - Since:
- 2.5
-
getValueEvaluationContext
Obtain aValueEvaluationContext
for arootObject
.- Parameters:
rootObject
- must not be null.- Returns:
- the evaluation context including all potential extensions.
- Since:
- 3.3
-
getValueEvaluationContext
protected ValueEvaluationContext getValueEvaluationContext(Object rootObject, ExpressionDependencies dependencies) - Parameters:
rootObject
- must not be null.dependencies
- must not be null.- Returns:
- the evaluation context with extensions loaded that satisfy
ExpressionDependencies
. - Since:
- 3.3
-
getFallbackIsNewStrategy
Returns the defaultIsNewStrategy
to be used. Will be aPersistentEntityIsNewStrategy
by default. Note, that this strategy only gets used if the entity doesn't implementPersistable
as this indicates the user wants to be in control over whether an entity is new or not.- Returns:
- Since:
- 2.1
-