|
21 | 21 | import org.springframework.data.relational.core.mapping.AggregatePath;
|
22 | 22 | import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
23 | 23 | import org.springframework.data.relational.domain.RowDocument;
|
| 24 | +import org.springframework.data.util.TypeInformation; |
24 | 25 | import org.springframework.jdbc.core.RowMapper;
|
25 |
| -import org.springframework.lang.Nullable; |
26 | 26 |
|
27 | 27 | /**
|
28 | 28 | * Maps a {@link ResultSet} to an entity of type {@code T}, including entities referenced. This {@link RowMapper} might
|
|
37 | 37 | */
|
38 | 38 | public class EntityRowMapper<T> implements RowMapper<T> {
|
39 | 39 |
|
40 |
| - private final RelationalPersistentEntity<T> entity; |
41 |
| - private final AggregatePath path; |
| 40 | + private final TypeInformation<T> typeInformation; |
42 | 41 | private final JdbcConverter converter;
|
43 |
| - private final @Nullable Identifier identifier; |
| 42 | + private final Identifier identifier; |
44 | 43 |
|
45 |
| - @SuppressWarnings("unchecked") |
46 |
| - public EntityRowMapper(AggregatePath path, JdbcConverter converter, Identifier identifier) { |
| 44 | + private EntityRowMapper(TypeInformation<T> typeInformation, JdbcConverter converter, Identifier identifier) { |
47 | 45 |
|
48 |
| - this.entity = (RelationalPersistentEntity<T>) path.getLeafEntity(); |
49 |
| - this.path = path; |
| 46 | + this.typeInformation = typeInformation; |
50 | 47 | this.converter = converter;
|
51 | 48 | this.identifier = identifier;
|
52 | 49 | }
|
53 | 50 |
|
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 | + } |
55 | 55 |
|
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()); |
60 | 58 | }
|
61 | 59 |
|
62 | 60 | @Override
|
63 | 61 | public T mapRow(ResultSet resultSet, int rowNumber) throws SQLException {
|
64 | 62 |
|
65 | 63 | RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet);
|
66 | 64 |
|
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); |
70 | 66 | }
|
71 | 67 |
|
72 | 68 | }
|
0 commit comments