Skip to content

Commit dfd8123

Browse files
committed
Simplified EntityRowMapper.
Removes an unused field and moves operations into constructor, to make the mapRow method simpler. Closes #1974
1 parent 8b157aa commit dfd8123

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/EntityRowMapper.java

+12-16
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.springframework.data.relational.core.mapping.AggregatePath;
2222
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
2323
import org.springframework.data.relational.domain.RowDocument;
24+
import org.springframework.data.util.TypeInformation;
2425
import org.springframework.jdbc.core.RowMapper;
25-
import org.springframework.lang.Nullable;
2626

2727
/**
2828
* Maps a {@link ResultSet} to an entity of type {@code T}, including entities referenced. This {@link RowMapper} might
@@ -37,36 +37,32 @@
3737
*/
3838
public class EntityRowMapper<T> implements RowMapper<T> {
3939

40-
private final RelationalPersistentEntity<T> entity;
41-
private final AggregatePath path;
40+
private final TypeInformation<T> typeInformation;
4241
private final JdbcConverter converter;
43-
private final @Nullable Identifier identifier;
42+
private final Identifier identifier;
4443

45-
@SuppressWarnings("unchecked")
46-
public EntityRowMapper(AggregatePath path, JdbcConverter converter, Identifier identifier) {
44+
private EntityRowMapper(TypeInformation<T> typeInformation, JdbcConverter converter, Identifier identifier) {
4745

48-
this.entity = (RelationalPersistentEntity<T>) path.getLeafEntity();
49-
this.path = path;
46+
this.typeInformation = typeInformation;
5047
this.converter = converter;
5148
this.identifier = identifier;
5249
}
5350

54-
public EntityRowMapper(RelationalPersistentEntity<T> entity, JdbcConverter converter) {
51+
@SuppressWarnings("unchecked")
52+
public EntityRowMapper(AggregatePath path, JdbcConverter converter, Identifier identifier) {
53+
this(((RelationalPersistentEntity<T>) path.getRequiredLeafEntity()).getTypeInformation(), converter, identifier);
54+
}
5555

56-
this.entity = entity;
57-
this.path = null;
58-
this.converter = converter;
59-
this.identifier = null;
56+
public EntityRowMapper(RelationalPersistentEntity<T> entity, JdbcConverter converter) {
57+
this(entity.getTypeInformation(), converter, Identifier.empty());
6058
}
6159

6260
@Override
6361
public T mapRow(ResultSet resultSet, int rowNumber) throws SQLException {
6462

6563
RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet);
6664

67-
return identifier == null //
68-
? converter.readAndResolve(entity.getTypeInformation(), document, Identifier.empty()) //
69-
: converter.readAndResolve(entity.getTypeInformation(), document, identifier);
65+
return converter.readAndResolve(typeInformation, document, identifier);
7066
}
7167

7268
}

0 commit comments

Comments
 (0)