|
18 | 18 | import java.util.ArrayList;
|
19 | 19 | import java.util.Collections;
|
20 | 20 | import java.util.List;
|
| 21 | +import java.util.function.Consumer; |
21 | 22 |
|
22 | 23 | import org.springframework.data.convert.EntityWriter;
|
23 |
| -import org.springframework.data.mapping.PersistentProperty; |
| 24 | +import org.springframework.data.mapping.PersistentPropertyPath; |
24 | 25 | import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
|
25 | 26 | import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
26 |
| -import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; |
27 | 27 | import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
|
28 | 28 | import org.springframework.lang.Nullable;
|
29 | 29 | import org.springframework.util.Assert;
|
@@ -74,10 +74,7 @@ private List<DbAction<?>> deleteAll(Class<?> entityType) {
|
74 | 74 |
|
75 | 75 | List<DbAction<?>> deleteReferencedActions = new ArrayList<>();
|
76 | 76 |
|
77 |
| - context.findPersistentPropertyPaths(entityType, PersistentProperty::isEntity) // |
78 |
| - .filter(p -> !p.getRequiredLeafProperty().isEmbedded() // |
79 |
| - && PersistentPropertyPathExtension.isWritable(p)) // |
80 |
| - .forEach(p -> deleteReferencedActions.add(new DbAction.DeleteAll<>(p))); |
| 77 | + forAllTableRepresentingPaths(entityType, p -> deleteReferencedActions.add(new DbAction.DeleteAll<>(p))); |
81 | 78 |
|
82 | 79 | Collections.reverse(deleteReferencedActions);
|
83 | 80 |
|
@@ -118,14 +115,18 @@ private List<DbAction<?>> deleteReferencedEntities(Object id, AggregateChange<?>
|
118 | 115 |
|
119 | 116 | List<DbAction<?>> actions = new ArrayList<>();
|
120 | 117 |
|
121 |
| - context.findPersistentPropertyPaths(aggregateChange.getEntityType(), p -> p.isEntity()) // |
122 |
| - .filter(p -> !p.getRequiredLeafProperty().isEmbedded() // |
123 |
| - && PersistentPropertyPathExtension.isWritable(p)) // |
124 |
| - .forEach(p -> actions.add(new DbAction.Delete<>(id, p))); |
| 118 | + forAllTableRepresentingPaths(aggregateChange.getEntityType(), p -> actions.add(new DbAction.Delete<>(id, p))); |
125 | 119 |
|
126 | 120 | Collections.reverse(actions);
|
127 | 121 |
|
128 | 122 | return actions;
|
129 | 123 | }
|
130 | 124 |
|
| 125 | + private void forAllTableRepresentingPaths(Class<?> entityType, |
| 126 | + Consumer<PersistentPropertyPath<RelationalPersistentProperty>> pathConsumer) { |
| 127 | + |
| 128 | + context.findPersistentPropertyPaths(entityType, property -> property.isEntity() && !property.isEmbedded()) // |
| 129 | + .filter(PersistentPropertyPathExtension::isWritable) // |
| 130 | + .forEach(pathConsumer); |
| 131 | + } |
131 | 132 | }
|
0 commit comments