2727import org .apache .commons .logging .Log ;
2828import org .apache .commons .logging .LogFactory ;
2929import org .springframework .context .ApplicationContextAware ;
30- import org .springframework .core .convert .ConversionException ;
31- import org .springframework .core .convert .ConversionFailedException ;
3230import org .springframework .core .convert .converter .Converter ;
33- import org .springframework .dao .DataAccessException ;
3431import org .springframework .dao .NonTransientDataAccessException ;
3532import org .springframework .data .convert .CustomConversions ;
3633import org .springframework .data .jdbc .core .mapping .AggregateReference ;
3936import org .springframework .data .mapping .context .MappingContext ;
4037import org .springframework .data .mapping .model .SimpleTypeHolder ;
4138import org .springframework .data .mapping .model .ValueExpressionEvaluator ;
42- import org .springframework .data .relational .core .conversion .DbActionExecutionException ;
4339import org .springframework .data .relational .core .conversion .MappingRelationalConverter ;
4440import org .springframework .data .relational .core .conversion .ObjectPath ;
4541import org .springframework .data .relational .core .conversion .RelationalConverter ;
@@ -177,8 +173,33 @@ private Class<?> doGetColumnType(RelationalPersistentProperty property) {
177173 return componentColumnType ;
178174 }
179175
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+ */
180184 @ 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 ) {
182203
183204 if (value instanceof Array array ) {
184205 try {
@@ -191,8 +212,11 @@ protected Object readTechnologyType(Object value) {
191212 return value ;
192213 }
193214
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 ) {
196220
197221 if (AggregateReference .class .isAssignableFrom (ultimateTargetType .getType ())) {
198222 // the id type of a AggregateReference
@@ -201,8 +225,10 @@ protected TypeInformation<?> determineModuleReadTarget(TypeInformation<?> ultima
201225 return ultimateTargetType ;
202226 }
203227
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 ) {
206232
207233 if (AggregateReference .class .isAssignableFrom (targetType .getType ())) {
208234 return AggregateReference .to (value );
0 commit comments