Class MappingJdbcConverter
java.lang.Object
org.springframework.data.relational.core.conversion.AbstractRelationalConverter
org.springframework.data.relational.core.conversion.MappingRelationalConverter
org.springframework.data.jdbc.core.convert.MappingJdbcConverter
- All Implemented Interfaces:
Aware, ApplicationContextAware, EnvironmentCapable, JdbcConverter, RelationalConverter
public class MappingJdbcConverter
extends MappingRelationalConverter
implements JdbcConverter, ApplicationContextAware
RelationalConverter that uses a MappingContext to apply conversion of relational values to property
values.
Conversion is configurable by providing a customized CustomConversions.
- Since:
- 3.2
- Author:
- Mark Paluch, Jens Schauder, Christoph Strobl, Myeonghyeon Lee, Chirag Tailor
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class MappingRelationalConverter
MappingRelationalConverter.AggregatePathValueProvider, MappingRelationalConverter.ConversionContext, MappingRelationalConverter.DefaultConversionContext, MappingRelationalConverter.DocumentValueProvider, MappingRelationalConverter.ProjectingConversionContext, MappingRelationalConverter.RelationalPropertyValueProvider -
Constructor Summary
ConstructorsConstructorDescriptionMappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver) Creates a newMappingJdbcConvertergivenMappingContextand ano-op type factorythrowingUnsupportedOperationExceptionon type creation.MappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver, CustomConversions conversions, JdbcTypeFactory typeFactory) Creates a newMappingJdbcConvertergivenMappingContext. -
Method Summary
Modifier and TypeMethodDescriptionClass<?> getColumnType(RelationalPersistentProperty property) The type to be used to store this property in the database.protected @Nullable ObjectgetPotentiallyConvertedSimpleWrite(Object value, org.springframework.data.core.TypeInformation<?> type) getTargetSqlType(RelationalPersistentProperty property) The SQL type constant used when using this property as a parameter for a SQL statement.newValueProvider(RowDocumentAccessor documentAccessor, ValueExpressionEvaluator evaluator, MappingRelationalConverter.ConversionContext context) <R> RreadAndResolve(org.springframework.data.core.TypeInformation<R> type, RowDocument source, Identifier identifier) Read aRowDocumentinto the requestedaggregate typeand resolve references by looking these up fromRelationResolver.@Nullable ObjectRead and convert a single value that is coming from a database to the targetType expected by the domain model.voidsetExceptionTranslator(SQLExceptionTranslator exceptionTranslator) Set the exception translator for this instance.protected @Nullable ObjectUnwraps values of typeJdbcValue.writeJdbcValue(@Nullable Object value, org.springframework.data.core.TypeInformation<?> columnType, SQLType sqlType) Convert a property value into aJdbcValuethat contains the converted value and information how to bind it to JDBC parameters.Methods inherited from class MappingRelationalConverter
doReadProjection, getConversionContext, getEnvironment, getPotentiallyConvertedSimpleRead, getPropertyAccessor, introspectProjection, newProjectingConversionContext, project, read, read, readAggregate, readAggregate, readCollectionOrArray, readMap, setApplicationContext, writeValueMethods inherited from class AbstractRelationalConverter
getConversions, getConversionService, getEntityInstantiators, getMappingContextMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ApplicationContextAware
setApplicationContextMethods inherited from interface JdbcConverter
getMappingContext, readAndResolve, readAndResolve, writeJdbcValueMethods inherited from interface RelationalConverter
getConversionService, getEntityInstantiators, getPropertyAccessor, introspectProjection, project, read, writeValue
-
Constructor Details
-
MappingJdbcConverter
Creates a newMappingJdbcConvertergivenMappingContextand ano-op type factorythrowingUnsupportedOperationExceptionon type creation. UseMappingJdbcConverter(RelationalMappingContext, RelationResolver, CustomConversions, JdbcTypeFactory)(MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and large objects into JDBC-specific types.- Parameters:
context- must not be null.relationResolver- used to fetch additional relations from the database. Must not be null.
-
MappingJdbcConverter
public MappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver, CustomConversions conversions, JdbcTypeFactory typeFactory) Creates a newMappingJdbcConvertergivenMappingContext.- Parameters:
context- must not be null.relationResolver- used to fetch additional relations from the database. Must not be null.typeFactory- must not be null
-
-
Method Details
-
setExceptionTranslator
Set the exception translator for this instance. Defaults to aSQLErrorCodeSQLExceptionTranslator.- See Also:
-
getTargetSqlType
Description copied from interface:JdbcConverterThe SQL type constant used when using this property as a parameter for a SQL statement.- Specified by:
getTargetSqlTypein interfaceJdbcConverter- Returns:
- Must not be
null. - See Also:
-
getColumnType
Description copied from interface:JdbcConverterThe type to be used to store this property in the database. Multidimensional arrays are unwrapped to reflect a top-level array type (e.g.String[][]returnsString[]).- Specified by:
getColumnTypein interfaceJdbcConverter- Returns:
- a
Classthat is suitable for usage with JDBC drivers. - See Also:
-
readValue
public @Nullable Object readValue(@Nullable Object value, org.springframework.data.core.TypeInformation<?> targetType) Read and convert a single value that is coming from a database to the targetType expected by the domain model.- Specified by:
readValuein interfaceRelationalConverter- Overrides:
readValuein classMappingRelationalConverter- Parameters:
value- a value as it is returned by the driver accessing the persistence store. May benull.targetType-TypeInformationinto which the value is to be converted. Must not benull.- Returns:
-
getPotentiallyConvertedSimpleWrite
protected @Nullable Object getPotentiallyConvertedSimpleWrite(Object value, org.springframework.data.core.TypeInformation<?> type) - Overrides:
getPotentiallyConvertedSimpleWritein classMappingRelationalConverter
-
writeJdbcValue
public JdbcValue writeJdbcValue(@Nullable Object value, org.springframework.data.core.TypeInformation<?> columnType, SQLType sqlType) Description copied from interface:JdbcConverterConvert a property value into aJdbcValuethat contains the converted value and information how to bind it to JDBC parameters.- Specified by:
writeJdbcValuein interfaceJdbcConverter- Parameters:
value- a value as it is used in the object model. May benull.columnType-TypeInformationinto which the value is to be converted. Must not benull.sqlType- theSQLTypeto be used if non is specified by a converter.- Returns:
- The converted value wrapped in a
JdbcValue. Guaranteed to be not null.
-
unwrap
Unwraps values of typeJdbcValue.- Overrides:
unwrapin classMappingRelationalConverter- Parameters:
convertedValue- a value that might need unwrapping.
-
readAndResolve
public <R> R readAndResolve(org.springframework.data.core.TypeInformation<R> type, RowDocument source, Identifier identifier) Description copied from interface:JdbcConverterRead aRowDocumentinto the requestedaggregate typeand resolve references by looking these up fromRelationResolver.- Specified by:
readAndResolvein interfaceJdbcConverter- Type Parameters:
R- aggregate type.- Parameters:
type- target aggregate type.source- sourceRowDocument.identifier- identifier chain.- Returns:
- the converted object.
- See Also:
-
newValueProvider
protected MappingRelationalConverter.RelationalPropertyValueProvider newValueProvider(RowDocumentAccessor documentAccessor, ValueExpressionEvaluator evaluator, MappingRelationalConverter.ConversionContext context) - Overrides:
newValueProviderin classMappingRelationalConverter
-