27
27
import org .apache .commons .logging .Log ;
28
28
import org .apache .commons .logging .LogFactory ;
29
29
import org .springframework .context .ApplicationContextAware ;
30
- import org .springframework .core .convert .ConversionException ;
31
- import org .springframework .core .convert .ConversionFailedException ;
32
30
import org .springframework .core .convert .converter .Converter ;
33
- import org .springframework .dao .DataAccessException ;
34
31
import org .springframework .dao .NonTransientDataAccessException ;
35
32
import org .springframework .data .convert .CustomConversions ;
36
33
import org .springframework .data .jdbc .core .mapping .AggregateReference ;
39
36
import org .springframework .data .mapping .context .MappingContext ;
40
37
import org .springframework .data .mapping .model .SimpleTypeHolder ;
41
38
import org .springframework .data .mapping .model .ValueExpressionEvaluator ;
42
- import org .springframework .data .relational .core .conversion .DbActionExecutionException ;
43
39
import org .springframework .data .relational .core .conversion .MappingRelationalConverter ;
44
40
import org .springframework .data .relational .core .conversion .ObjectPath ;
45
41
import org .springframework .data .relational .core .conversion .RelationalConverter ;
@@ -177,8 +173,33 @@ private Class<?> doGetColumnType(RelationalPersistentProperty property) {
177
173
return componentColumnType ;
178
174
}
179
175
176
+ /**
177
+ * Read and convert a single value that is coming from a database to the {@literal targetType} expected by the domain
178
+ * model.
179
+ *
180
+ * @param value a value as it is returned by the driver accessing the persistence store. May be {@code null}.
181
+ * @param targetType {@link TypeInformation} into which the value is to be converted. Must not be {@code null}.
182
+ * @return
183
+ */
180
184
@ Override
181
- protected Object readTechnologyType (Object value ) {
185
+ @ Nullable
186
+ public Object readValue (@ Nullable Object value , TypeInformation <?> targetType ) {
187
+
188
+ if (null == value ) {
189
+ return null ;
190
+ }
191
+
192
+ TypeInformation <?> originalTargetType = targetType ;
193
+ value = readJdbcArray (value );
194
+ targetType = determineNestedTargetType (targetType );
195
+
196
+ return readToAggregateReference (getPotentiallyConvertedSimpleRead (value , targetType ), originalTargetType );
197
+ }
198
+
199
+ /**
200
+ * Unwrap a Jdbc array, if such a value is provided
201
+ */
202
+ private Object readJdbcArray (Object value ) {
182
203
183
204
if (value instanceof Array array ) {
184
205
try {
@@ -191,8 +212,11 @@ protected Object readTechnologyType(Object value) {
191
212
return value ;
192
213
}
193
214
194
- @ Override
195
- protected TypeInformation <?> determineModuleReadTarget (TypeInformation <?> ultimateTargetType ) {
215
+ /**
216
+ * Determine the id type of an {@link AggregateReference} that the rest of the conversion infrastructure needs to use
217
+ * as a conversion target.
218
+ */
219
+ private TypeInformation <?> determineNestedTargetType (TypeInformation <?> ultimateTargetType ) {
196
220
197
221
if (AggregateReference .class .isAssignableFrom (ultimateTargetType .getType ())) {
198
222
// the id type of a AggregateReference
@@ -201,8 +225,10 @@ protected TypeInformation<?> determineModuleReadTarget(TypeInformation<?> ultima
201
225
return ultimateTargetType ;
202
226
}
203
227
204
- @ Override
205
- protected Object readModuleType (Object value , TypeInformation <?> targetType ) {
228
+ /**
229
+ * Convert value to an {@link AggregateReference} if that is specified by the parameter targetType.
230
+ */
231
+ private Object readToAggregateReference (Object value , TypeInformation <?> targetType ) {
206
232
207
233
if (AggregateReference .class .isAssignableFrom (targetType .getType ())) {
208
234
return AggregateReference .to (value );
0 commit comments