Package org.springframework.data.mapping
Interface PersistentEntity<T,P extends PersistentProperty<P>>
- All Superinterfaces:
Iterable<P>
- All Known Subinterfaces:
MutablePersistentEntity<T,
P>
- All Known Implementing Classes:
BasicPersistentEntity
Represents a persistent entity. The order of the properties returned via the
Iterator
is not guaranteed.- Author:
- Oliver Gierke, Graeme Rocher, Jon Brisbin, Patryk Wasik, Mark Paluch, Christoph Strobl, Johannes Englmeier
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
doWithAll
(PropertyHandler<P> handler) Applies the givenPropertyHandler
to both allPersistentProperty
s as well as all inverse properties of allAssociation
s.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
.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.default P
getPersistentProperty
(Class<? extends Annotation> annotationType) Returns the first property 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.default <A extends Annotation>
AgetRequiredAnnotation
(Class<A> annotationType) Returns the required annotation of the given type on thePersistentEntity
.default P
Returns the id property of thePersistentEntity
.default P
Returns thePersistentProperty
with the given name.default P
Returns the version property of thePersistentEntity
.getType()
Returns the resolved Java type of this entity.Returns the alias to be used when storing type information.Returns theTypeInformation
backing thisPersistentEntity
.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 viagetPropertyAccessor(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.boolean
Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
getName
String getName()The entity name including any package prefix.- Returns:
- must never return null.
-
getInstanceCreatorMetadata
Returns theInstanceCreatorMetadata
to be used to instantiate objects of thisPersistentEntity
.- 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. - Since:
- 3.0
-
isCreatorArgument
Returns whether the givenPersistentProperty
is referred to by a creator argument of thePersistentEntity
.- 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
Returns whether the givenPersistentProperty
is the id property of the entity.- Parameters:
property
- can be null.- Returns:
- true given property is the entities id.
-
isVersionProperty
Returns whether the givenPersistentProperty
is the version property of the entity.- Parameters:
property
- can be null.- Returns:
- true given property is used as version.
-
getIdProperty
Returns the id property of thePersistentEntity
. Can be null in case this is an entity completely handled by a custom conversion.- Returns:
- the id property of the
PersistentEntity
.
-
getRequiredIdProperty
Returns the id property of thePersistentEntity
.- Returns:
- the id property of the
PersistentEntity
. - Throws:
IllegalStateException
- ifPersistentEntity
does not define an id property.- Since:
- 2.0
-
getVersionProperty
Returns the version property of thePersistentEntity
. Can be null in case no version property is available on the entity.- Returns:
- the version property of the
PersistentEntity
.
-
getRequiredVersionProperty
Returns the version property of thePersistentEntity
. Can be null in case no version property is available on the entity.- Returns:
- the version property of the
PersistentEntity
. - Throws:
IllegalStateException
- ifPersistentEntity
does not define a version property.- Since:
- 2.0
-
getPersistentProperty
Obtains aPersistentProperty
instance by name.- Parameters:
name
- The name of the property. Can be null.- Returns:
- the
PersistentProperty
or null if it doesn't exist.
-
getRequiredPersistentProperty
Returns thePersistentProperty
with the given name.- Parameters:
name
- the name of the property. Can be null or empty.- Returns:
- the
PersistentProperty
with the given name. - Throws:
IllegalStateException
- in case no property with the given name exists.
-
getPersistentProperty
Returns the first property equipped with anAnnotation
of the given type.- Parameters:
annotationType
- must not be null.- Returns:
- null if no property found with given annotation type.
- Since:
- 1.8
-
getPersistentProperties
Returns all properties equipped with anAnnotation
of the given type.- Parameters:
annotationType
- must not be null.- Returns:
- empty
Iterator
if no match found. Never null. - Since:
- 2.0
-
hasIdProperty
boolean hasIdProperty()Returns whether thePersistentEntity
has an id property. If this call returns true,getIdProperty()
will return a non-null value.- Returns:
- true if entity has an id property.
-
hasVersionProperty
boolean hasVersionProperty()Returns whether thePersistentEntity
has a version property. If this call returns true,getVersionProperty()
will return a non-null value.- Returns:
- true if entity has a version property.
-
getType
Returns the resolved Java type of this entity.- Returns:
- The underlying Java class for this entity. Never null.
-
getTypeAlias
Alias getTypeAlias()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.- Returns:
-
getTypeInformation
TypeInformation<T> getTypeInformation()Returns theTypeInformation
backing thisPersistentEntity
.- Returns:
-
doWithProperties
Applies the givenPropertyHandler
to allPersistentProperty
s contained in thisPersistentEntity
. The iteration order is undefined.- Parameters:
handler
- must not be null.
-
doWithProperties
Applies the givenSimplePropertyHandler
to allPersistentProperty
s contained in thisPersistentEntity
. The iteration order is undefined.- Parameters:
handler
- must not be null.
-
doWithAssociations
Applies the givenAssociationHandler
to allAssociation
contained in thisPersistentEntity
. The iteration order is undefined.- Parameters:
handler
- must not be null.
-
doWithAssociations
Applies the givenSimpleAssociationHandler
to allAssociation
contained in thisPersistentEntity
. The iteration order is undefined.- Parameters:
handler
- must not be null.
-
doWithAll
Applies the givenPropertyHandler
to both allPersistentProperty
s as well as all inverse properties of allAssociation
s. The iteration order is undefined.- Parameters:
handler
- must not be null.- Since:
- 2.5
-
findAnnotation
Looks up the annotation of the given type on thePersistentEntity
.- Parameters:
annotationType
- must not be null.- Returns:
- null if not found.
- Since:
- 1.8
-
getRequiredAnnotation
default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType) throws IllegalStateException Returns the required annotation of the given type on thePersistentEntity
.- Parameters:
annotationType
- must not be null.- Returns:
- the annotation.
- Throws:
IllegalStateException
- if the requiredannotationType
is not found.- Since:
- 2.0
-
isAnnotationPresent
Checks whether the annotation of the given type is present on thePersistentEntity
.- Parameters:
annotationType
- must not be null.- Returns:
- true if
Annotation
of given type is present. - Since:
- 2.0
-
getPropertyAccessor
Returns aPersistentPropertyAccessor
to access property values of the given bean.- Parameters:
bean
- must not be null.- Returns:
- new
PersistentPropertyAccessor
. - Since:
- 1.10
-
getPropertyPathAccessor
Returns aPersistentPropertyPathAccessor
to access property values of the given bean.- Parameters:
bean
- must not be null.- Returns:
- a new
PersistentPropertyPathAccessor
- Since:
- 2.3
-
getIdentifierAccessor
Returns theIdentifierAccessor
for the given bean.- Parameters:
bean
- must not be null.- Returns:
- new
IdentifierAccessor
. - Since:
- 1.10
-
isNew
Returns whether the given bean is considered new according to the static metadata.- Parameters:
bean
- must not be null.- Returns:
- whether the given bean is considered a new instance.
- Throws:
IllegalArgumentException
- in case the given bean is not an instance of the typ represented by thePersistentEntity
.
-
isImmutable
boolean isImmutable()Returns whether the entity is considered immutable, i.e. clients shouldn't attempt to change instances via thePersistentPropertyAccessor
obtained viagetPropertyAccessor(Object)
.- Returns:
- Since:
- 2.1
- See Also:
-
requiresPropertyPopulation
boolean requiresPropertyPopulation()Returns whether the entity needs properties to be populated, i.e. if any property exists that's not initialized by the constructor.- Returns:
- Since:
- 2.1
-