47
47
import org .springframework .data .relational .core .dialect .ArrayColumns ;
48
48
import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
49
49
import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
50
- import org .springframework .data .relational .core .sql .IdentifierProcessing ;
51
50
import org .springframework .data .util .ClassTypeInformation ;
52
51
import org .springframework .data .util .TypeInformation ;
53
52
import org .springframework .lang .Nullable ;
@@ -155,16 +154,18 @@ private <R> R read(RelationalPersistentEntity<R> entity, Row row, @Nullable RowM
155
154
* @param prefix to be used for all column names accessed by this method. Must not be {@literal null}.
156
155
* @return the value read from the {@link Row}. May be {@literal null}.
157
156
*/
157
+ @ Nullable
158
158
private Object readFrom (Row row , @ Nullable RowMetadata metadata , RelationalPersistentProperty property ,
159
159
String prefix ) {
160
160
161
+ String identifier = prefix + property .getColumnName ().getReference ();
162
+
161
163
try {
162
164
163
165
if (property .isEntity ()) {
164
166
return readEntityFrom (row , metadata , property );
165
167
}
166
168
167
- String identifier = prefix + property .getColumnName ().getReference ();
168
169
if (metadata != null && !metadata .getColumnNames ().contains (identifier )) {
169
170
return null ;
170
171
}
@@ -173,7 +174,8 @@ private Object readFrom(Row row, @Nullable RowMetadata metadata, RelationalPersi
173
174
return readValue (value , property .getTypeInformation ());
174
175
175
176
} catch (Exception o_O ) {
176
- throw new MappingException (String .format ("Could not read property %s from result set!" , property ), o_O );
177
+ throw new MappingException (String .format ("Could not read property %s from column %s!" , property , identifier ),
178
+ o_O );
177
179
}
178
180
}
179
181
@@ -274,8 +276,10 @@ private <S> S readEntityFrom(Row row, RowMetadata metadata, PersistentProperty<?
274
276
275
277
RelationalPersistentEntity <?> entity = getMappingContext ().getRequiredPersistentEntity (property .getActualType ());
276
278
277
- if (readFrom (row , metadata , entity .getRequiredIdProperty (), prefix ) == null ) {
278
- return null ;
279
+ if (entity .hasIdProperty ()) {
280
+ if (readFrom (row , metadata , entity .getRequiredIdProperty (), prefix ) == null ) {
281
+ return null ;
282
+ }
279
283
}
280
284
281
285
Object instance = createInstance (row , metadata , prefix , entity );
@@ -637,7 +641,7 @@ private boolean potentiallySetId(Row row, RowMetadata metadata, PersistentProper
637
641
638
642
Collection <String > columns = metadata .getColumnNames ();
639
643
Object generatedIdValue = null ;
640
- String idColumnName = idProperty .getColumnName ().getReference (IdentifierProcessing . NONE );
644
+ String idColumnName = idProperty .getColumnName ().getReference ();
641
645
642
646
if (columns .contains (idColumnName )) {
643
647
generatedIdValue = row .get (idColumnName );
@@ -688,7 +692,7 @@ public <T> T getParameterValue(PreferredConstructor.Parameter<T, RelationalPersi
688
692
}
689
693
}
690
694
691
- private static class RowParameterValueProvider implements ParameterValueProvider <RelationalPersistentProperty > {
695
+ private class RowParameterValueProvider implements ParameterValueProvider <RelationalPersistentProperty > {
692
696
693
697
private final Row resultSet ;
694
698
private final RowMetadata metadata ;
@@ -714,30 +718,22 @@ public RowParameterValueProvider(Row resultSet, RowMetadata metadata, Relational
714
718
public <T > T getParameterValue (PreferredConstructor .Parameter <T , RelationalPersistentProperty > parameter ) {
715
719
716
720
RelationalPersistentProperty property = this .entity .getRequiredPersistentProperty (parameter .getName ());
721
+ Object value = readFrom (this .resultSet , this .metadata , property , this .prefix );
717
722
718
- String reference = property .getColumnName ().getReference (IdentifierProcessing .NONE );
719
- String column = this .prefix .isEmpty () ? reference : this .prefix + reference ;
720
-
721
- try {
722
-
723
- if (this .metadata != null && !this .metadata .getColumnNames ().contains (column )) {
724
- return null ;
725
- }
726
-
727
- Object value = this .resultSet .get (column );
723
+ if (value == null ) {
724
+ return null ;
725
+ }
728
726
729
- if (value == null ) {
730
- return null ;
731
- }
727
+ Class <T > type = parameter .getType ().getType ();
732
728
733
- Class <T > type = parameter .getType ().getType ();
729
+ if (type .isInstance (value )) {
730
+ return type .cast (value );
731
+ }
734
732
735
- if (type .isInstance (value )) {
736
- return type .cast (value );
737
- }
733
+ try {
738
734
return this .converter .getConversionService ().convert (value , type );
739
735
} catch (Exception o_O ) {
740
- throw new MappingException (String .format ("Couldn't read column %s from Row ." , column ), o_O );
736
+ throw new MappingException (String .format ("Couldn't read parameter %s." , parameter . getName () ), o_O );
741
737
}
742
738
}
743
739
}
0 commit comments