Skip to content

Commit 4b7eb5c

Browse files
committed
Simplify code and improve naming consistency
1 parent 923c3d0 commit 4b7eb5c

File tree

3 files changed

+12
-69
lines changed

3 files changed

+12
-69
lines changed

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232
/**
3333
* The AggregateCommand class represents a command designed to execute an aggregate operation on a
34-
* stream of entities and return a result. This class implements the {@code Command} interface,
35-
* allowing for execution via a {@code execute} method and providing access to the underlying query.
34+
* stream of entities and return a result.
3635
*
3736
* @param <RESULT> the result type of the aggregation
3837
* @param <ENTITY> the root entity type used within the aggregation
@@ -75,25 +74,15 @@ public RESULT execute() {
7574
Stream<ENTITY> stream =
7675
(Stream<ENTITY>)
7776
cache.entrySet().stream()
78-
.filter(e -> e.getKey().belongsToRootEntity())
79-
.map(Map.Entry::getValue);
77+
.filter(e -> e.getKey().isRootEntityKey())
78+
.map(Map.Entry::getValue)
79+
.filter(entityType.getEntityClass()::isInstance);
8080
return streamReducer.reduce(stream);
8181
}
8282

8383
/**
8484
* Establishes associations between source and target entities based on the provided combination
85-
* of linkage rules and updates the cache with newly associated entities. This method iterates
86-
* through association linker types and applies specific linking logic to pair source and target
87-
* entities according to their respective keys. The method avoids redundant associations by
88-
* checking existing combinations before linking.
89-
*
90-
* @param cache a map that stores entities indexed by their unique {@link LinkableEntityKey}. It
91-
* is updated during the association process with newly created entities.
92-
* @param combinations a set of previously established entity key pairs. This is used to ensure no
93-
* duplicate associations are created. New pairs are added to this set during the process.
94-
* @param associationCandidate a map containing potential source and target entities, where keys
95-
* are string identifiers corresponding to their roles (e.g., source or target) and values are
96-
* {@code LinkableEntity} objects.
85+
* of linkage rules and updates the cache with newly associated entities.
9786
*/
9887
private void associate(
9988
Map<LinkableEntityKey, Object> cache,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public EntityType<?> entityType() {
4040
return associationIdentifier.entityType();
4141
}
4242

43-
public boolean belongsToRootEntity() {
43+
public boolean isRootEntityKey() {
4444
return associationIdentifier.propertyPath().isEmpty();
4545
}
4646
}

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

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
* caching to avoid duplicate instantiation, and handles linking of associated entities. This
4444
* provider is configured with essential details such as the entity type, query, aggregation
4545
* strategy, and mapping and fetching mechanisms.
46-
*
47-
* <p>It ensures efficient and reusable entity instantiation through its caching mechanism and
48-
* provides a robust support for mapping result set columns to entity properties, even in cases
49-
* involving complex associations and aggregation strategies.
5046
*/
5147
public class LinkableEntityPoolProvider extends AbstractObjectProvider<LinkableEntityPool> {
5248

@@ -85,25 +81,14 @@ public LinkableEntityPoolProvider(
8581

8682
@Override
8783
public LinkableEntityPool get(ResultSet resultSet) throws SQLException {
88-
List<MappingSupport.Prop> props = cratesProps(resultSet);
84+
List<MappingSupport.Prop> props = createProps(resultSet);
8985
Map<AssociationIdentifier, List<MappingSupport.Prop>> propGroup =
9086
groupPropsByAssociationIdentifier(props);
9187
return createEntityPool(propGroup);
9288
}
9389

94-
/**
95-
* Processes the given ResultSet and constructs a list of MappingSupport.Prop objects. Each Prop
96-
* object is created by extracting the raw value from the ResultSet using the associated property
97-
* type and its index, as defined by the indexMap. If the indexMap is null, it initializes it by
98-
* creating a column name mapping and determining the appropriate indexes based on the ResultSet's
99-
* metadata.
100-
*
101-
* @param resultSet the ResultSet from which property values are extracted, must not be null
102-
* @return a list of MappingSupport.Prop objects, each representing a property with its extracted
103-
* value
104-
* @throws SQLException if a database access error occurs
105-
*/
106-
private List<MappingSupport.Prop> cratesProps(ResultSet resultSet) throws SQLException {
90+
/** Processes the given ResultSet and constructs a list of MappingSupport.Prop objects. */
91+
private List<MappingSupport.Prop> createProps(ResultSet resultSet) throws SQLException {
10792
assertNotNull(resultSet);
10893
if (indexMap == null) {
10994
Map<String, MappingSupport.PropType> columnNameMap = createColumnNameMap();
@@ -122,15 +107,7 @@ private List<MappingSupport.Prop> cratesProps(ResultSet resultSet) throws SQLExc
122107
return props;
123108
}
124109

125-
/**
126-
* Creates a column name mapping for the entity type associated with this provider. This method
127-
* retrieves the entity property types and populates a map where column names are keys and their
128-
* corresponding property types are values. It also ensures that the mapping includes appropriate
129-
* table aliases for column names to avoid conflicts.
130-
*
131-
* @return a map where the keys are column names (with applied table aliases) and the values are
132-
* corresponding {@link MappingSupport.PropType} objects
133-
*/
110+
/** Creates a column name mapping for the entity type associated with this provider. */
134111
private Map<String, MappingSupport.PropType> createColumnNameMap() {
135112
List<? extends EntityPropertyType<?, ?>> propertyTypes = entityType.getEntityPropertyTypes();
136113
Map<String, MappingSupport.PropType> result = new HashMap<>(propertyTypes.size());
@@ -143,15 +120,6 @@ private Map<String, MappingSupport.PropType> createColumnNameMap() {
143120
* type and its properties. This method recursively processes entity properties and association
144121
* properties to populate the given map with column names and corresponding property type
145122
* information.
146-
*
147-
* @param map a map where column names (in a prefixed, lowercase format) are mapped to their
148-
* corresponding {@link MappingSupport.PropType} values
149-
* @param source the {@link EntityType} representing the source entity for which column names and
150-
* property types are being collected
151-
* @param propertyPath the property path used to identify the hierarchy of properties, allowing
152-
* proper association handling
153-
* @param tableAlias the table alias used as a prefix for column names to ensure uniqueness across
154-
* multiple joined tables
155123
*/
156124
private void collectColumnNames(
157125
Map<String, MappingSupport.PropType> map,
@@ -182,13 +150,7 @@ private void collectColumnNames(
182150

183151
/**
184152
* Groups a list of {@link MappingSupport.Prop} objects by their associated {@link
185-
* AssociationIdentifier}. The grouping is determined based on the combination of the property
186-
* path and entity type for each property.
187-
*
188-
* @param props a list of {@link MappingSupport.Prop} objects representing entity properties to be
189-
* grouped
190-
* @return a map where the keys are {@link AssociationIdentifier} objects and the values are lists
191-
* of {@link MappingSupport.Prop} objects grouped by their association identifier
153+
* AssociationIdentifier}.
192154
*/
193155
private Map<AssociationIdentifier, List<MappingSupport.Prop>> groupPropsByAssociationIdentifier(
194156
List<MappingSupport.Prop> props) {
@@ -200,15 +162,7 @@ private Map<AssociationIdentifier, List<MappingSupport.Prop>> groupPropsByAssoci
200162

201163
/**
202164
* Creates and populates a {@link LinkableEntityPool} based on the provided group of properties
203-
* organized by their {@link AssociationIdentifier}. The method processes the given properties,
204-
* checks their validity, determines the appropriate keys and states, and associates the created
205-
* entities with a unique key in the pool. It ensures caching and state preservation for entities.
206-
*
207-
* @param propGroup a map where keys are {@link AssociationIdentifier} objects representing the
208-
* association identifiers and values are lists of {@link MappingSupport.Prop}, which define
209-
* properties for the entities within that association.
210-
* @return a {@link LinkableEntityPool} containing the processed and created entities organized by
211-
* their associations.
165+
* organized by their {@link AssociationIdentifier}.
212166
*/
213167
private LinkableEntityPool createEntityPool(
214168
Map<AssociationIdentifier, List<MappingSupport.Prop>> propGroup) {

0 commit comments

Comments
 (0)