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

### Method Summary

All Methods Instance Methods Abstract Methods Default Methods
`<A extends Annotation> A` `findAnnotation(Class<A> annotationType)` Looks up the annotation of the given type on the `PersistentProperty`.
`<A extends Annotation> A` `findPropertyOrOwnerAnnotation(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 a `PersistentPropertyAccessor` for the current property's owning value.
`Class<?>` `getActualType()` Returns the actual type of the property.
`Association<P>` `getAssociation()`
`Class<?>` `getAssociationTargetType()` Return the type the property refers to in case it's an association.
`Class<?>` `getComponentType()` Returns the component type of the type if it is a `Collection`.
`Field` `getField()`
`Method` `getGetter()` Returns the getter method to access the property value if available.
`Class<?>` `getMapValueType()` Returns the type of the values if the property is a `Map`.
`String` `getName()` The name of the property
`PersistentEntity<?,P>` `getOwner()` Returns the `PersistentEntity` owning the current `PersistentProperty`.
`Iterable<? extends TypeInformation<?>>` `getPersistentEntityTypes()` Returns the `TypeInformation` if the property references a `PersistentEntity`.
`Class<?>` `getRawType()` Returns the raw type as it's pulled from from the reflected property.
`default <A extends Annotation> A` `getRequiredAnnotation(Class<A> annotationType)` Looks up the annotation of the given type on the `PersistentProperty`.
`default Association<P>` `getRequiredAssociation()` Get the `Association` of this property.
`default Field` `getRequiredField()`
`default Method` `getRequiredGetter()`
`default Method` `getRequiredSetter()`
`default Method` `getRequiredWither()`
`Method` `getSetter()` Returns the setter method to set a property value.
`String` `getSpelExpression()`
`Class<?>` `getType()` The type of the property
`TypeInformation<?>` `getTypeInformation()` Returns the `TypeInformation` of the property.
`Method` `getWither()` Returns the with `Method` 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 the `PersistentProperty` has an annotation of the given type.
`boolean` `isArray()` Returns whether the property is an array.
`boolean` `isAssociation()` Returns whether the property is an `Association`.
`boolean` `isCollectionLike()` Returns whether the property is a `Collection`, `Iterable` or an array.
`boolean` `isEntity()` Returns whether the type of the `PersistentProperty` is actually to be regarded as `PersistentEntity` in turn.
`boolean` `isIdProperty()` Returns whether the property is a potential identifier property of the owning `PersistentEntity`.
`boolean` `isImmutable()` Returns whether the current property is immutable, i.e. if there is no setter or the backing `Field` is `final`.
`boolean` `isMap()` Returns whether the property is a `Map`.
`boolean` `isTransient()` Returns whether the property is transient.
`boolean` `isVersionProperty()` Returns whether the current property is a potential version property of the owning `PersistentEntity`.
`boolean` `isWritable()` Returns whether the current property is writable, i.e. if the value held for it shall be written to the data store.
`boolean` `usePropertyAccess()` Returns whether property access shall be used for reading the property value.

### Method Detail

#### getOwner

    PersistentEntity<?,P> getOwner()

Returns the `PersistentEntity` owning the current `PersistentProperty`.

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 the `TypeInformation` of the property.

Returns:

#### getPersistentEntityTypes

    Iterable<? extends TypeInformation<?>> getPersistentEntityTypes()

Returns the `TypeInformation` if the property references a `PersistentEntity`. Will return null in case it refers to a simple type. Will return `Collection`'s component type or the `Map`'s value type transparently.

Returns:

#### getGetter

    @Nullable
    Method 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

    default Method getRequiredGetter()

#### getSetter

    @Nullable
    Method 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

    default Method getRequiredSetter()

#### getWither

    @Nullable
    Method getWither()

Returns the with `Method` 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 instance `methods` 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

    default Method getRequiredWither()

#### getField

    @Nullable
    Field getField()

#### getRequiredField

    default Field getRequiredField()

#### getSpelExpression

    @Nullable
    String getSpelExpression()

Returns:
  null if no expression defined.

#### getAssociation

    @Nullable
    Association<P> getAssociation()

Returns:
  null if property is not part of an `Association`.

#### getRequiredAssociation

    default Association<P> getRequiredAssociation()

Get the `Association` of this property.

Returns:
  never null.
Throws:
  `IllegalStateException` - if not involved in an `Association`.

#### isEntity

    boolean isEntity()

Returns whether the type of the `PersistentProperty` is actually to be regarded as `PersistentEntity` in turn.

Returns:
  true a `PersistentEntity`.

#### isIdProperty

    boolean isIdProperty()

Returns whether the property is a potential identifier property of the owning `PersistentEntity`. This method is mainly used by `PersistentEntity` implementation to discover id property candidates on `PersistentEntity` creation you should rather call `PersistentEntity.isIdProperty(PersistentProperty)` to determine whether the current property is the id property of that `PersistentEntity` under consideration.

Returns:
  true if the id property.

#### isVersionProperty

    boolean isVersionProperty()

Returns whether the current property is a potential version property of the owning `PersistentEntity`. This method is mainly used by `PersistentEntity` implementation to discover version property candidates on `PersistentEntity` creation you should rather call `PersistentEntity.isVersionProperty(PersistentProperty)` to determine whether the current property is the version property of that `PersistentEntity` under consideration.

Returns:

#### isCollectionLike

    boolean isCollectionLike()

Returns whether the property is a `Collection`, `Iterable` or an array.

Returns:

#### isMap

    boolean isMap()

Returns whether the property is a `Map`.

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 backing `Field` is `final`.

Returns:
Since:
  2.1
See Also:
  `Modifier.isFinal(int)`

#### isAssociation

    boolean isAssociation()

Returns whether the property is an `Association`.

Returns:

#### getComponentType

    @Nullable
    Class<?> getComponentType()

Returns the component type of the type if it is a `Collection`. Will return the type of the key if the property is a `Map`.

Returns:
  the component type, the map's key type or null if neither `Collection` nor `Map`.

#### getRawType

    Class<?> getRawType()

Returns the raw type as it's pulled from from the reflected property.

Returns:
  the raw type of the property.

#### getMapValueType

    @Nullable
    Class<?> getMapValueType()

Returns the type of the values if the property is a `Map`.

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

    @Nullable
    <A extends Annotation> A findAnnotation(Class<A> annotationType)

Looks up the annotation of the given type on the `PersistentProperty`. 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:
  `AnnotationUtils.findAnnotation(Method, Class)`

#### getRequiredAnnotation

    default <A extends Annotation> A getRequiredAnnotation(Class<A> annotationType)
                                                    throws IllegalStateException

Looks up the annotation of the given type on the `PersistentProperty`. 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 required `annotationType` is not found.
Since:
  2.0

#### findPropertyOrOwnerAnnotation

    @Nullable
    <A extends Annotation> A findPropertyOrOwnerAnnotation(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. 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

    boolean isAnnotationPresent(Class<? extends Annotation> annotationType)

Returns whether the `PersistentProperty` 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

    default boolean hasActualTypeAnnotation(Class<? extends Annotation> annotationType)

Returns whether the actual type of the property carries the given annotation.

Parameters:
  `annotationType` - must not be null.
Returns:
Since:
  2.1
See Also:
  `getActualType()`

#### getAssociationTargetType

    @Nullable
    Class<?> getAssociationTargetType()

Return the type the property refers to in case it's an association.

Returns:
  the type the property refers to in case it's an association or null in case it's not an association, the target entity type is not explicitly defined (either explicitly or through the property type itself).
Since:
  2.1

#### getAccessorForOwner

    default <T> PersistentPropertyAccessor<T> getAccessorForOwner(T owner)

Returns a `PersistentPropertyAccessor` for the current property's owning value.

Parameters:
  `owner` - must not be null.
Returns:
  will never be null.
Since:
  2.3