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 aPersistentPropertyAccessorfor 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 thePersistentEntityowning the currentPersistentProperty.Iterable<? extends TypeInformation<?>>Returns the detectedTypeInformationsif 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 theAssociationof this property.default Fielddefault Methoddefault Methoddefault MethodReturns the setter method to set a property value.Class<?>getType()The type of the propertyReturns theTypeInformationof the property.Returns the withMethodto set a property value on a new object instance.default booleanhasActualTypeAnnotation(Class<? extends Annotation> annotationType) Returns whether the actual type of the property carries the given annotation.booleanisAnnotationPresent(Class<? extends Annotation> annotationType) Returns whether thePersistentPropertyhas an annotation of the given type.booleanisArray()Returns whether the property is an array.booleanReturns whether the property is anAssociation.booleanReturns whether the property is aCollection,Iterableor an array.booleanisEntity()Returns whether the type of thePersistentPropertyis actually to be regarded asPersistentEntityin turn.booleanReturns whether the property is a potential identifier property of the owningPersistentEntity.booleanReturns whether the current property is immutable, i.e. if there is no setter or the backingFieldisfinal.booleanisMap()Returns whether the property is aMap.booleanReturns whether the property is transient.booleanReturns whether the current property is a potential version property of the owningPersistentEntity.booleanReturns whether the current property is writable, i.e. if the value held for it shall be written to the data store.booleanReturns whether property access shall be used for reading the property value.
-
Method Details
-
getOwner
PersistentEntity<?,P> getOwner()Returns thePersistentEntityowning 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 theTypeInformationof the property.- Returns:
-
getPersistentEntityTypeInformation
Iterable<? extends TypeInformation<?>> getPersistentEntityTypeInformation()Returns the detectedTypeInformationsif the property references aPersistentEntity. Will return an emptyIterablein 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 withMethodto set a property value on a new object instance. Might return null in case there is no with available.With
methodsare property-bound instancemethodsthat 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
Methodto 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 theAssociationof this property.- Returns:
- never null.
- Throws:
IllegalStateException- if not involved in anAssociation.
-
isEntity
boolean isEntity()Returns whether the type of thePersistentPropertyis actually to be regarded asPersistentEntityin 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 byPersistentEntityimplementation to discover id property candidates onPersistentEntitycreation you should rather callPersistentEntity.isIdProperty(PersistentProperty)to determine whether the current property is the id property of thatPersistentEntityunder 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 byPersistentEntityimplementation to discover version property candidates onPersistentEntitycreation you should rather callPersistentEntity.isVersionProperty(PersistentProperty)to determine whether the current property is the version property of thatPersistentEntityunder consideration.- Returns:
-
isCollectionLike
boolean isCollectionLike()Returns whether the property is aCollection,Iterableor 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
-
isImmutable
boolean isImmutable()Returns whether the current property is immutable, i.e. if there is no setter or the backingFieldisfinal.- 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
CollectionnorMap.
-
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 requiredannotationTypeis 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 thePersistentPropertyhas an annotation of the given type.- Parameters:
annotationType- the annotation to lookup, must not be null.- Returns:
- whether the
PersistentPropertyhas 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 aPersistentPropertyAccessorfor the current property's owning value.- Parameters:
owner- must not be null.- Returns:
- will never be null.
- Since:
- 2.3
-