Skip to content

Commit 31a0825

Browse files
committed
DATACMNS-1354 - BasicPersistentEntity now exposes means to override the fallback IsNewStrategy.
This is useful in case a particular store implementation needs to customize the default is new detection.
1 parent 3c2522d commit 31a0825

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ public BasicPersistentEntity(TypeInformation<T> information, @Nullable Comparato
131131
this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType()));
132132
this.isNewStrategy = Lazy.of(() -> Persistable.class.isAssignableFrom(information.getType()) //
133133
? PersistableIsNewStrategy.INSTANCE
134-
: PersistentEntityIsNewStrategy.of(this));
134+
: getFallbackIsNewStrategy());
135+
135136
this.isImmutable = Lazy.of(() -> isAnnotationPresent(Immutable.class));
136137
}
137138

@@ -520,6 +521,18 @@ protected EvaluationContext getEvaluationContext(Object rootObject) {
520521
return evaluationContextProvider.getEvaluationContext(rootObject);
521522
}
522523

524+
/**
525+
* Returns the default {@link IsNewStrategy} to be used. Will be a {@link PersistentEntityIsNewStrategy} by default.
526+
* Note, that this strategy only gets used if the entity doesn't implement {@link Persistable} as this indicates the
527+
* user wants to be in control over whether an entity is new or not.
528+
*
529+
* @return
530+
* @since 2.1
531+
*/
532+
protected IsNewStrategy getFallbackIsNewStrategy() {
533+
return PersistentEntityIsNewStrategy.of(this);
534+
}
535+
523536
/**
524537
* Verifies the given bean type to no be {@literal null} and of the type of the current {@link PersistentEntity}.
525538
*

0 commit comments

Comments
 (0)