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
PersistentEntitys.- Author:
- Oliver Gierke, Jon Brisbin, Patryk Wasik, Thomas Darimont, Christoph Strobl, Mark Paluch, Johannes Englmeier
-
Constructor Summary
ConstructorsConstructorDescriptionBasicPersistentEntity(TypeInformation<T> information) Creates a newBasicPersistentEntityfrom the givenTypeInformation.BasicPersistentEntity(TypeInformation<T> information, Comparator<P> comparator) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAssociation(Association<P> association) Adds anAssociationto the entity.voidaddPersistentProperty(P property) Adds aPersistentPropertyto the entity.voiddoWithAssociations(AssociationHandler<P> handler) voidvoiddoWithProperties(PropertyHandler<P> handler) voiddoWithProperties(SimplePropertyHandler handler) <A extends Annotation>
AfindAnnotation(Class<A> annotationType) Looks up the annotation of the given type on thePersistentEntity.protected EvaluationContextgetEvaluationContext(Object rootObject) Obtain aEvaluationContextfor arootObject.protected EvaluationContextgetEvaluationContext(Object rootObject, ExpressionDependencies dependencies) protected IsNewStrategyReturns the defaultIsNewStrategyto be used.getIdentifierAccessor(Object bean) Returns theIdentifierAccessorfor the given bean.Returns the id property of thePersistentEntity.Returns theInstanceCreatorMetadatato be used to instantiate objects of thisPersistentEntity.getName()The entity name including any package prefix.Returns thePreferredConstructorto be used to instantiate objects of thisPersistentEntity.getPersistentProperties(Class<? extends Annotation> annotationType) Returns all properties equipped with anAnnotationof the given type.getPersistentProperty(String name) Obtains aPersistentPropertyinstance by name.<B> PersistentPropertyAccessor<B>getPropertyAccessor(B bean) Returns aPersistentPropertyAccessorto access property values of the given bean.getPropertyPathAccessor(B bean) Returns aPersistentPropertyPathAccessorto 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 theTypeInformationbacking thisPersistentEntity.Returns the version property of thePersistentEntity.booleanReturns whether thePersistentEntityhas an id property.booleanReturns whether thePersistentEntityhas a version property.<A extends Annotation>
booleanisAnnotationPresent(Class<A> annotationType) Checks whether the annotation of the given type is present on thePersistentEntity.booleanisCreatorArgument(PersistentProperty<?> property) Returns whether the givenPersistentPropertyis referred to by a creator argument of thePersistentEntity.booleanisIdProperty(PersistentProperty<?> property) Returns whether the givenPersistentPropertyis the id property of the entity.booleanReturns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via thePersistentPropertyAccessorobtained viaPersistentEntity.getPropertyAccessor(Object).booleanReturns whether the given bean is considered new according to the static metadata.booleanisVersionProperty(PersistentProperty<?> property) Returns whether the givenPersistentPropertyis the version property of the entity.iterator()booleanReturns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.protected PReturns the given property if it is a better candidate for the id property than the current id property.voidSets theEvaluationContextProviderto be used by the entity.voidSets thePersistentPropertyAccessorFactoryfor the entity.voidverify()Callback method to trigger validation of thePersistentEntity.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.springframework.data.mapping.PersistentEntity
doWithAll, getPersistentProperty, getRequiredAnnotation, getRequiredIdProperty, getRequiredPersistentProperty, getRequiredVersionProperty, isConstructorArgument
-
Constructor Details
-
BasicPersistentEntity
Creates a newBasicPersistentEntityfrom the givenTypeInformation.- Parameters:
information- must not be null.
-
BasicPersistentEntity
Creates a newBasicPersistentEntityfor the givenTypeInformationandComparator. The givenComparatorwill be used to define the order of thePersistentPropertyinstances added to the entity.- Parameters:
information- must not be null.comparator- can be null.
-
-
Method Details
-
getPersistenceConstructor
Description copied from interface:PersistentEntityReturns thePreferredConstructorto be used to instantiate objects of thisPersistentEntity.- Specified by:
getPersistenceConstructorin interfacePersistentEntity<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
EntityInstantiatoror handled by custom conversion mechanisms entirely.
-
getInstanceCreatorMetadata
Description copied from interface:PersistentEntityReturns theInstanceCreatorMetadatato be used to instantiate objects of thisPersistentEntity.- Specified by:
getInstanceCreatorMetadatain 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
EntityInstantiatoror handled by custom conversion mechanisms entirely.
-
isCreatorArgument
Description copied from interface:PersistentEntityReturns whether the givenPersistentPropertyis referred to by a creator argument of thePersistentEntity.- Specified by:
isCreatorArgumentin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
property- can be null.- Returns:
- true if the given
PersistentPropertyis referred to by a creator argument or false if not or null.
-
isIdProperty
Description copied from interface:PersistentEntityReturns whether the givenPersistentPropertyis the id property of the entity.- Specified by:
isIdPropertyin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
property- can be null.- Returns:
- true given property is the entities id.
-
isVersionProperty
Description copied from interface:PersistentEntityReturns whether the givenPersistentPropertyis the version property of the entity.- Specified by:
isVersionPropertyin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
property- can be null.- Returns:
- true given property is used as version.
-
getName
Description copied from interface:PersistentEntityThe entity name including any package prefix.- Specified by:
getNamein interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
- must never return null.
-
getIdProperty
Description copied from interface:PersistentEntityReturns the id property of thePersistentEntity. Can be null in case this is an entity completely handled by a custom conversion.- Specified by:
getIdPropertyin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
- the id property of the
PersistentEntity.
-
getVersionProperty
Description copied from interface:PersistentEntityReturns the version property of thePersistentEntity. Can be null in case no version property is available on the entity.- Specified by:
getVersionPropertyin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
- the version property of the
PersistentEntity.
-
hasIdProperty
public boolean hasIdProperty()Description copied from interface:PersistentEntityReturns whether thePersistentEntityhas an id property. If this call returns true,PersistentEntity.getIdProperty()will return a non-null value.- Specified by:
hasIdPropertyin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
- true if entity has an id property.
-
hasVersionProperty
public boolean hasVersionProperty()Description copied from interface:PersistentEntityReturns whether thePersistentEntityhas a version property. If this call returns true,PersistentEntity.getVersionProperty()will return a non-null value.- Specified by:
hasVersionPropertyin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
- true if entity has a version property.
-
addPersistentProperty
Description copied from interface:MutablePersistentEntityAdds aPersistentPropertyto the entity.- Specified by:
addPersistentPropertyin interfaceMutablePersistentEntity<T,P extends PersistentProperty<P>>
-
setEvaluationContextProvider
Description copied from interface:MutablePersistentEntitySets theEvaluationContextProviderto be used by the entity.- Specified by:
setEvaluationContextProviderin interfaceMutablePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
provider- must not be null.
-
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:MutablePersistentEntityAdds anAssociationto the entity.- Specified by:
addAssociationin interfaceMutablePersistentEntity<T,P extends PersistentProperty<P>>
-
getPersistentProperty
Description copied from interface:PersistentEntityObtains aPersistentPropertyinstance by name.- Specified by:
getPersistentPropertyin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
name- The name of the property. Can be null.- Returns:
- the
PersistentPropertyor null if it doesn't exist.
-
getPersistentProperties
Description copied from interface:PersistentEntityReturns all properties equipped with anAnnotationof the given type.- Specified by:
getPersistentPropertiesin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
annotationType- must not be null.- Returns:
- empty
Iteratorif no match found. Never null.
-
getType
Description copied from interface:PersistentEntityReturns the resolved Java type of this entity.- Specified by:
getTypein interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
- The underlying Java class for this entity. Never null.
-
getTypeAlias
Description copied from interface:PersistentEntityReturns 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:
getTypeAliasin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
-
getTypeInformation
Description copied from interface:PersistentEntityReturns theTypeInformationbacking thisPersistentEntity.- Specified by:
getTypeInformationin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
-
doWithProperties
Description copied from interface:PersistentEntity- Specified by:
doWithPropertiesin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
handler- must not be null.
-
doWithProperties
- Specified by:
doWithPropertiesin interfacePersistentEntity<T,P extends PersistentProperty<P>>
-
doWithAssociations
Description copied from interface:PersistentEntity- Specified by:
doWithAssociationsin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
handler- must not be null.
-
doWithAssociations
- Specified by:
doWithAssociationsin interfacePersistentEntity<T,P extends PersistentProperty<P>>
-
findAnnotation
Description copied from interface:PersistentEntityLooks up the annotation of the given type on thePersistentEntity.- Specified by:
findAnnotationin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
annotationType- must not be null.- Returns:
- null if not found.
-
isAnnotationPresent
Description copied from interface:PersistentEntityChecks whether the annotation of the given type is present on thePersistentEntity.- Specified by:
isAnnotationPresentin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
annotationType- must not be null.- Returns:
- true if
Annotationof given type is present.
-
verify
public void verify()Description copied from interface:MutablePersistentEntityCallback method to trigger validation of thePersistentEntity. AsMutablePersistentEntityis not immutable there might be some verification steps necessary after the object has reached is final state.- Specified by:
verifyin interfaceMutablePersistentEntity<T,P extends PersistentProperty<P>>
-
setPersistentPropertyAccessorFactory
Description copied from interface:MutablePersistentEntitySets thePersistentPropertyAccessorFactoryfor the entity. APersistentPropertyAccessorFactorycreatesPersistentPropertyAccessors for instances of this entity.- Specified by:
setPersistentPropertyAccessorFactoryin interfaceMutablePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
factory- must not be null.
-
getPropertyAccessor
Description copied from interface:PersistentEntityReturns aPersistentPropertyAccessorto access property values of the given bean.- Specified by:
getPropertyAccessorin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
bean- must not be null.- Returns:
- new
PersistentPropertyAccessor.
-
getPropertyPathAccessor
Description copied from interface:PersistentEntityReturns aPersistentPropertyPathAccessorto access property values of the given bean.- Specified by:
getPropertyPathAccessorin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
bean- must not be null.- Returns:
- a new
PersistentPropertyPathAccessor
-
getIdentifierAccessor
Description copied from interface:PersistentEntityReturns theIdentifierAccessorfor the given bean.- Specified by:
getIdentifierAccessorin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Parameters:
bean- must not be null.- Returns:
- new
IdentifierAccessor.
-
isNew
Description copied from interface:PersistentEntityReturns whether the given bean is considered new according to the static metadata.- Specified by:
isNewin 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:PersistentEntityReturns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via thePersistentPropertyAccessorobtained viaPersistentEntity.getPropertyAccessor(Object).- Specified by:
isImmutablein interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
- See Also:
-
requiresPropertyPopulation
public boolean requiresPropertyPopulation()Description copied from interface:PersistentEntityReturns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.- Specified by:
requiresPropertyPopulationin interfacePersistentEntity<T,P extends PersistentProperty<P>> - Returns:
-
iterator
-
getEvaluationContext
Obtain aEvaluationContextfor 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
-
getFallbackIsNewStrategy
Returns the defaultIsNewStrategyto be used. Will be aPersistentEntityIsNewStrategyby default. Note, that this strategy only gets used if the entity doesn't implementPersistableas this indicates the user wants to be in control over whether an entity is new or not.- Returns:
- Since:
- 2.1
-