Polishing.

Revise aggregatePathCache generics. Reformat code.

See #1657
Original pull request: #1661
This commit is contained in:
Mark Paluch
2023-11-14 11:45:27 +01:00
parent eae39d4438
commit 6440f9e6dc
2 changed files with 24 additions and 11 deletions

View File

@@ -44,7 +44,7 @@ public class RelationalMappingContext
extends AbstractMappingContext<RelationalPersistentEntity<?>, RelationalPersistentProperty> {
private final NamingStrategy namingStrategy;
private final Map<Object, AggregatePath> aggregatePathCache = new ConcurrentHashMap<>();
private final Map<AggregatePathCacheKey, AggregatePath> aggregatePathCache = new ConcurrentHashMap<>();
private boolean forceQuote = true;
@@ -115,10 +115,7 @@ public class RelationalMappingContext
@Override
public RelationalPersistentEntity<?> getPersistentEntity(RelationalPersistentProperty persistentProperty) {
boolean embeddedDelegation = false;
if (persistentProperty instanceof EmbeddedRelationalPersistentProperty) {
embeddedDelegation = true;
}
boolean embeddedDelegation = persistentProperty instanceof EmbeddedRelationalPersistentProperty;
RelationalPersistentEntity<?> entity = super.getPersistentEntity(persistentProperty);
@@ -203,6 +200,7 @@ public class RelationalMappingContext
AggregatePathCacheKey cacheKey = AggregatePathCacheKey.of(type);
AggregatePath aggregatePath = aggregatePathCache.get(cacheKey);
if (aggregatePath == null) {
aggregatePath = new DefaultAggregatePath(this, type);
@@ -212,14 +210,27 @@ public class RelationalMappingContext
return aggregatePath;
}
private record AggregatePathCacheKey(RelationalPersistentEntity<?> root,@Nullable PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
private record AggregatePathCacheKey(RelationalPersistentEntity<?> root,
@Nullable PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
/**
* Create a new AggregatePathCacheKey for a root entity.
*
* @param root the root entity.
* @return
*/
static AggregatePathCacheKey of(RelationalPersistentEntity<?> root) {
return new AggregatePathCacheKey(root, null);
}
static AggregatePathCacheKey of(PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
RelationalPersistentEntity<?> root = path.getBaseProperty().getOwner();
return new AggregatePathCacheKey(root, path);
/**
* Create a new AggregatePathCacheKey for a property path.
*
* @param path
* @return
*/
static AggregatePathCacheKey of(PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
return new AggregatePathCacheKey(path.getBaseProperty().getOwner(), path);
}
}
}

View File

@@ -17,8 +17,8 @@ package org.springframework.data.relational.core.mapping;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
@@ -32,10 +32,12 @@ import org.springframework.data.relational.core.sql.SqlIdentifier;
* Unit tests for {@link RelationalMappingContext}.
*
* @author Toshiaki Maki
* @author Jens Schauder
*/
public class RelationalMappingContextUnitTests {
RelationalMappingContext context = new RelationalMappingContext();
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<>(Arrays.asList(UUID.class)), true);
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<>(List.of(UUID.class)), true);
@BeforeEach
void setup() {