Skip to content

Commit 8d4b052

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

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

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

+13-17
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
2323
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
2424
import org.springframework.data.relational.domain.RowDocument;
25+
import org.springframework.data.util.TypeInformation;
2526
import org.springframework.jdbc.core.RowMapper;
26-
import org.springframework.lang.Nullable;
2727

2828
/**
2929
* Maps a {@link ResultSet} to an entity of type {@code T}, including entities referenced. This {@link RowMapper} might
@@ -38,10 +38,16 @@
3838
*/
3939
public class EntityRowMapper<T> implements RowMapper<T> {
4040

41-
private final RelationalPersistentEntity<T> entity;
42-
private final AggregatePath path;
41+
private final TypeInformation<T> typeInformation;
4342
private final JdbcConverter converter;
44-
private final @Nullable Identifier identifier;
43+
private final Identifier identifier;
44+
45+
private EntityRowMapper(TypeInformation<T> typeInformation, JdbcConverter converter, Identifier identifier) {
46+
47+
this.typeInformation = typeInformation;
48+
this.converter = converter;
49+
this.identifier = identifier;
50+
}
4551

4652
/**
4753
* @deprecated use {@link EntityRowMapper#EntityRowMapper(AggregatePath, JdbcConverter, Identifier)} instead
@@ -58,29 +64,19 @@ public EntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter conve
5864

5965
@SuppressWarnings("unchecked")
6066
public EntityRowMapper(AggregatePath path, JdbcConverter converter, Identifier identifier) {
61-
62-
this.entity = (RelationalPersistentEntity<T>) path.getLeafEntity();
63-
this.path = path;
64-
this.converter = converter;
65-
this.identifier = identifier;
67+
this(((RelationalPersistentEntity<T>) path.getRequiredLeafEntity()).getTypeInformation(), converter, identifier);
6668
}
6769

6870
public EntityRowMapper(RelationalPersistentEntity<T> entity, JdbcConverter converter) {
69-
70-
this.entity = entity;
71-
this.path = null;
72-
this.converter = converter;
73-
this.identifier = null;
71+
this(entity.getTypeInformation(), converter, Identifier.empty());
7472
}
7573

7674
@Override
7775
public T mapRow(ResultSet resultSet, int rowNumber) throws SQLException {
7876

7977
RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet);
8078

81-
return identifier == null //
82-
? converter.readAndResolve(entity.getTypeInformation(), document, Identifier.empty()) //
83-
: converter.readAndResolve(entity.getTypeInformation(), document, identifier);
79+
return converter.readAndResolve(typeInformation, document, identifier);
8480
}
8581

8682
}

0 commit comments

Comments
 (0)