Skip to content

Commit 0ed7d98

Browse files
committed
Refactor and rename LinkableEntity* classes to AggregateEntity*
1 parent 79f71ee commit 0ed7d98

File tree

9 files changed

+73
-70
lines changed

9 files changed

+73
-70
lines changed

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AggregateCommand.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ public AggregateCommand(
5757

5858
@Override
5959
public RESULT execute() {
60-
Set<EntityCacheKey> rootEntityKeys = new LinkedHashSet<>();
61-
Map<EntityCacheKey, Object> entityCache = new HashMap<>();
62-
SelectCommand<List<LinkableEntityPool>> command =
60+
Set<AggregateEntityCacheKey> rootEntityKeys = new LinkedHashSet<>();
61+
Map<AggregateEntityCacheKey, Object> entityCache = new HashMap<>();
62+
SelectCommand<List<AggregateEntityPool>> command =
6363
new SelectCommand<>(
6464
query,
65-
new LinkableEntityPoolIterationHandler(
65+
new AggregateEntityPoolIterationHandler(
6666
entityType,
6767
aggregateStrategyType,
6868
query.isResultMappingEnsured(),
6969
rootEntityKeys,
7070
entityCache));
71-
List<LinkableEntityPool> entityPools = command.execute();
71+
List<AggregateEntityPool> entityPools = command.execute();
7272

73-
Combinations<LinkableEntityKey> combinations = new Combinations<>();
74-
for (LinkableEntityPool entityPool : entityPools) {
75-
Map<PathKey, LinkableEntityPoolEntry> associationCandidate = new HashMap<>();
76-
for (LinkableEntityPoolEntry entry : entityPool) {
73+
Combinations<AggregateEntityKey> combinations = new Combinations<>();
74+
for (AggregateEntityPool entityPool : entityPools) {
75+
Map<AggregatePathKey, AggregateEntityPoolEntry> associationCandidate = new HashMap<>();
76+
for (AggregateEntityPoolEntry entry : entityPool) {
7777
associationCandidate.put(entry.entityKey().pathKey(), entry);
7878
}
7979
associate(entityCache, combinations, associationCandidate);
@@ -95,19 +95,19 @@ public RESULT execute() {
9595
* of linkage rules and updates the cache with newly associated entities.
9696
*/
9797
private void associate(
98-
Map<EntityCacheKey, Object> entityCache,
99-
Combinations<LinkableEntityKey> combinations,
100-
Map<PathKey, LinkableEntityPoolEntry> associationCandidate) {
98+
Map<AggregateEntityCacheKey, Object> entityCache,
99+
Combinations<AggregateEntityKey> combinations,
100+
Map<AggregatePathKey, AggregateEntityPoolEntry> associationCandidate) {
101101

102102
for (AssociationLinkerType<?, ?> linkerType :
103103
aggregateStrategyType.getAssociationLinkerTypes()) {
104-
LinkableEntityPoolEntry source = associationCandidate.get(linkerType.getSourcePathKey());
105-
LinkableEntityPoolEntry target = associationCandidate.get(linkerType.getTargetPathKey());
104+
AggregateEntityPoolEntry source = associationCandidate.get(linkerType.getSourcePathKey());
105+
AggregateEntityPoolEntry target = associationCandidate.get(linkerType.getTargetPathKey());
106106
if (source == null || target == null) {
107107
continue;
108108
}
109109

110-
Pair<LinkableEntityKey, LinkableEntityKey> keyPair =
110+
Pair<AggregateEntityKey, AggregateEntityKey> keyPair =
111111
new Pair<>(source.entityKey(), target.entityKey());
112112
if (combinations.contains(keyPair)) {
113113
continue;
@@ -119,10 +119,10 @@ private void associate(
119119
(BiFunction<Object, Object, Object>) linkerType.getLinker();
120120
Object entity = linker.apply(source.entity(), target.entity());
121121
if (entity != null) {
122-
EntityCacheKey cacheKey = EntityCacheKey.of(source.entityKey());
122+
AggregateEntityCacheKey cacheKey = AggregateEntityCacheKey.of(source.entityKey());
123123
entityCache.replace(cacheKey, entity);
124124
associationCandidate.replace(
125-
source.pathKey(), new LinkableEntityPoolEntry(source.entityKey(), entity));
125+
source.pathKey(), new AggregateEntityPoolEntry(source.entityKey(), entity));
126126
}
127127
}
128128
}

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/EntityCacheKey.java renamed to doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AggregateEntityCacheKey.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.util.List;
1919
import org.seasar.doma.jdbc.entity.EntityType;
2020

21-
public record EntityCacheKey(EntityType<?> entityType, List<?> items) {
22-
public static EntityCacheKey of(LinkableEntityKey entityKey) {
23-
return new EntityCacheKey(entityKey.entityType(), entityKey.items());
21+
public record AggregateEntityCacheKey(EntityType<?> entityType, List<?> items) {
22+
public static AggregateEntityCacheKey of(AggregateEntityKey entityKey) {
23+
return new AggregateEntityCacheKey(entityKey.entityType(), entityKey.items());
2424
}
2525
}

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/LinkableEntityKey.java renamed to doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AggregateEntityKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.util.Objects;
2020
import org.seasar.doma.jdbc.entity.EntityType;
2121

22-
public record LinkableEntityKey(PathKey pathKey, List<?> items) {
23-
public LinkableEntityKey {
22+
public record AggregateEntityKey(AggregatePathKey pathKey, List<?> items) {
23+
public AggregateEntityKey {
2424
Objects.requireNonNull(pathKey);
2525
Objects.requireNonNull(items);
2626
}

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/LinkableEntityPool.java renamed to doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AggregateEntityPool.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
import java.util.List;
2121
import java.util.Objects;
2222

23-
public class LinkableEntityPool implements Iterable<LinkableEntityPoolEntry> {
24-
private final List<LinkableEntityPoolEntry> entities = new ArrayList<>();
23+
public class AggregateEntityPool implements Iterable<AggregateEntityPoolEntry> {
24+
private final List<AggregateEntityPoolEntry> entities = new ArrayList<>();
2525

26-
public void add(LinkableEntityPoolEntry entry) {
26+
public void add(AggregateEntityPoolEntry entry) {
2727
Objects.requireNonNull(entry);
2828
entities.add(entry);
2929
}
3030

3131
@SuppressWarnings("NullableProblems")
3232
@Override
33-
public Iterator<LinkableEntityPoolEntry> iterator() {
33+
public Iterator<AggregateEntityPoolEntry> iterator() {
3434
return entities.iterator();
3535
}
3636
}

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/LinkableEntityPoolEntry.java renamed to doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AggregateEntityPoolEntry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
import java.util.Objects;
1919

20-
public record LinkableEntityPoolEntry(LinkableEntityKey entityKey, Object entity) {
21-
public LinkableEntityPoolEntry {
20+
public record AggregateEntityPoolEntry(AggregateEntityKey entityKey, Object entity) {
21+
public AggregateEntityPoolEntry {
2222
Objects.requireNonNull(entityKey);
2323
Objects.requireNonNull(entity);
2424
}
2525

26-
public PathKey pathKey() {
26+
public AggregatePathKey pathKey() {
2727
return entityKey.pathKey();
2828
}
2929
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@
2626
import org.seasar.doma.jdbc.query.SelectQuery;
2727

2828
/**
29-
* Handles the iteration of {@link LinkableEntityPool} results from a query execution and manages
29+
* Handles the iteration of {@link AggregateEntityPool} results from a query execution and manages
3030
* the creation and configuration of object providers used to process the results.
3131
*/
32-
public class LinkableEntityPoolIterationHandler
33-
extends AbstractIterationHandler<LinkableEntityPool, List<LinkableEntityPool>> {
32+
public class AggregateEntityPoolIterationHandler
33+
extends AbstractIterationHandler<AggregateEntityPool, List<AggregateEntityPool>> {
3434

3535
private final EntityType<?> entityType;
3636
private final AggregateStrategyType aggregateStrategyType;
3737
private final boolean resultMappingEnsured;
38-
private final Set<EntityCacheKey> rootEntityKeys;
39-
private final Map<EntityCacheKey, Object> entityCache;
38+
private final Set<AggregateEntityCacheKey> rootEntityKeys;
39+
private final Map<AggregateEntityCacheKey, Object> entityCache;
4040

41-
public LinkableEntityPoolIterationHandler(
41+
public AggregateEntityPoolIterationHandler(
4242
EntityType<?> entityType,
4343
AggregateStrategyType aggregateStrategyType,
4444
boolean resultMappingEnsured,
45-
Set<EntityCacheKey> rootEntityKeys,
46-
Map<EntityCacheKey, Object> entityCache) {
45+
Set<AggregateEntityCacheKey> rootEntityKeys,
46+
Map<AggregateEntityCacheKey, Object> entityCache) {
4747
super(new ResultListCallback<>());
4848
this.entityType = Objects.requireNonNull(entityType);
4949
this.aggregateStrategyType = Objects.requireNonNull(aggregateStrategyType);
@@ -53,8 +53,8 @@ public LinkableEntityPoolIterationHandler(
5353
}
5454

5555
@Override
56-
protected ObjectProvider<LinkableEntityPool> createObjectProvider(SelectQuery query) {
57-
return new LinkableEntityPoolProvider(
56+
protected ObjectProvider<AggregateEntityPool> createObjectProvider(SelectQuery query) {
57+
return new AggregateEntityPoolProvider(
5858
entityType,
5959
aggregateStrategyType,
6060
query,

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/LinkableEntityPoolProvider.java renamed to doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AggregateEntityPoolProvider.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@
3737
import org.seasar.doma.jdbc.entity.Property;
3838
import org.seasar.doma.jdbc.query.Query;
3939

40-
public class LinkableEntityPoolProvider extends AbstractObjectProvider<LinkableEntityPool> {
40+
public class AggregateEntityPoolProvider extends AbstractObjectProvider<AggregateEntityPool> {
4141

4242
private final EntityType<?> entityType;
4343
private final Query query;
44-
private final Set<EntityCacheKey> rootEntityKeys;
45-
private final Map<EntityCacheKey, Object> entityCache;
44+
private final Set<AggregateEntityCacheKey> rootEntityKeys;
45+
private final Map<AggregateEntityCacheKey, Object> entityCache;
4646
private Map<Integer, MappingSupport.PropType> indexMap;
4747
private final MappingSupport mappingSupport;
4848
private final FetchSupport fetchSupport;
4949
private final AggregateStrategyType aggregateStrategyType;
5050
private final Map<String, AssociationLinkerType<?, ?>> associationLinkerTypeMap;
5151

52-
public LinkableEntityPoolProvider(
52+
public AggregateEntityPoolProvider(
5353
EntityType<?> entityType,
5454
AggregateStrategyType aggregateStrategyType,
5555
Query query,
5656
boolean resultMappingEnsured,
57-
Set<EntityCacheKey> rootEntityKeys,
58-
Map<EntityCacheKey, Object> entityCache) {
57+
Set<AggregateEntityCacheKey> rootEntityKeys,
58+
Map<AggregateEntityCacheKey, Object> entityCache) {
5959
assertNotNull(entityType, aggregateStrategyType, query, rootEntityKeys, entityCache);
6060
this.entityType = entityType;
6161
this.query = query;
@@ -76,9 +76,9 @@ public LinkableEntityPoolProvider(
7676
}
7777

7878
@Override
79-
public LinkableEntityPool get(ResultSet resultSet) throws SQLException {
79+
public AggregateEntityPool get(ResultSet resultSet) throws SQLException {
8080
List<MappingSupport.Prop> props = createProps(resultSet);
81-
Map<PathKey, List<MappingSupport.Prop>> propGroup = groupPropsByPathKey(props);
81+
Map<AggregatePathKey, List<MappingSupport.Prop>> propGroup = groupPropsByPathKey(props);
8282
return createEntityPool(propGroup);
8383
}
8484

@@ -143,29 +143,31 @@ private void collectColumnNames(
143143
}
144144
}
145145

146-
private Map<PathKey, List<MappingSupport.Prop>> groupPropsByPathKey(
146+
private Map<AggregatePathKey, List<MappingSupport.Prop>> groupPropsByPathKey(
147147
List<MappingSupport.Prop> props) {
148148
return props.stream()
149-
.collect(Collectors.groupingBy(it -> new PathKey(it.propertyPath(), it.entityType())));
149+
.collect(
150+
Collectors.groupingBy(it -> new AggregatePathKey(it.propertyPath(), it.entityType())));
150151
}
151152

152153
/**
153-
* Creates and populates a {@link LinkableEntityPool} based on the provided group of properties
154-
* organized by their {@link PathKey}.
154+
* Creates and populates a {@link AggregateEntityPool} based on the provided group of properties
155+
* organized by their {@link AggregatePathKey}.
155156
*/
156-
private LinkableEntityPool createEntityPool(Map<PathKey, List<MappingSupport.Prop>> propGroup) {
157-
LinkableEntityPool entityPool = new LinkableEntityPool();
157+
private AggregateEntityPool createEntityPool(
158+
Map<AggregatePathKey, List<MappingSupport.Prop>> propGroup) {
159+
AggregateEntityPool entityPool = new AggregateEntityPool();
158160

159-
for (Map.Entry<PathKey, List<MappingSupport.Prop>> entry : propGroup.entrySet()) {
160-
PathKey pathKey = entry.getKey();
161+
for (Map.Entry<AggregatePathKey, List<MappingSupport.Prop>> entry : propGroup.entrySet()) {
162+
AggregatePathKey pathKey = entry.getKey();
161163
List<MappingSupport.Prop> props = entry.getValue();
162164
if (props.stream().allMatch(p -> p.rawValue() == null)) {
163165
continue;
164166
}
165-
LinkableEntityKey entityKey = createLinkableEntityKey(pathKey, props);
166-
EntityCacheKey cacheKey = EntityCacheKey.of(entityKey);
167+
AggregateEntityKey entityKey = createEntityKey(pathKey, props);
168+
AggregateEntityCacheKey cacheKey = AggregateEntityCacheKey.of(entityKey);
167169
Object entity = entityCache.computeIfAbsent(cacheKey, k -> createEntity(k, props));
168-
entityPool.add(new LinkableEntityPoolEntry(entityKey, entity));
170+
entityPool.add(new AggregateEntityPoolEntry(entityKey, entity));
169171
if (pathKey.isRoot()) {
170172
rootEntityKeys.add(cacheKey);
171173
}
@@ -174,20 +176,21 @@ private LinkableEntityPool createEntityPool(Map<PathKey, List<MappingSupport.Pro
174176
return entityPool;
175177
}
176178

177-
private static LinkableEntityKey createLinkableEntityKey(
178-
PathKey pathKey, List<MappingSupport.Prop> props) {
179-
LinkableEntityKey entityKey;
179+
private static AggregateEntityKey createEntityKey(
180+
AggregatePathKey pathKey, List<MappingSupport.Prop> props) {
181+
AggregateEntityKey entityKey;
180182
if (pathKey.entityType().getIdPropertyTypes().isEmpty()) {
181-
entityKey = new LinkableEntityKey(pathKey, Collections.singletonList(new Object()));
183+
entityKey = new AggregateEntityKey(pathKey, Collections.singletonList(new Object()));
182184
} else {
183185
List<?> items =
184186
props.stream().filter(MappingSupport.Prop::isId).map(it -> it.wrapper().get()).toList();
185-
entityKey = new LinkableEntityKey(pathKey, items);
187+
entityKey = new AggregateEntityKey(pathKey, items);
186188
}
187189
return entityKey;
188190
}
189191

190-
private static Object createEntity(EntityCacheKey cacheKey, List<MappingSupport.Prop> props) {
192+
private static Object createEntity(
193+
AggregateEntityCacheKey cacheKey, List<MappingSupport.Prop> props) {
191194
@SuppressWarnings("unchecked")
192195
EntityType<Object> entityType = (EntityType<Object>) cacheKey.entityType();
193196
Map<String, Property<Object, ?>> states =

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/PathKey.java renamed to doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AggregatePathKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.util.Objects;
1919
import org.seasar.doma.jdbc.entity.EntityType;
2020

21-
public record PathKey(String propertyPath, EntityType<?> entityType) {
22-
public PathKey {
21+
public record AggregatePathKey(String propertyPath, EntityType<?> entityType) {
22+
public AggregatePathKey {
2323
Objects.requireNonNull(propertyPath);
2424
Objects.requireNonNull(entityType);
2525
}

doma-core/src/main/java/org/seasar/doma/jdbc/aggregate/AssociationLinkerType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public BiFunction<S, T, S> getLinker() {
8080
return linker;
8181
}
8282

83-
public PathKey getSourcePathKey() {
84-
return new PathKey(ancestorPath, source);
83+
public AggregatePathKey getSourcePathKey() {
84+
return new AggregatePathKey(ancestorPath, source);
8585
}
8686

87-
public PathKey getTargetPathKey() {
88-
return new PathKey(propertyPath, target);
87+
public AggregatePathKey getTargetPathKey() {
88+
return new AggregatePathKey(propertyPath, target);
8989
}
9090

9191
public static <S, T> AssociationLinkerType<S, T> of(

0 commit comments

Comments
 (0)