org.springframework.data.mapping.model

## Class AnnotationBasedPersistentProperty<P extends PersistentProperty<P>>

- java.lang.Object
- - org.springframework.data.mapping.model.AbstractPersistentProperty<P>
  - - org.springframework.data.mapping.model.AnnotationBasedPersistentProperty<P>

All Implemented Interfaces:
  PersistentProperty<P>

    public abstract class AnnotationBasedPersistentProperty<P extends PersistentProperty<P>>
    extends AbstractPersistentProperty<P>

Special `PersistentProperty` that takes annotations at a property into account.

Author:
  Oliver Gierke, Christoph Strobl, Mark Paluch

### Constructor Summary

Constructors
Constructor and Description
`AnnotationBasedPersistentProperty(Property property, PersistentEntity<?,P> owner, SimpleTypeHolder simpleTypeHolder)` Creates a new `AnnotationBasedPersistentProperty`.

### Method Summary

All Methods Instance Methods Concrete Methods
`<A extends Annotation> A` `findAnnotation(Class<A> annotationType)` Returns the annotation found for the current `AnnotationBasedPersistentProperty`.
`<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.
`Class<?>` `getAssociationTargetType()` Return the type the property refers to in case it's an association.
`String` `getSpelExpression()` Inspects a potentially available `Value` annotation at the property and returns the `String` value of it.
`boolean` `isAnnotationPresent(Class<? extends Annotation> annotationType)` Returns whether the property carries the an annotation of the given type.
`boolean` `isAssociation()` Considers the property an `Association` if it is annotated with `Reference`.
`boolean` `isIdProperty()` Returns whether the property is a potential identifier property of the owning `PersistentEntity`.
`boolean` `isTransient()` Considers plain transient fields, fields annotated with `Transient`, `Value` or `Autowired` as 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.
`String` `toString()`
`boolean` `usePropertyAccess()` Returns whether property access shall be used for reading the property value.

### Methods inherited from class org.springframework.data.mapping.model.AbstractPersistentProperty

`createAssociation, equals, getActualType, getAssociation, getComponentType, getField, getGetter, getMapValueType, getName, getOwner, getPersistentEntityTypes, getProperty, getRawType, getSetter, getType, getTypeInformation, getWither, hashCode, isArray, isCollectionLike, isEntity, isImmutable, isMap`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.data.mapping.PersistentProperty

`getAccessorForOwner, getRequiredAnnotation, getRequiredAssociation, getRequiredField, getRequiredGetter, getRequiredSetter, getRequiredWither, hasActualTypeAnnotation`

### Constructor Detail

#### AnnotationBasedPersistentProperty

    public AnnotationBasedPersistentProperty(Property property,
                                             PersistentEntity<?,P> owner,
                                             SimpleTypeHolder simpleTypeHolder)

Creates a new `AnnotationBasedPersistentProperty`.

Parameters:
  `property` - must not be null.
  `owner` - must not be null.

### Method Detail

#### getSpelExpression

    @Nullable
    public String getSpelExpression()

Inspects a potentially available `Value` annotation at the property and returns the `String` value of it.

Specified by:
  `getSpelExpression` in interface `PersistentProperty<P extends PersistentProperty<P>>`
Overrides:
  `getSpelExpression` in class `AbstractPersistentProperty<P extends PersistentProperty<P>>`
Returns:
  null if no expression defined.
See Also:
  `AbstractPersistentProperty.getSpelExpression()`

#### isTransient

    public boolean isTransient()

Considers plain transient fields, fields annotated with `Transient`, `Value` or `Autowired` as transient.

Specified by:
  `isTransient` in interface `PersistentProperty<P extends PersistentProperty<P>>`
Overrides:
  `isTransient` in class `AbstractPersistentProperty<P extends PersistentProperty<P>>`
Returns:
See Also:
  `PersistentProperty.isTransient()`

#### isIdProperty

    public boolean isIdProperty()

Description copied from interface: `PersistentProperty`
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

    public boolean isVersionProperty()

Description copied from interface: `PersistentProperty`
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:

#### isAssociation

    public boolean isAssociation()

Considers the property an `Association` if it is annotated with `Reference`.

Specified by:
  `isAssociation` in interface `PersistentProperty<P extends PersistentProperty<P>>`
Overrides:
  `isAssociation` in class `AbstractPersistentProperty<P extends PersistentProperty<P>>`
Returns:

#### isWritable

    public boolean isWritable()

Description copied from interface: `PersistentProperty`
Returns whether the current property is writable, i.e. if the value held for it shall be written to the data store.

Specified by:
  `isWritable` in interface `PersistentProperty<P extends PersistentProperty<P>>`
Overrides:
  `isWritable` in class `AbstractPersistentProperty<P extends PersistentProperty<P>>`
Returns:

#### findAnnotation

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

Returns the annotation found for the current `AnnotationBasedPersistentProperty`. Will prefer getters or setters annotations over ones found at the backing field as the former can be used to reconfigure the metadata in subclasses.

Parameters:
  `annotationType` - must not be null.
Returns:
  null if annotation type not found on property.
See Also:
  `AnnotationUtils.findAnnotation(Method, Class)`

#### findPropertyOrOwnerAnnotation

    @Nullable
    public <A extends Annotation> A findPropertyOrOwnerAnnotation(Class<A> annotationType)

Description copied from interface: `PersistentProperty`
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

    public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)

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

Parameters:
  `annotationType` - the annotation type to look up.
Returns:

#### usePropertyAccess

    public boolean usePropertyAccess()

Description copied from interface: `PersistentProperty`
Returns whether property access shall be used for reading the property value. This means it will use the getter instead of field access.

Specified by:
  `usePropertyAccess` in interface `PersistentProperty<P extends PersistentProperty<P>>`
Overrides:
  `usePropertyAccess` in class `AbstractPersistentProperty<P extends PersistentProperty<P>>`
Returns:

#### getAssociationTargetType

    @Nullable
    public Class<?> getAssociationTargetType()

Description copied from interface: `PersistentProperty`
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).

#### toString

    public String toString()

Overrides:
  `toString` in class `AbstractPersistentProperty<P extends PersistentProperty<P>>`