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
- Direct Known Subclasses:
BasicJdbcConverter
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 org.springframework.data.relational.core.conversion.MappingRelationalConverter
MappingRelationalConverter.AggregatePathValueProvider, MappingRelationalConverter.ConversionContext, MappingRelationalConverter.DefaultConversionContext, MappingRelationalConverter.DocumentValueProvider, MappingRelationalConverter.ProjectingConversionContext, MappingRelationalConverter.RelationalPropertyValueProvider
-
Constructor Summary
ConstructorsConstructorDescriptionMappingJdbcConverter
(RelationalMappingContext context, RelationResolver relationResolver) Creates a newMappingJdbcConverter
givenMappingContext
and ano-op type factory
throwingUnsupportedOperationException
on type creation.MappingJdbcConverter
(RelationalMappingContext context, RelationResolver relationResolver, CustomConversions conversions, JdbcTypeFactory typeFactory) Creates a newMappingJdbcConverter
givenMappingContext
. -
Method Summary
Modifier and TypeMethodDescriptionClass<?>
getColumnType
(RelationalPersistentProperty property) The type to be used to store this property in the database.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> R
readAndResolve
(Class<R> type, RowDocument source, Identifier identifier) Read aRowDocument
into the requestedaggregate type
and resolve references by looking these up fromRelationResolver
.readValue
(Object value, TypeInformation<?> type) Read a relational value into the desireddestination type
.writeJdbcValue
(Object value, Class<?> columnType, SQLType sqlType) Convert a property value into aJdbcValue
that contains the converted value and information how to bind it to JDBC parameters.writeValue
(Object value, TypeInformation<?> type) Write a property value into a relational type that can be stored natively.Methods inherited from class org.springframework.data.relational.core.conversion.MappingRelationalConverter
createInstance, doReadProjection, getConversionContext, getEnvironment, getPotentiallyConvertedSimpleRead, getPropertyAccessor, introspectProjection, newProjectingConversionContext, project, read, read, readAggregate, readAggregate, readCollectionOrArray, readMap, setApplicationContext
Methods inherited from class org.springframework.data.relational.core.conversion.AbstractRelationalConverter
getConversions, getConversionService, getEntityInstantiators, getMappingContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
Methods inherited from interface org.springframework.data.jdbc.core.convert.JdbcConverter
getMappingContext, mapRow, mapRow, readAndResolve
Methods inherited from interface org.springframework.data.relational.core.conversion.RelationalConverter
createInstance, getConversionService, getEntityInstantiators, getPropertyAccessor, introspectProjection, project, read
-
Constructor Details
-
MappingJdbcConverter
Creates a newMappingJdbcConverter
givenMappingContext
and ano-op type factory
throwingUnsupportedOperationException
on 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 newMappingJdbcConverter
givenMappingContext
.- 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
-
getTargetSqlType
Description copied from interface:JdbcConverter
The SQL type constant used when using this property as a parameter for a SQL statement.- Specified by:
getTargetSqlType
in interfaceJdbcConverter
- Returns:
- Must not be
null
. - See Also:
-
getColumnType
Description copied from interface:JdbcConverter
The 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:
getColumnType
in interfaceJdbcConverter
- Returns:
- a
Class
that is suitable for usage with JDBC drivers. - See Also:
-
readValue
Description copied from interface:RelationalConverter
Read a relational value into the desireddestination type
.- Specified by:
readValue
in interfaceRelationalConverter
- Overrides:
readValue
in classMappingRelationalConverter
- Parameters:
value
- a value as it is returned by the driver accessing the persistence store. May benull
.type
-TypeInformation
into which the value is to be converted. Must not benull
.- Returns:
- The converted value. May be
null
.
-
writeValue
Description copied from interface:RelationalConverter
Write a property value into a relational type that can be stored natively.- Specified by:
writeValue
in interfaceRelationalConverter
- Overrides:
writeValue
in classMappingRelationalConverter
- Parameters:
value
- a value as it is used in the object model. May benull
.type
-TypeInformation
into which the value is to be converted. Must not benull
.- Returns:
- The converted value. May be
null
.
-
writeJdbcValue
Description copied from interface:JdbcConverter
Convert a property value into aJdbcValue
that contains the converted value and information how to bind it to JDBC parameters.- Specified by:
writeJdbcValue
in interfaceJdbcConverter
- Parameters:
value
- a value as it is used in the object model. May benull
.columnType
- Class into which the value is to be converted. Must not benull
.sqlType
- theSQLType
to be used if non is specified by a converter.- Returns:
- The converted value wrapped in a
JdbcValue
. Guaranteed to be not null.
-
readAndResolve
Description copied from interface:JdbcConverter
Read aRowDocument
into the requestedaggregate type
and resolve references by looking these up fromRelationResolver
.- Specified by:
readAndResolve
in 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:
newValueProvider
in classMappingRelationalConverter
-