Package org.springframework.data.mapping
Interface PersistentProperty<P extends PersistentProperty<P>>
- All Known Implementing Classes:
AbstractPersistentProperty
,AnnotationBasedPersistentProperty
public interface PersistentProperty<P extends PersistentProperty<P>>
- Author:
- Graeme Rocher, Jon Brisbin, Oliver Gierke, Mark Paluch, Jens Schauder, Christoph Strobl, Johannes Englmeier
-
Method Summary
Modifier and TypeMethodDescription<A extends Annotation>
AfindAnnotation
(Class<A> annotationType) Looks up the annotation of the given type on thePersistentProperty
.<A extends Annotation>
AfindPropertyOrOwnerAnnotation
(Class<A> annotationType) Looks up the annotation of the given type on the property and the owning type if no annotation can be found on it.default <T> PersistentPropertyAccessor<T>
getAccessorForOwner
(T owner) Returns aPersistentPropertyAccessor
for the current property's owning value.Class<?>
Returns the actual type of the property.Class<?>
Return the type the property refers to in case it's an association, i.e.Return the type the property refers to in case it's an association, i.e.Class<?>
Returns the component type of the type if it is aCollection
.getField()
Returns the getter method to access the property value if available.Class<?>
Returns the type of the values if the property is aMap
.getName()
The name of the propertygetOwner()
Returns thePersistentEntity
owning the currentPersistentProperty
.Iterable<? extends TypeInformation<?>>
Returns the detectedTypeInformations
if the property references aPersistentEntity
.Class<?>
Returns the raw type as it's pulled from from the reflected property.default <A extends Annotation>
AgetRequiredAnnotation
(Class<A> annotationType) Looks up the annotation of the given type on thePersistentProperty
.default Association<P>
Get theAssociation
of this property.default Field
default Method
default Method
default Method
Returns the setter method to set a property value.Class<?>
getType()
The type of the propertyReturns theTypeInformation
of the property.Returns the withMethod
to set a property value on a new object instance.default boolean
hasActualTypeAnnotation
(Class<? extends Annotation> annotationType) Returns whether the actual type of the property carries the given annotation.boolean
isAnnotationPresent
(Class<? extends Annotation> annotationType) Returns whether thePersistentProperty
has an annotation of the given type.boolean
isArray()
Returns whether the property is an array.boolean
Returns whether the property is anAssociation
.boolean
Returns whether the property is aCollection
,Iterable
or an array.boolean
isEntity()
Returns whether the type of thePersistentProperty
is actually to be regarded asPersistentEntity
in turn.boolean
Returns whether the property is a potential identifier property of the owningPersistentEntity
.boolean
Returns whether the current property is immutable, i.e. if there is no setter or the backingField
isfinal
.boolean
isMap()
Returns whether the property is aMap
.boolean
Returns whether the current property is readable throughPersistentPropertyAccessor
, i.e. if it is notisTransient()
, if the value can be set on the current instance or read to create a new instance as pergetWither()
or via Kotlin Copy methods.boolean
Returns whether the property is transient.boolean
Returns whether the current property is a potential version property of the owningPersistentEntity
.boolean
Returns whether the current property is writable, i.e. if the value held for it shall be written to the data store.boolean
Returns whether property access shall be used for reading the property value.
-
Method Details
-
getOwner
PersistentEntity<?,P> getOwner()Returns thePersistentEntity
owning the currentPersistentProperty
.- Returns:
- never null.
-
getName
String getName()The name of the property- Returns:
- The property name
-
getType
Class<?> getType()The type of the property- Returns:
- The property type
-
getTypeInformation
TypeInformation<?> getTypeInformation()Returns theTypeInformation
of the property.- Returns:
-
getPersistentEntityTypeInformation
Iterable<? extends TypeInformation<?>> getPersistentEntityTypeInformation()Returns the detectedTypeInformations
if the property references aPersistentEntity
. Will return an emptyIterable
in case it refers to a simple type. Will return theCollection
's component types or theMap
's value type transparently.- Returns:
- never null.
- Since:
- 2.6
-
getGetter
Returns the getter method to access the property value if available. Might return null in case there is no getter method with a return type assignable to the actual property's type.- Returns:
- the getter method to access the property value if available, otherwise null.
-
getRequiredGetter
-
getSetter
Returns the setter method to set a property value. Might return null in case there is no setter available.- Returns:
- the setter method to set a property value if available, otherwise null.
-
getRequiredSetter
-
getWither
Returns the withMethod
to set a property value on a new object instance. Might return null in case there is no with available.With
methods
are property-bound instancemethods
that accept a single argument of the property type creating a new object instance.class Person { final String id; final String name; // … Person withName(String name) { return new Person(this.id, name); } }
- Returns:
- the with
Method
to set a property value on a new object instance if available, otherwise null. - Since:
- 2.1
-
getRequiredWither
-
getField
-
getRequiredField
-
getSpelExpression
- Returns:
- null if no expression defined.
-
getAssociation
- Returns:
- null if property is not part of an
Association
.
-
getRequiredAssociation
Get theAssociation
of this property.- Returns:
- never null.
- Throws:
IllegalStateException
- if not involved in anAssociation
.
-
isEntity
boolean isEntity()Returns whether the type of thePersistentProperty
is actually to be regarded asPersistentEntity
in turn.- Returns:
- true a
PersistentEntity
.
-
isIdProperty
boolean isIdProperty()Returns whether the property is a potential identifier property of the owningPersistentEntity
. This method is mainly used byPersistentEntity
implementation to discover id property candidates onPersistentEntity
creation you should rather callPersistentEntity.isIdProperty(PersistentProperty)
to determine whether the current property is the id property of thatPersistentEntity
under consideration.- Returns:
- true if the id property.
-
isVersionProperty
boolean isVersionProperty()Returns whether the current property is a potential version property of the owningPersistentEntity
. This method is mainly used byPersistentEntity
implementation to discover version property candidates onPersistentEntity
creation you should rather callPersistentEntity.isVersionProperty(PersistentProperty)
to determine whether the current property is the version property of thatPersistentEntity
under consideration.- Returns:
-
isCollectionLike
boolean isCollectionLike()Returns whether the property is aCollection
,Iterable
or an array.- Returns:
-
isMap
boolean isMap()Returns whether the property is aMap
.- Returns:
-
isArray
boolean isArray()Returns whether the property is an array.- Returns:
-
isTransient
boolean isTransient()Returns whether the property is transient.- Returns:
-
isWritable
boolean isWritable()Returns whether the current property is writable, i.e. if the value held for it shall be written to the data store.- Returns:
- Since:
- 1.9
-
isReadable
boolean isReadable()Returns whether the current property is readable throughPersistentPropertyAccessor
, i.e. if it is notisTransient()
, if the value can be set on the current instance or read to create a new instance as pergetWither()
or via Kotlin Copy methods.- Returns:
- Since:
- 3.2
-
isImmutable
boolean isImmutable()Returns whether the current property is immutable, i.e. if there is no setter or the backingField
isfinal
.- Returns:
- Since:
- 2.1
- See Also:
-
isAssociation
boolean isAssociation()Returns whether the property is anAssociation
.- Returns:
-
getComponentType
Returns the component type of the type if it is aCollection
. Will return the type of the key if the property is aMap
.- Returns:
- the component type, the map's key type or null if neither
Collection
norMap
.
-
getRawType
Class<?> getRawType()Returns the raw type as it's pulled from from the reflected property.- Returns:
- the raw type of the property.
-
getMapValueType
Returns the type of the values if the property is aMap
.- Returns:
- the map's value type or null if no
Map
-
getActualType
Class<?> getActualType()Returns the actual type of the property. This will be the original property type if no generics were used, the component type for collection-like types and arrays as well as the value type for map properties.- Returns:
-
findAnnotation
Looks up the annotation of the given type on thePersistentProperty
. Will inspect accessors and the potentially backing field and traverse accessor methods to potentially available super types.- Parameters:
annotationType
- the annotation to look up, must not be null.- Returns:
- the annotation of the given type. Can be null.
- See Also:
-
getRequiredAnnotation
default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType) throws IllegalStateException Looks up the annotation of the given type on thePersistentProperty
. Will inspect accessors and the potentially backing field and traverse accessor methods to potentially available super types.- Parameters:
annotationType
- the annotation to look up, must not be null.- Returns:
- the annotation of the given type.
- Throws:
IllegalStateException
- if the requiredannotationType
is not found.- Since:
- 2.0
-
findPropertyOrOwnerAnnotation
Looks up the annotation of the given type on the property and the owning type if no annotation can be found on it. Useful to lookup annotations that can be configured on the type but overridden on an individual property.- Parameters:
annotationType
- must not be null.- Returns:
- the annotation of the given type. Can be null.
-
isAnnotationPresent
Returns whether thePersistentProperty
has an annotation of the given type.- Parameters:
annotationType
- the annotation to lookup, must not be null.- Returns:
- whether the
PersistentProperty
has an annotation of the given type.
-
usePropertyAccess
boolean usePropertyAccess()Returns whether property access shall be used for reading the property value. This means it will use the getter instead of field access.- Returns:
-
hasActualTypeAnnotation
Returns whether the actual type of the property carries the given annotation.- Parameters:
annotationType
- must not be null.- Returns:
- Since:
- 2.1
- See Also:
-
getAssociationTargetType
Return the type the property refers to in case it's an association, i.e.isAssociation()
returns true. That means, that implementations must return a non-null value from this method in that case. We also recommend to return null for non-associations right away to establish symmetry between this method andisAssociation()
.- Returns:
- the type the property refers to in case it's an association, i.e.
isAssociation()
returns true. - Since:
- 2.1
-
getAssociationTargetTypeInformation
Return the type the property refers to in case it's an association, i.e.isAssociation()
returns true. That means, that implementations must return a non-null value from this method in that case. We also recommend to return null for non-associations right away to establish symmetry between this method andisAssociation()
.- Returns:
- the type the property refers to in case it's an association, i.e.
isAssociation()
returns true. - Since:
- 2.6
-
getAccessorForOwner
Returns aPersistentPropertyAccessor
for the current property's owning value.- Parameters:
owner
- must not be null.- Returns:
- will never be null.
- Since:
- 2.3
-