DATACMNS-1550 - Added RevisionType to RevisionMetadata.
This commit is contained in:
committed by
Oliver Drotbohm
parent
1e98932278
commit
f29756e5f8
@@ -40,10 +40,12 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem
|
||||
private final Object entity;
|
||||
private final Lazy<Optional<N>> revisionNumber;
|
||||
private final Lazy<Optional<Object>> revisionDate;
|
||||
private final RevisionType revisionType;
|
||||
|
||||
/**
|
||||
* Creates a new {@link AnnotationRevisionMetadata} inspecting the given entity for the given annotations. If no
|
||||
* annotations will be provided these values will not be looked up from the entity and return {@literal null}.
|
||||
* annotations will be provided these values will not be looked up from the entity and return {@literal null}. The
|
||||
* revisionType will be set to {@literal unknown}
|
||||
*
|
||||
* @param entity must not be {@literal null}.
|
||||
* @param revisionNumberAnnotation must not be {@literal null}.
|
||||
@@ -52,13 +54,31 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem
|
||||
public AnnotationRevisionMetadata(Object entity, Class<? extends Annotation> revisionNumberAnnotation,
|
||||
Class<? extends Annotation> revisionTimeStampAnnotation) {
|
||||
|
||||
this(entity, revisionNumberAnnotation, revisionTimeStampAnnotation, RevisionType.UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link AnnotationRevisionMetadata} inspecting the given entity for the given annotations. If no
|
||||
* annotations will be provided these values will not be looked up from the entity and return {@literal null}.
|
||||
*
|
||||
* @param entity must not be {@literal null}.
|
||||
* @param revisionNumberAnnotation must not be {@literal null}.
|
||||
* @param revisionTimeStampAnnotation must not be {@literal null}.
|
||||
* @param revisionType Must not be {@literal null}.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public AnnotationRevisionMetadata(Object entity, Class<? extends Annotation> revisionNumberAnnotation,
|
||||
Class<? extends Annotation> revisionTimeStampAnnotation, RevisionType revisionType) {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
Assert.notNull(revisionNumberAnnotation, "Revision number annotation must not be null!");
|
||||
Assert.notNull(revisionTimeStampAnnotation, "Revision time stamp annotation must not be null!");
|
||||
Assert.notNull(revisionType, "Revision Type must not be null!");
|
||||
|
||||
this.entity = entity;
|
||||
this.revisionNumber = detectAnnotation(entity, revisionNumberAnnotation);
|
||||
this.revisionDate = detectAnnotation(entity, revisionTimeStampAnnotation);
|
||||
this.revisionType = revisionType;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -77,6 +97,14 @@ public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implem
|
||||
return revisionDate.get().map(AnnotationRevisionMetadata::convertToInstant);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.history.RevisionMetadata#getRevisionDate()
|
||||
*/
|
||||
public RevisionType getRevisionType() {
|
||||
return revisionType;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.history.RevisionMetadata#getDelegate()
|
||||
|
||||
@@ -71,4 +71,32 @@ public interface RevisionMetadata<N extends Number & Comparable<N>> {
|
||||
* @return
|
||||
*/
|
||||
<T> T getDelegate();
|
||||
|
||||
/**
|
||||
* Returns the {@link RevisionType} of this change. If the {@link RevisionType} cannot be determined this method
|
||||
* returns {@link RevisionType#UNKNOWN}.
|
||||
*
|
||||
* @return Guaranteed to be not {@literal null}.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
default RevisionType getRevisionType() {
|
||||
return RevisionType.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of a {@link Revision}.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @since 2.2.0
|
||||
*/
|
||||
enum RevisionType {
|
||||
/** Fallback when the type of a revision cannot be determined. */
|
||||
UNKNOWN,
|
||||
/** Creation of an instance */
|
||||
INSERT,
|
||||
/** Change of an instance */
|
||||
UPDATE,
|
||||
/** Deletion of an instance */
|
||||
DELETE
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user