22
22
import org .springframework .data .relational .core .mapping .PersistentPropertyPathExtension ;
23
23
import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
24
24
import org .springframework .data .relational .domain .RowDocument ;
25
+ import org .springframework .data .util .TypeInformation ;
25
26
import org .springframework .jdbc .core .RowMapper ;
26
- import org .springframework .lang .Nullable ;
27
27
28
28
/**
29
29
* Maps a {@link ResultSet} to an entity of type {@code T}, including entities referenced. This {@link RowMapper} might
38
38
*/
39
39
public class EntityRowMapper <T > implements RowMapper <T > {
40
40
41
- private final RelationalPersistentEntity <T > entity ;
42
- private final AggregatePath path ;
41
+ private final TypeInformation <T > typeInformation ;
43
42
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
+ }
45
51
46
52
/**
47
53
* @deprecated use {@link EntityRowMapper#EntityRowMapper(AggregatePath, JdbcConverter, Identifier)} instead
@@ -58,29 +64,19 @@ public EntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter conve
58
64
59
65
@ SuppressWarnings ("unchecked" )
60
66
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 );
66
68
}
67
69
68
70
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 ());
74
72
}
75
73
76
74
@ Override
77
75
public T mapRow (ResultSet resultSet , int rowNumber ) throws SQLException {
78
76
79
77
RowDocument document = RowDocumentResultSetExtractor .toRowDocument (resultSet );
80
78
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 );
84
80
}
85
81
86
82
}
0 commit comments