Skip to content

Commit 6440f9e

Browse files
committed
Polishing.
Revise aggregatePathCache generics. Reformat code. See #1657 Original pull request: #1661
1 parent eae39d4 commit 6440f9e

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class RelationalMappingContext
4444
extends AbstractMappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> {
4545

4646
private final NamingStrategy namingStrategy;
47-
private final Map<Object, AggregatePath> aggregatePathCache = new ConcurrentHashMap<>();
47+
private final Map<AggregatePathCacheKey, AggregatePath> aggregatePathCache = new ConcurrentHashMap<>();
4848

4949
private boolean forceQuote = true;
5050

@@ -115,10 +115,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
115115
@Override
116116
public RelationalPersistentEntity<?> getPersistentEntity(RelationalPersistentProperty persistentProperty) {
117117

118-
boolean embeddedDelegation = false;
119-
if (persistentProperty instanceof EmbeddedRelationalPersistentProperty) {
120-
embeddedDelegation = true;
121-
}
118+
boolean embeddedDelegation = persistentProperty instanceof EmbeddedRelationalPersistentProperty;
122119

123120
RelationalPersistentEntity<?> entity = super.getPersistentEntity(persistentProperty);
124121

@@ -203,6 +200,7 @@ public AggregatePath getAggregatePath(RelationalPersistentEntity<?> type) {
203200
AggregatePathCacheKey cacheKey = AggregatePathCacheKey.of(type);
204201

205202
AggregatePath aggregatePath = aggregatePathCache.get(cacheKey);
203+
206204
if (aggregatePath == null) {
207205

208206
aggregatePath = new DefaultAggregatePath(this, type);
@@ -212,14 +210,27 @@ public AggregatePath getAggregatePath(RelationalPersistentEntity<?> type) {
212210
return aggregatePath;
213211
}
214212

215-
private record AggregatePathCacheKey(RelationalPersistentEntity<?> root,@Nullable PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
213+
private record AggregatePathCacheKey(RelationalPersistentEntity<?> root,
214+
@Nullable PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
215+
216+
/**
217+
* Create a new AggregatePathCacheKey for a root entity.
218+
*
219+
* @param root the root entity.
220+
* @return
221+
*/
216222
static AggregatePathCacheKey of(RelationalPersistentEntity<?> root) {
217223
return new AggregatePathCacheKey(root, null);
218224
}
219-
static AggregatePathCacheKey of(PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
220225

221-
RelationalPersistentEntity<?> root = path.getBaseProperty().getOwner();
222-
return new AggregatePathCacheKey(root, path);
226+
/**
227+
* Create a new AggregatePathCacheKey for a property path.
228+
*
229+
* @param path
230+
* @return
231+
*/
232+
static AggregatePathCacheKey of(PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
233+
return new AggregatePathCacheKey(path.getBaseProperty().getOwner(), path);
223234
}
224235
}
225236
}

spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/RelationalMappingContextUnitTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import java.util.Arrays;
2120
import java.util.HashSet;
21+
import java.util.List;
2222
import java.util.UUID;
2323

2424
import org.junit.jupiter.api.BeforeEach;
@@ -32,10 +32,12 @@
3232
* Unit tests for {@link RelationalMappingContext}.
3333
*
3434
* @author Toshiaki Maki
35+
* @author Jens Schauder
3536
*/
3637
public class RelationalMappingContextUnitTests {
38+
3739
RelationalMappingContext context = new RelationalMappingContext();
38-
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<>(Arrays.asList(UUID.class)), true);
40+
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<>(List.of(UUID.class)), true);
3941

4042
@BeforeEach
4143
void setup() {

0 commit comments

Comments
 (0)