Skip to content

Commit fb07ad9

Browse files
Add factory method to Reactive-/IsNewAwareAuditingHandler.
By providing a factory method that accepts the MappingContext we can avoid the creation of additional support beans during the configuration phase for store modules implementing auditing. See: #2593
1 parent 9c3696d commit fb07ad9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/main/java/org/springframework/data/auditing/IsNewAwareAuditingHandler.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
3636
private final PersistentEntities entities;
3737

3838
/**
39-
* Creates a new {@link IsNewAwareAuditingHandler} for the given {@link MappingContext}.
39+
* Creates a new {@link IsNewAwareAuditingHandler} for the given {@link PersistentEntities}.
4040
*
4141
* @param entities must not be {@literal null}.
4242
* @since 1.10
@@ -48,6 +48,16 @@ public IsNewAwareAuditingHandler(PersistentEntities entities) {
4848
this.entities = entities;
4949
}
5050

51+
/**
52+
* Factory method that creates a new {@link IsNewAwareAuditingHandler} for the given {@link MappingContext}.
53+
*
54+
* @param mappingContext must not be {@literal null}.
55+
* @since 3.0
56+
*/
57+
public static IsNewAwareAuditingHandler from(MappingContext<?,?> mappingContext) {
58+
return new IsNewAwareAuditingHandler(PersistentEntities.of(mappingContext));
59+
}
60+
5161
/**
5262
* Marks the given object created or modified based on {@link PersistentEntity#isNew(Object)}. Will route the calls to
5363
* {@link #markCreated(Object)} and {@link #markModified(Object)} accordingly.

src/main/java/org/springframework/data/auditing/ReactiveIsNewAwareAuditingHandler.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ReactiveIsNewAwareAuditingHandler extends ReactiveAuditingHandler {
3737
private final PersistentEntities entities;
3838

3939
/**
40-
* Creates a new {@link ReactiveIsNewAwareAuditingHandler} for the given {@link MappingContext}.
40+
* Creates a new {@link ReactiveIsNewAwareAuditingHandler} for the given {@link PersistentEntities}.
4141
*
4242
* @param entities must not be {@literal null}.
4343
*/
@@ -48,6 +48,16 @@ public ReactiveIsNewAwareAuditingHandler(PersistentEntities entities) {
4848
this.entities = entities;
4949
}
5050

51+
/**
52+
* Factory method that creates a new {@link ReactiveIsNewAwareAuditingHandler} for the given {@link MappingContext}.
53+
*
54+
* @param mappingContext must not be {@literal null}.
55+
* @since 3.0
56+
*/
57+
public static ReactiveIsNewAwareAuditingHandler from(MappingContext<?,?> mappingContext) {
58+
return new ReactiveIsNewAwareAuditingHandler(PersistentEntities.of(mappingContext));
59+
}
60+
5161
/**
5262
* Marks the given object created or modified based on {@link PersistentEntity#isNew(Object)}. Will route the calls to
5363
* {@link #markCreated(Object)} and {@link #markModified(Object)} accordingly.

0 commit comments

Comments
 (0)