DATACMNS-1333 - Unified is-new-detection in PersistentEntity.isNew(…).
PersistentEntity now exposes an ….isNew(…) method that exposes the same detection algorithm previously exposed through MappingContextIsNewStrategyFactory (Persistable in favor of the version property in favor of an identifier lookup). MappingContextIsNewStrategyFactory has been refactored to return an ad-hoc strategy to delegate to the newly introduced method. The core message to implementing modules is that they should now prefer PersistentEntityInformation within their RepositoryFactorySupport implementation and move all customizations made in the store-specific EntityInformation implementation in PersistentEntity.
This commit is contained in:
@@ -20,14 +20,12 @@ import java.util.Optional;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContextIsNewStrategyFactory;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.support.IsNewStrategy;
|
||||
import org.springframework.data.support.IsNewStrategyFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link AuditingHandler} extension that uses an {@link IsNewStrategyFactory} to expose a generic
|
||||
* {@link AuditingHandler} extension that uses {@link PersistentEntity#isNew(Object)} to expose a generic
|
||||
* {@link #markAudited(Optional)} method that will route calls to {@link #markCreated(Optional)} or
|
||||
* {@link #markModified(Optional)} based on the {@link IsNewStrategy} determined from the factory.
|
||||
*
|
||||
@@ -37,7 +35,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class IsNewAwareAuditingHandler extends AuditingHandler {
|
||||
|
||||
private final IsNewStrategyFactory isNewStrategyFactory;
|
||||
private final PersistentEntities entities;
|
||||
|
||||
/**
|
||||
* Creates a new {@link IsNewAwareAuditingHandler} for the given {@link MappingContext}.
|
||||
@@ -62,13 +60,12 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
|
||||
|
||||
super(entities);
|
||||
|
||||
this.isNewStrategyFactory = new MappingContextIsNewStrategyFactory(entities);
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the given object created or modified based on the {@link IsNewStrategy} returned by the
|
||||
* {@link IsNewStrategyFactory} configured. Will rout the calls to {@link #markCreated(Optional)} and
|
||||
* {@link #markModified(Optional)} accordingly.
|
||||
* Marks the given object created or modified based on {@link PersistentEntity#isNew(Object)}. Will route the calls to
|
||||
* {@link #markCreated(Optional)} and {@link #markModified(Optional)} accordingly.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
@@ -80,9 +77,10 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
IsNewStrategy strategy = isNewStrategyFactory.getIsNewStrategy(object.getClass());
|
||||
PersistentEntity<?, ? extends PersistentProperty<?>> entity = entities
|
||||
.getRequiredPersistentEntity(object.getClass());
|
||||
|
||||
if (strategy.isNew(object)) {
|
||||
if (entity.isNew(object)) {
|
||||
markCreated(object);
|
||||
} else {
|
||||
markModified(object);
|
||||
|
||||
Reference in New Issue
Block a user